This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] TMS320F2800157:SPI_receiveNBytes 帮助

Guru**** 2782625 points

Other Parts Discussed in Thread: C2000WARE

请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/c2000-microcontrollers-group/c2000/f/c2000-microcontrollers-forum/1612024/tms320f2800157-spi_receivenbytes-help

器件型号: TMS320F2800157
主题: C2000WARE 中讨论的其他器件

您好、

我正在将 SPI EEPROM 与我的系统集成、并且已经按照 C2000Ware 5.04 中的 SPI EEPROM 示例进行了操作。  示例中未使用但引用的调用之一是 SPI_receiveNBytes。  因为我想一次读一个更长的字串,我认为这种调用将是肤浅的。

我注意到该示例是围绕 EEPROM 设计的、只需要 16 位地址、我的需要 24 位地址。  因此、我进行了相应修改以发送 24 位地址。  这适用于 SPI_receive32Bits。  

在下面的监听中、我包含这两个调用、并在 SPI_receive32Bits 和 SPI_receiveNBytes 之间交换。  snip-it 显示了 SPI_receiveNBytes 注释掉、因为我在上次运行中使用了 SPI_receive32Bits。  

我的问题是两个呼叫都不会返回相同的数据。  我知道 SPI_receive32 位仅接收 32 位、但接收到的这 32 位是正确的。

更多有关 SPI_receiveNBytes 的信息。  我提供的长度= 8(字节)、txdly = no_delay。

您能告诉我我我在坑里的下落吗?

// Function to read data from the EEPROM
// - address is the byte address of the EEPROM
// - data is a pointer to an array of data being received
// - length is the number of characters in the array to receive
void PR_ReadData(uint32_t address, uint16_t *data, uint16_t length, uint16_t txdly)
{
     uint32_t RXdata = 0;
     CS_LOW;

    // Send the READ opcode.
    SPI_transmitByte(SPIA_BASE, READ);

    // Send EEPROM 24bit address to write data
    SPI_transmitByte(SPIA_BASE, address>>16);
    SPI_transmitByte(SPIA_BASE, address>>8);
    SPI_transmitByte(SPIA_BASE, address);

    // Receive length number of bytes
    //SPI_receiveNBytes(SPIA_BASE, data, length, txdly);

    RXdata = SPI_receive32Bits(SPIA_BASE, SPI_DATA_LITTLE_ENDIAN, DUMMY_DATA, txdly);

    CS_HIGH;
}
  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    再做一些研究、我发现 SPI_receiveNBytes  spi.h 中定义了以下内容

    //*****************************************************************************
    //
    //! This macro is used to receive 'N' bytes of data
    //!
    //! \param base specifies the SPI module base address.
    //! \param rxBuffer specifies receive buffer which will store the received bytes
    //! \param numOfWords specifies the number of bytes to be received
    //! \param txDelay specifies the number of serial clock cycles delay time after
    //!        completion of perious word
    //!
    //! This function is used to receive 'N' bytes of data
    //! This function uses SPI_pollingFIFOTransaction function.
    //! SPI character length must be configured to 8 bits BEFORE calling the
    //! function
    //!
    //! \return None.
    //
    //*****************************************************************************
    #define SPI_receiveNBytes(base, rxBuffer, numOfWords, txDelay)                 \
          SPI_pollingFIFOTransaction(base, 8U,  NULL, rxBuffer, numOfWords, txDelay)

    SPI_receive32Bits uses the SPI_pollingFIFOTransaction call as below

    uint32_t
    SPI_receive32Bits(uint32_t base, SPI_endianess endianness, uint16_t dummyData,
                      uint16_t txDelay)
    {
        uint16_t i;
        uint16_t txBuffer[4];
        uint16_t rxBuffer[4];
        uint32_t rxData = 0U;
    
        ASSERT(dummyData <= 0xFFU);
    
        //
        // Empty Transmit buffer
        //
        for(i = 0U; i < 4U; i++)
        {
            txBuffer[i] = dummyData;
            rxBuffer[i] = 0U;
        }
    
        //
        // Send dummy words to receive data from peripheral
        // Four 8-bits make a 32-bit
        // Character length = 8
        // number of bytes = 4
        //
        SPI_pollingFIFOTransaction(base, 8U, txBuffer, rxBuffer, 4U, txDelay);
    
        if(endianness == SPI_DATA_LITTLE_ENDIAN)
        {
            //
            // LITTLE_ENDIAN
            //
            rxData = ((uint32_t)rxBuffer[3] << 24U) |
                     ((uint32_t)rxBuffer[2] << 16U) |
                     ((uint32_t)rxBuffer[1] << 8U)  |
                     (uint32_t)rxBuffer[0];
        }
        else
        {
            //
            // BIG_ENDIAN
            //
            rxData = ((uint32_t)rxBuffer[0] << 24U) |
                     ((uint32_t)rxBuffer[1] << 16U) |
                     ((uint32_t)rxBuffer[2] << 8U)  |
                     (uint32_t)rxBuffer[3];
        }
    
        return(rxData);
    }
    

    I had to create an equivalent of SPI_receive32Bits to call SPI_pollingFIFOTransaction and then it all worked.

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    请参阅相关文章: e2e.ti.com/.../6222598