Problem with setting SPI TCR register

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Problem with setting SPI TCR register

ソリューションへジャンプ
1,627件の閲覧回数
trunghieudon
Contributor I

Hi,

I wrote a driver with a goal to access all Spi instances and implemented macro definitions so that it can be used easily in the future. I used these macros to initialize one of my SPI channel. It worked well for everything but somehow for the TCR register, it only updates the last register write and it does not update right away. It updates when it escapes the function. Weird! Consider the following example for better explanation.

The macros:

#define spi_SetClkPrescale(bInstance, bPrescaler) (pSpiRegisters[bInstance]->TCR = (pSpiRegisters[bInstance]->TCR & ~LPSPI_TCR_PRESCALE_MASK) | LPSPI_TCR_PRESCALE(bPrescaler))


#define spi_ConfigurePcs(bInstance, bIndex) (pSpiRegisters[bInstance]->TCR = (pSpiRegisters[bInstance]->TCR & ~LPSPI_TCR_PCS_MASK) | LPSPI_TCR_PCS(bIndex))


#define spi_SetFrameSize(bInstance,bSize) (pSpiRegisters[bInstance]->TCR = (pSpiRegisters[bInstance]->TCR & ~LPSPI_TCR_FRAMESZ_MASK) | LPSPI_TCR_FRAMESZ(bSize))

Initialize SPI

spi_SetFrameSize(1, 7);
spi_ConfigurePcs(1, 0);
spi_SetClkPrescale(1, 2);

This will then only updates the Prescaler and not the frame size nor the PCS. 

This however works for other registers and it updates everything.

I have attached a simplified module to save work for anyone trying to help me out. In this example, the CCR register updates everything (Line 91-94) while the TCR only updates the final write (Line 88) and discards the previous.

タグ(1)
0 件の賞賛
返信
1 解決策
1,598件の閲覧回数
danielmartynek
NXP TechSupport
NXP TechSupport

Hi trunghieudon@geotab.com,

The Transmit Command Register (TCR) is not an ordinary register, it is a FIFO.

Please take a look at the description of the register in the RM.

Section 51.3.1.15.2 Function

If you are using several commands, it is better to just store them as constants and write the commands as 32b words without reading a modifying the value in the register.

Regards,

Daniel

元の投稿で解決策を見る

0 件の賞賛
返信
1 返信
1,599件の閲覧回数
danielmartynek
NXP TechSupport
NXP TechSupport

Hi trunghieudon@geotab.com,

The Transmit Command Register (TCR) is not an ordinary register, it is a FIFO.

Please take a look at the description of the register in the RM.

Section 51.3.1.15.2 Function

If you are using several commands, it is better to just store them as constants and write the commands as 32b words without reading a modifying the value in the register.

Regards,

Daniel

0 件の賞賛
返信