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.

TMS570LS1224: Issue of SPI

Part Number: TMS570LS1224
Other Parts Discussed in Thread: HALCOGEN

Hi,

I'm testing SPI in TMS570LS12x launch pad according to example_spi_Master_Slave.c in HalCogen. Because of there isn't SPI2 in my launch pad, I use SPI3 as slave. I think SPI1 works in poll mode and SPI3 in interrupt mode. It seems communication was failed by observing the receiving buffers of SPI1 and SPI3 via break point shown as below. Please help me to find out something wrong I made or missed.

The connections of pins are shown as below.

My configurations of PINMUX, driver enable, VIM, SPI1 and SPI3 are shown as below.

The test code is almost identical to example_spi_Master_Slave.c, except for SPI3 but SPI2, shown as below.

/* USER CODE BEGIN (0) */
/* USER CODE END */

/* Include Files */

#include "sys_common.h"

/* USER CODE BEGIN (1) */
#include "spi.h"
/* USER CODE END */

/* USER CODE BEGIN (2) */
uint16 TX_Data_Master[16] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10 };
uint16 TX_Data_Slave[16]  = { 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20 };
uint16 RX_Data_Master[16] = { 0 };
uint16 RX_Data_Slave[16]  = { 0 };
/* USER CODE END */

int main(void)
{
/* USER CODE BEGIN (3) */
    spiDAT1_t dataconfig1_t;

    dataconfig1_t.CS_HOLD = FALSE;
    dataconfig1_t.WDEL    = TRUE;
    dataconfig1_t.DFSEL   = SPI_FMT_0;
    dataconfig1_t.CSNR    = 0xFE;


    /* Enable CPU Interrupt through CPSR */
    _enable_IRQ();

    /* Initialize SPI Module Based on GUI configuration
     * SPI1 - Master ( SIMO, SOMI, CLK, CS0 )
     * SPI3 - Slave  ( SIMO, SOMI, CLK, CS0 )
     * */
    spiInit();

    /* Initiate SPI3 Transmit and Receive through Interrupt Mode */
    spiSendAndGetData(spiREG3, &dataconfig1_t, 16, TX_Data_Slave, RX_Data_Slave);

    /* Initiate SPI1 Transmit and Receive through Polling Mode*/
    spiTransmitAndReceiveData(spiREG1, &dataconfig1_t, 16, TX_Data_Master, RX_Data_Master);

    while(1);
/* USER CODE END */

    return 0;
}

/* USER CODE BEGIN (4) */
/* USER CODE END */

There is also one point confused me that only RXINT of SPI3 could be enabled in HalCoGen shown as below.

Best Regards

