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 help

Part Number: TMS320F2800157
Other Parts Discussed in Thread: C2000WARE

Hi,

I am integrating a SPI EEPROM with my system and have followed the SPI EEPROM example in C2000Ware 5.04.  One of the calls that aren't used in the example but is referenced is SPI_receiveNBytes.  Since I want to read a longer string of bytes in at a time, I thought this call would be benificial.

I noticed the example is designed around an EEPROM that only requires 16 bits of address and mine requires 24.  Thus I have made that modification to send the 24 bits of address.  This works with SPI_receive32Bits correctly. 

In the snip-it below I include both calls, and swapped between the SPI_receive32Bits and SPI_receiveNBytes.  The snip-it shows SPI_receiveNBytes commented out because I used SPI_receive32Bits in my last run. 

My problem is that both calls do not return the same data.  I know that SPI_receive32Bits only receives 32 bits, but those 32 bits recieved are correct.

A little more info on SPI_receiveNBytes.  I'm supplying length = 8 (bytes) and txdly = NO_DELAY.

Can you please show me where I'm falling in the pit?

// 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;
}
  • Doing a little more research, I found that SPI_receiveNBytes is defined in spi.h as below

    //*****************************************************************************
    //
    //! 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.