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.

CC2745P10-Q1: SPI transmit issue

Part Number: CC2745P10-Q1

Tool/software:

I have installed latest SDK (simplelink_lowpower_f3_sdk_9_11_00_18) for CC2745. And I have using SPI to communicate with other peripheral devices. When i am transmitting the SPI signal i am not getting a clock properly. But MOSI signal seems ok with 1MHz bitrate.

In SPI i consider CC2745 as controller. bitrate 1MHz.

Also after one transmit code get stuck in Hard Fault Handler , 

Exception_handlerSpin() function. 
Please tell me what are the functions has to be call an parameter has to update before SPI transmit.

  • Hello Anto,

    Can I get a little more information about what you are trying to implement, and your current code? It might be something with how you are initializing the SPI communication so I would like to see how you are setting it up. Thanks.

    Eshaan

  • Hi,

    /*
     *  ======== spicontroller.c ========
     */
    #include <stddef.h>
    #include <stdint.h>
    #include <string.h>
    
    /* POSIX Header files */
    #include <pthread.h>
    #include <semaphore.h>
    #include <unistd.h>
    
    /* Driver Header files */
    #include <ti/drivers/GPIO.h>
    #include <ti/drivers/SPI.h>
    #include <ti/display/Display.h>
    
    /* Driver configuration */
    #include "ti_drivers_config.h"
    
    #define THREADSTACKSIZE (1024)
    
    #define SPI_MSG_LENGTH (256)
    #define CONTROLLER_MSG ("Hello from controller, msg#: ")
    
    #define MAX_LOOP (10)
    
    #ifdef DeviceFamily_CC35XX
        #define CONFIG_GPIO_LED_0 GPIO_INVALID_INDEX
        #define CONFIG_GPIO_LED_1 GPIO_INVALID_INDEX
    #endif
    
    uint8_t example_string[270]={0xAA,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,
                                  2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
                                  3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
                                  4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
                                  1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                                  2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
                                  3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
                                  4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,0xFF    };
    
    unsigned char controllerRxBuffer[SPI_MSG_LENGTH];
    unsigned char controllerTxBuffer[SPI_MSG_LENGTH];
    
    /* Semaphore to block controller until peripheral is ready for transfer */
    sem_t controllerSem;
    
    void spiCallbackFxn(SPI_Handle controllerSpi, SPI_Transaction *tran);
    
    /* Default SPI parameters structure */
    const SPI_Params NFC_SPI = {
        SPI_MODE_CALLBACK, /* transferMode */
        1000,  /* transferTimeout */
        spiCallbackFxn,    /* transferCallbackFxn */
        SPI_CONTROLLER,    /* mode */
        1000000,           /* bitRate */
        8,                 /* dataSize */
        SPI_POL0_PHA0,     /* frameFormat */
        NULL               /* custom */
    };
    
    /*
     *  ======== peripheralReadyFxn ========
     *  Callback function for the GPIO interrupt on CONFIG_SPI_PERIPHERAL_READY.
     */
    void peripheralReadyFxn(uint_least8_t index)
    {
        sem_post(&controllerSem);
        
    }
      SPI_Handle controllerSpi ; //controllerSpi;    //SPI_config
        SPI_Params spiParams;
        SPI_Transaction transaction;
        SPI_Mode Controller = SPI_CONTROLLER;
        uint32_t i;
        bool transferOK;
        int32_t status;
    /*
     *  ======== controllerThread ========
     *  Controller SPI sends a message to peripheral while simultaneously receiving a
     *  message from the peripheral.
     */
    void SPI_Init(void )
    {
      
        SPI_init();
        /* Open SPI as controller (default) */
      //  SPI_Params_init(&NFC_SPI);
        controllerSpi  = SPI_open(Controller, &NFC_SPI);
        /*
         * Controller has opened CONFIG_SPI_CONTROLLER; set
         * CONFIG_SPI_CONTROLLER_READY low to inform the peripheral.
         */
        // GPIO_write(CONFIG_GPIO_SPI_0_CSN, 1);
            /* Initialize controller SPI transaction structure */
          //  controllerTxBuffer[sizeof(CONTROLLER_MSG) - 1] = (i % 10) + '0';
            transaction.count = 8;
            transaction.txBuf = (void *)controllerTxBuffer;
            transaction.rxBuf = (void *)controllerRxBuffer;
    
    }
    
    void spiCallbackFxn(SPI_Handle controllerSpi, SPI_Transaction *tran)
    {
           sem_t *semPtr = (sem_t *)(tran->arg);
         // Post the semaphore if our transaction was more than LIMIT
           if (tran->status == SPI_STATUS_SUCCESS ){//&& tran->count > LIMIT) {
               sem_post(semPtr);
          }
      }
    _Bool SPI_Sts_Info=0;
    void SPI_Tx_test(void){
          /* Perform SPI transfer */
          // GPIO_write(CONFIG_GPIO_SPI_0_CSN, 0);
            transaction.txBuf = (void *)example_string;
            transferOK = SPI_transfer(controllerSpi, &transaction);
            if (transferOK)
            {
                SPI_Sts_Info=1;
            }
            else
            {
                 SPI_Sts_Info=0;
            }
    
        SPI_close(controllerSpi);
    }

  • Hi,

    What device are you using as the peripheral, and are you able to establish a handshake or at least initial connection before you start a transfer? Also, can you please send a picture of your output/error so I can see exactly what message you are getting?

    However, on initial review of the code, I recommend using library SPI_Params_init() and then manually changing the parameters. This will initialize the parameters as per the stack default, so it will ensure the struct follows the required format for SPI_open(). Also, I notice you have SPI_Init() and SPI_Tx_test() as separate functions, but I don't see a main function that shows how you are calling those two functions. If you do have one, it would help to also see that function so that I can what order you are calling these functions in.

    Thanks

  • Hi,

    I am catching the signa with logic analyzer,

    currently i am testing transmit only, in the above screen short the clock is not proper, but the MOSI signal is perfectly transmitted.

    I am not getting the callback at spiCallbackFxn after transfer success,

    in "  transferOK = SPI_transfer(controllerSpi, &transaction); " here return status shows one (transferOK). 

    I am calling the "SPI_Tx_test()" function in 1 sec time interval at 1ms timer callback.

    after first transfer i am able to get timer callback one time. 

  • i have modified code little but same response, in SPI clock

    /*
     *  ======== spicontroller.c ========
     */
    #include <stddef.h>
    #include <stdint.h>
    #include <string.h>
    
    /* POSIX Header files */
    #include <pthread.h>
    #include <semaphore.h>
    #include <unistd.h>
    
    /* Driver Header files */
    #include <ti/drivers/GPIO.h>
    #include <ti/drivers/SPI.h>
    #include <ti/display/Display.h>
    
    /* Driver configuration */
    #include "ti_drivers_config.h"
    
    #define THREADSTACKSIZE (1024)
    
    #define SPI_MSG_LENGTH (256)
    #define CONTROLLER_MSG ("Hello from controller, msg#: ")
    
    #define MAX_LOOP (10)
    
    #ifdef DeviceFamily_CC35XX
        #define CONFIG_GPIO_LED_0 GPIO_INVALID_INDEX
        #define CONFIG_GPIO_LED_1 GPIO_INVALID_INDEX
    #endif
    
    uint8_t example_string[270]={0xAA,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,
                                  2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
                                  3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
                                  4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
                                  1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                                  2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
                                  3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
                                  4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,0xFF    };
    
    unsigned char controllerRxBuffer[SPI_MSG_LENGTH];
    unsigned char controllerTxBuffer[SPI_MSG_LENGTH];
    
    /* Semaphore to block controller until peripheral is ready for transfer */
    sem_t controllerSem;
    
    void spiCallbackFxn(SPI_Handle controllerSpi, SPI_Transaction *tran);
    
    /* Default SPI parameters structure */
    // const SPI_Params NFC_SPI = {
    //     SPI_MODE_CALLBACK, /* transferMode */
    //     100,  /* transferTimeout */
    //     spiCallbackFxn,    /* transferCallbackFxn */
    //     SPI_CONTROLLER,    /* mode */
    //     1000000,           /* bitRate */
    //     8,                 /* dataSize */
    //     SPI_POL0_PHA0,     /* frameFormat */
    //     NULL               /* custom */
    // };
    
    /*
     *  ======== peripheralReadyFxn ========
     *  Callback function for the GPIO interrupt on CONFIG_SPI_PERIPHERAL_READY.
     */
    void peripheralReadyFxn(uint_least8_t index)
    {
        sem_post(&controllerSem);
        
    }
      SPI_Handle controllerSpi ; //controllerSpi;    //SPI_config
        SPI_Params NFC_SPI;
        SPI_Transaction transaction;
        SPI_Mode Controller = SPI_CONTROLLER;
        uint32_t i;
        bool transferOK;
        int32_t status;
    /*
     *  ======== controllerThread ========
     *  Controller SPI sends a message to peripheral while simultaneously receiving a
     *  message from the peripheral.
     */
    void SPI_Init(void )
    {
      
        SPI_init();
        /* Open SPI as controller (default) */
        SPI_Params_init(&NFC_SPI);
        NFC_SPI.transferMode = SPI_MODE_CALLBACK, /* transferMode */
       // NFC_SPI.transferTimeout=      100,  /* transferTimeout */
        NFC_SPI.transferCallbackFxn=    spiCallbackFxn,    /* transferCallbackFxn */
        NFC_SPI.mode  =   SPI_CONTROLLER,    /* mode */
        NFC_SPI.bitRate =     1000000,           /* bitRate */
        NFC_SPI.dataSize =     8,                 /* dataSize */
        NFC_SPI.frameFormat =      SPI_POL0_PHA0,     /* frameFormat */
    
        controllerSpi  = SPI_open(Controller, &NFC_SPI);
        /*
         * Controller has opened CONFIG_SPI_CONTROLLER; set
         * CONFIG_SPI_CONTROLLER_READY low to inform the peripheral.
         */
        // GPIO_write(CONFIG_GPIO_SPI_0_CSN, 1);
            /* Initialize controller SPI transaction structure */
          //  controllerTxBuffer[sizeof(CONTROLLER_MSG) - 1] = (i % 10) + '0';
            transaction.count = 8;
            transaction.txBuf = (void *)controllerTxBuffer;
            transaction.rxBuf = (void *)controllerRxBuffer;
    
    }
    
    void spiCallbackFxn(SPI_Handle controllerSpi, SPI_Transaction *tran)
    {
           sem_t *semPtr = (sem_t *)(tran->arg);
         // Post the semaphore if our transaction was more than LIMIT
           if (tran->status == SPI_STATUS_SUCCESS ){//&& tran->count > LIMIT) {
               sem_post(semPtr);
          }
      }
    _Bool SPI_Sts_Info=0;
    void SPI_Tx_test(void){
          /* Perform SPI transfer */
          // GPIO_write(CONFIG_GPIO_SPI_0_CSN, 0);
            transaction.txBuf = (void *)example_string;
            transferOK = SPI_transfer(controllerSpi, &transaction);
            if (transferOK)
            {
                SPI_Sts_Info=1;
            }
            else
            {
                 SPI_Sts_Info=0;
            }
      //  SPI_close(controllerSpi);
    }

  • Hi Anto,

    Based on the code you provided, I see that you don't have any conditions that are checking to see if the peripheral device is actually ready for a transfer. If you are constantly transmitting signals without continuously checking if peripheral device is also ready, you will see the behavior you are currently observing, and the callbackFxn will only work the first time. So, I suggest that in addition to a timer callback/interrupt, you also initialize a semaphore associate with a GPIO or other signal that signals to the SPI protocol that a device is ready to transmit before actually calling SPI_transfer().

     Eshaan

  • Hi Eshaan,

    I have the peripheral with out ready pin, I don't have to check pre condition. when i transmit data from chip select pin peripheral will able to get ready and receive signal.

    Please give the information for the clock signal shown below, 

    it is expected clock signal. (from other chip)

    this is i received from CC2745

  • Hello Anto,

    I apologize for the late reply; I am looking into the issue and will get back you on Monday or Tuesday.

    Eshaan

  • Hello Anto,

    I tried recreating the issue you are seeing using two CC2745s and basic SPI demo, but I am not seeing the same clock sync issue. Is your peripheral device also a TI device?