Datïan

  • Hello,

    Please correct your signal connection (SIMO <--> SOMI). The correct connection is:

    1. SPI1 SIMO -- SPI3 SIMO

    2. SPI1 SOMI  -- SPI3 SOMI

  • Hello QJ,

    Thanks a lot for your correction. That's I misunderstood the pins of SPI. After changing the pins, the sample works well.

    Then I enabled spiEnableNotification to generate requests of RXINTENA and TXINTENA. I think the two interrupts of transmitter empty and receiver full would be generated shown as below.

    However it seems 0x0100 of RXINTENA enabled both RXINTENA and TXINTENA. 0x0200 and/or 0x300 will cause master's receiving in poll mode incorrectly as below.

    Here are my functions of main and spiEndNotification. The line underlined is the way I enabled RXINTENA and/ or TXINTENA. Please correct my mistake ?

    int main(void)
    {
    /* USER CODE BEGIN (3) */
        int i;
        spiDAT1_t dataconfig1_t;
    
        dataconfig1_t.CS_HOLD = FALSE;
        dataconfig1_t.WDEL    = TRUE;
        dataconfig1_t.DFSEL   = SPI_FMT_0;
        dataconfig1_t.CSNR    = 0xFE;
    
        gioInit();
    
        /* Enable CPU Interrupt through CPSR */
        _enable_IRQ();
    
        /* Initialize SPI Module Based on GUI configuration
         * SPI1 - Master ( SIMO, SOMI, CLK, CS0 )
         * SPI3 - Slave  ( SIMO, SOMI, CLK, CS0 )
         * */
        spiInit();
    
        spiEnableNotification(spiREG3, 0x0100U);//0x0100 R buffer is full; 0x0200 T buffer is empty
    
        while(1)
        {
            /* Initiate SPI3 Transmit and Receive through Interrupt Mode */
            spiSendAndGetData(spiREG3, &dataconfig1_t, 16, TX_Data_Slave, RX_Data_Slave);
    
            /* Initiate SPI1 Transmit and Receive through Polling Mode*/
            spiTransmitAndReceiveData(spiREG1, &dataconfig1_t, 16, TX_Data_Master, RX_Data_Master);
    
            for(i=0;i<DELAY_VALUE;i++);
    
            if(RX_Data_Master[15]==0x20)
            {
                RX_Data_Master[15]=0;
            }
            else
            {
                while(1);
            }
        }
    /* USER CODE END */
    
        return 0;
    }
    
    /* USER CODE BEGIN (4) */
    /** @fn void spiEndNotification(spiBASE_t *spi)
    *   @brief Interrupt callback for End of TX or RX data length.
    *   @param[in] spi   - Spi module base address
    *
    * This is a callback that is provided by the application and is called upon
    * an interrupt at the End of TX or RX data length.
    */
    void spiEndNotification(spiBASE_t *spi)
    {
        if(SPI_COMPLETED==SpiRxStatus(spi))
        {
            if(RX_Data_Slave[15]==0X10)
            {
                RX_Data_Slave[15]=0;
                gioToggleBit(gioPORTB, 1);
                return;
            }
           else
           {
               gioSetBit(gioPORTB, 1, 0);
               return;
           }
        }else if(SPI_COMPLETED==SpiTxStatus(spi))
        {
            gioToggleBit(gioPORTB, 2);
            return;
        }
        else
        {
            gioSetBit(gioPORTB, 2, 0);
            return;
        }
    }
    /* USER CODE END */

    Kind Regards

    Datïan

     

  • Hello,

    I noticed you use a while() to tx and rx data continuously. Please check the RX and TX are done before doing next transmission.

    Just adding a delay is not good enough: for(i=0;i<DELAY_VALUE;i++);

  • Hello QJ,

    Thank you very much. I'll try it.

    Warm Regards

    Datïan

  • Hello QJ,

    I use SpiRxStatus(spiREG1) to check whether the receiving of master is finished. But the receiving buffer is not as I expecting of { 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20 }.

    Best Regards

    Datïan

  • Hello Datian,

    Please post the data of TX_Data_Slave, and received RX_Data_Master. I'd like to know which byte is different? How about the TX_Data_Master, and RX_Data_Slave?

  • Hello QJ,

    No problem. The high lighted part is TX_data_Slave, which was received incorrectly by Master.

    Here is the snapshot of incorrect RX_Data_Master observed by a break point, in the case of spiEnableNotification(spiREG3, 0x200u).

    And here is the correct RX_Data_Master observed by the other break point, in the case of spiEnableNotification(spiREG3, 0x100u).

    Warm Regards

    Datïan

  • Hi Datian,

    spiSendAndGetData() is to TX and RX data in interrupt mode, and the TX and RX interrupt are enabled in this function. Calling spiEnableNotification() before assigning value to g_spiPacket_t[] is not a correct way. 

    When happens if you remove spiEnableNotification(spiREG3, ...) before while(1) loop?

  • Hi QJ,

    Many thanks for your very helpful information of spiEnableNotification should not be called in the case of calling spiSendAndGetData. After I removed spiEnableNotification, it works very well as spiEnableNotification(spiREG3, 0x0100U).

    Normally I will reference "Help Topics" in HalCogen, when an issue is emereged. The "Help Topics" is very good. May I ask you recommend more materials about this kind of topics for me ?

    Kind regards

    Datïan

  • There are several example at: 

    If your issue has been solved, please click "This resolved my issue". Thanks

  • Hello QJ,

    Sure, thank you very much. It is very helpful.

    Warm Regards

    Datïan