Skip to main content
andykim
Associate II
May 15, 2013
Question

SPI Rx data reading error

  • May 15, 2013
  • 2 replies
  • 978 views
Posted on May 15, 2013 at 13:32

The original post was too long to process during our migration. Please click on the attachment to read the original post.
    This topic has been closed for replies.

    2 replies

    Tesla DeLorean
    Guru
    May 15, 2013
    Posted on May 15, 2013 at 15:45

    You need to make sure the clock edges are configured appropriately for your device.

    You should verify the data is sent by the device correctly using a scope or analyzer. You need to ensure that RXNE is cleared for prior data, so you read the right data in sequence. The SPI SD implementation routines look like this

    /**
    * @brief Write a byte on the SD.
    * @param Data: byte to send.
    * @retval None
    */
    uint8_t SD_WriteByte(uint8_t Data)
    {
    /*!< Wait until the transmit buffer is empty */
    while(SPI_I2S_GetFlagStatus(SD_SPI, SPI_I2S_FLAG_TXE) == RESET);
    /*!< Send the byte */
    SPI_I2S_SendData(SD_SPI, Data);
    /*!< Wait to receive a byte*/
    while(SPI_I2S_GetFlagStatus(SD_SPI, SPI_I2S_FLAG_RXNE) == RESET);
    /*!< Return the byte read from the SPI bus */ 
    return SPI_I2S_ReceiveData(SD_SPI);
    }
    /**
    * @brief Read a byte from the SD.
    * @param None
    * @retval The received byte.
    */
    uint8_t SD_ReadByte(void)
    {
    /*!< Wait until the transmit buffer is empty */
    while(SPI_I2S_GetFlagStatus(SD_SPI, SPI_I2S_FLAG_TXE) == RESET);
    /*!< Send the byte */
    SPI_I2S_SendData(SD_SPI, SD_DUMMY_BYTE);
    /*!< Wait until a data is received */
    while(SPI_I2S_GetFlagStatus(SD_SPI, SPI_I2S_FLAG_RXNE) == RESET);
    /*!< Return the byte read from the SPI bus */ 
    return SPI_I2S_ReceiveData(SD_SPI);
    }

    Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
    andykim
    andykimAuthor
    Associate II
    May 16, 2013
    Posted on May 16, 2013 at 08:27

    Hi,

    I have attached signals to read a data from the slave device.

    First write a index(0x74) to the slave, and then theslave ouputa data(0xff) like as the attached image.

    But DR of the SPI don't have 0xff, it has always 0x00.

    My code for this operation is like belows.

    I think that it is the same as clive1's.

    uint8_t SPI_rx_data(void)

    {

    uint8_t data;

    /* Tx a dummy data */

    while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);

    SPI_I2S_SendData(SPI1, 0x00);

    while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET) ;

    /* Wait for SPI1 data reception */

    while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET);

    data = SPI_I2S_ReceiveData(SPI1);

    return data;

    } What's wrong?

    Please help me.

    Thanks

    ________________

    Attachments :

    SIG.PNG : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I0xo&d=%2Fa%2F0X0000000bgJ%2FURXB7QHAcQczjPGtnwww8wdAFPbDEG.SbpJ1EWtaV_g&asPdf=false