Skip to main content
Visitor II
September 2, 2021
Question

SPI Data Register Problem

  • September 2, 2021
  • 3 replies
  • 2352 views

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!

    This topic has been closed for replies.

    3 replies

    Super User
    September 2, 2021

    > 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

    Visitor II
    September 3, 2021

    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

    Super User
    September 3, 2021

    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

    Visitor II
    September 6, 2021

    Hi @Community member​ ,

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

    I observe the MOSI pin set with oscilloscope.

    Thanks for your reply.

    Charlie

    Visitor II
    September 5, 2021

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

    Visitor II
    September 6, 2021

    Hi @S.Ma​ ,

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

    Thanks for your reply!

    Charlie