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.

SPI Problem

Other Parts Discussed in Thread: RM48L952, HALCOGEN, TEST2

Hi,

I'm using RM48L952, with CCS 6.1.0 and HALCoGen 04.04.00.

I’m trying to get communication between spi1 and spi2 by polling method.

The HALCoGen setting is as follows:

spi1  -  master         spi2 - slave

1) Driver TAB

             - Select SPI1

             - Select SPI2

2) SPI2 TAB

   - SPI2 Global SubTAB

- All unchecked            

  - SPI2 Port SubTAB

- SOMI set to output, all others are in INPUT mode.

3) SPI1 TAB                            

 - Have it default

My problem is, After calling “spiTransmitAndReceiveData” function data is being transmitted but I unfortunately receive 0x00FF in my RX_Data_Master (destbuff),

I also tried to change the Clock Phase or Clock Polarity, but the problem has not been solved.

Can you tell the reason for this?

Regards,

 

Fatemeh0726.SPI_test2.zip

  • Fatemeh,

    You are almost there, but there is a problem with your code.
    SPI1 is used as Master, SPI2 is used as Slave. I assume the connection are done between SPI1 and SPI2 at board level.

    In your main code, after doing the initialization of SPI1 and SPI2 (call to spiInit()) you only call the spiTransmitAndReceiveData for SPI1.

    This will start the transmission of TX_Data_Master, with the correct data, but SPI2 is not ready to receive or transmit.

    It is necessary to start the slave first by calling spiTransmitAndReceiveData if you want the Slave to receive the data from Master, but also to transmit data to the Master.

    Here a main code example:

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

    void main(void)
    {
    /* USER CODE BEGIN (3) */
        char command1[2];
        int i;
        spiDAT1_t dataconfig1_t;
        dataconfig1_t.CS_HOLD = FALSE;
        dataconfig1_t.WDEL    = TRUE;
        dataconfig1_t.DFSEL   = SPI_FMT_0;
        dataconfig1_t.CSNR    = 0xFC;


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

        while(1)
        {
            /* Initiate SPI1 Transmit and Receive through Polling Mode*/
            spiTransmitAndReceiveData(spiREG2, &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<16;i++)
            {
                printf("%d TX_Data_Slave: 0x%04x RX_Data_Slave: 0x%04x TX_Data_Master: 0x%04x RX_Data_Master: 0x%04x\r\n",i, TX_Data_Slave[i], RX_Data_Slave[i], TX_Data_Master[i], RX_Data_Master[i]);
            }
        }
    /* USER CODE END */
    }

     

    Please have a try and let me know.

  • Jean-Marc,

    Thanks for your help, As you mentioned I changed the code, but now when I call “spiTransmitAndReceiveData” function to service Slave (SPI2), code gets stuck in this loop "while((spi->FLG & 0x00000100U) != 0x00000100U) { } /* Wait */ "

    Best Regards,
    Fatemeh
  • Jean-Marc,

    There isn’t any connection between SPI1 and SPI2 at board level and unfortunately I didn't pay attention to this issue at that time.
    After I did the wiring externally, by using the interrupt module, I can receive the data I sent, it means the SPI (using interrupt) is working fine now.
    But the connection using polling method is not working yet. Can you help me to get this communication by polling method?


    Best Regards,
    Fatemeh
  • Fatemeh,

    What are the connection that you did between SPI1 and SPI2?

    Are you using 3 pin mode (SOMI, SIMO, CLK) or 4 pin mode (SOMI, SIMO, CLK, CSx)

    In Halcogen, on the SPI2 Port Tab, you should have SOMI, SIMO and CLK defined as SPI function (no GIO)
    If CS0 is also defined as SPI (not GIO) than it is necessary to have the same on the Master side and connect the CS line between Master and Slave.

  • Fatemeh,

    The polling mode function are blocking. When you call spiTransmitAndReceiveData on the slave SPI, the function will write the first data to be transmitted and will wait for the Receive flag. At that point, the Slave SPI can read the incoming data (from Master) and also write the next data to send to Master.

    So the CPU will be waiting for ever in this loop. The SPI1 Master will never send anything.

    In interrupt mode, the spiSendAndGetData is non blocking. The concept is similar, the Slave will write the first data to be sent to Master and will exit. The spiTransmitAndReceiveData on Master will be called and will write the first data to be sent to Slave.
    The transmission will start, and on completion, the Slave will get an interrupt. This will allow the Slave to read the incoming data, and to write the next data to be sent to Master.

    Polling mode can only be used between 2 physical device. The Slave will have to be started first (waiting for data from Master) and than the Master can start sending data to Slave.

    Please let me know if this make sense.

  • Jean-Marc,

    Thank you again for your reply, it was really helpful.

    Best Regards,
    Fatemeh