cancel
Showing results for 
Search instead for 
Did you mean: 

SPI Data Register Problem

Charlie CHEN
Associate III

Hi,

I`m using STM32G431 for practicing SPI protocol knowledge, but face some problem like below.

​I use �?HAL_SPI_Transmit_IT】API to send (0x5A,0xA5) data out, but measure with Oscilloscope and figure out the wrong data.

In �?SPI_TxISR_8BIT】show how data move to Data Register, but see the watch window DR gets the wrong data.

0693W00000DlyATQAZ.jpg

Is there anyone know why that happened ?

I have checked Hardware Setting & all register, and find any similar problem, but not help.

Appreciate any help!

6 REPLIES 6

> measure with Oscilloscope and figure out the wrong data.

Show us what do you see on the oscilloscope.

> watch window DR gets the wrong data

SPI_DR is not a single register and you cannot read back what you've written into it. When you write into it, the value written goes to the Tx FIFO and cannot be seen. What you see when you read SPI_DR is top of the Rx FIFO.

JW

Hi @Community member​ 

Thanks for your reply!

Cause of the oscilloscope shows the data 0xF3 like the Watch Window, so I print the data with uart and also check the first input before it`s enable status.

> SPI_DR is not a single register and you cannot read back what you've written into it. When you write into it, the value written goes to the Tx FIFO and cannot be seen. What you see when you read SPI_DR is top of the Rx FIFO.

You`re right, but I measure and check the position is before it send and close the ISR. Logically, it`s still the first data that we input, means the same as my Tx_Buffer parameter.

Charlie

I don't see 0xF3 in the watch window; I see 0xF0 and 0x03 as two distinct bytes. And that's Rx, not Tx.

Which pin do you observe with the oscilloscope, exactly?

JW

S.Ma
Principal

First check if non interrupt mode works as expected. This will remove few possible root causes.

Hi @Community member​ ,

Sor, you`re right, it`s 0xF0 & 0x03.

I observe the MOSI pin set with oscilloscope.

Thanks for your reply.

Charlie

Hi @S.Ma​ ,

It will get in interrupt correct. So I think SPI was working right!

Thanks for your reply!

Charlie