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.

RTOS/CC2640R2F: CC2640

Part Number: CC2640R2F


Tool/software: TI-RTOS

I am using simple_peripheral_cc2640relp_app project  and i want to implement SPI as a slave .

1 I added #include <ti/drivers/SPI.h>   in simple_perip[eral.c

2. SPI configuration 

CC2640R2_LAUNCHXL_SPI0_MOSI | PIN_INPUT_EN | PIN_PULLDOWN, /* SPI master out - slave in */
CC2640R2_LAUNCHXL_SPI0_MISO | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL, /* SPI master in - slave out */
CC2640R2_LAUNCHXL_SPI0_CLK | PIN_INPUT_EN | PIN_PULLDOWN, /* SPI clock */
CC2640R2_LAUNCHXL_SPI0_CSN | PIN_BM_INPUT_EN | PIN_PULLDOWN,

/* SPI Board */
#define CC2640R2_LAUNCHXL_SPI0_MISO IOID_6 //IOID_8 /* RF1.20 */
#define CC2640R2_LAUNCHXL_SPI0_MOSI IOID_7 //IOID_9 /* RF1.18 */
#define CC2640R2_LAUNCHXL_SPI0_CLK IOID_10 /* RF1.16 */
#define CC2640R2_LAUNCHXL_SPI0_CSN IOID_20 //PIN_UNASSIGNED

static void SimpleBLEPeripheral_taskFxn(UArg a0, UArg a1)
{
// Initialize application
SimpleBLEPeripheral_init();

// for SPI
// Callback function


SPI_init();
// Init SPI and specify non-default parameters
SPI_Params_init(&spi_params);
spi_params.bitRate = 1000000;
spi_params.frameFormat = SPI_POL0_PHA1; //SPI_POL0_PHA0;
spi_params.mode = SPI_SLAVE;
spi_params.transferMode = SPI_MODE_CALLBACK;
spi_params.transferCallbackFxn = transferCallback;
// Configure the transaction
spi_transaction.count = 5;
spi_transaction.txBuf = tbuf;
spi_transaction.rxBuf = rbuf;
// Open the SPI and initiate the first transfer
spi_handle = SPI_open(Board_SPI0, &spi_params);
if (!spi_handle) {
// Log_error0(" UnSuccessfully transfer I2C ");
Display_printf(dispHandle,0,0,"SPI do not open\n");
}
else{
Display_printf(dispHandle,0,0,"SPI intialize successfully\n");
}
status = SPI_transfer(spi_handle, &spi_transaction);
if (status == false) {
// Log_error0(" UnSuccessfully transfer I2C ");
Display_printf(dispHandle,0,0,"UnSuccessfully receive the data SPI\n");
}
else{
Display_printf(dispHandle,0,0,"Successfully receive the data SPI\n");
for(int i =0;i<5;i++)
{
Display_print1(dispHandle, 5, 0, "data : %d\n", rbuf[i]);
}
}
// Wait forever
while(true);
}

From Master i am trasnferring 5 bytes but i count receive the bytes 

  • Can you start with a empty project with just SPI implemented and see if you can receive data?

    Do you have logic analyzer to capture the signal trace?
    When there is no data received, do you get any error msg?
  • Hi i implemented in simple peripheral project its is working fine the fault was the cs pin from master side was not low
    I am more queries

    If i implement the same code in project zero it is not working ?? as i want some characteristic feature of project zero so wat may the issue
  • It does not make sense that the same code works on simple_peripheral but not project zero.
    Can you provide more information, ex: the error code, the logic analyzer trace, and the code snippet?

    You can just move the characteristics into simple_peripheral project.
    You should be able to grab the needed files from project zero and follow SimpleLink Academy training--> Custom Profile when you include those files and services.
  • ok i will check and update you soon
  • Hi i am able to move the characteristic thanks for the same.

    In SPI i am not able to print the receive the data but when i debug the data is seen . i am confuse where should i receve the data after SPI_transfer(spi_handle, &spi_transaction); is success
  • If you have seen the data, then you should be able to print the data if you are using the same display driver that's integrated in the simple_peripheral example.

    If you can post your code snippet, we might be able to find out why it's not printing.
  • hi this is my code
    uint8_t tbuf[12] ={0x02,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B},rbuf[1] = {0}

    static void SimpleBLEPeripheral_taskFxn(UArg a0, UArg a1)
    {
    SimpleBLEPeripheral_init();

    for (;;)
    {
    uint32_t events;

    // Waits for an event to be posted associated with the calling thread.
    // Note that an event associated with a thread is posted when a
    // message is queued to the message receive queue of the thread
    events = Event_pend(syncEvent, Event_Id_NONE, SBP_ALL_EVENTS,
    ICALL_TIMEOUT_FOREVER);

    if (events)
    {
    ICall_EntityID dest;
    ICall_ServiceEnum src;
    ICall_HciExtEvt *pMsg = NULL;

    // Fetch any available messages that might have been sent from the stack
    if (ICall_fetchServiceMsg(&src, &dest,
    (void **)&pMsg) == ICALL_ERRNO_SUCCESS)
    {
    uint8 safeToDealloc = TRUE;

    if ((src == ICALL_SERVICE_CLASS_BLE) && (dest == selfEntity))
    {
    ICall_Stack_Event *pEvt = (ICall_Stack_Event *)pMsg;

    // Check for BLE stack events first
    if (pEvt->signature == 0xffff)
    {
    // The GATT server might have returned a blePending as it was trying
    // to process an ATT Response. Now that we finished with this
    // connection event, let's try sending any remaining ATT Responses
    // on the next connection event.
    if (pEvt->event_flag & SBP_HCI_CONN_EVT_END_EVT)
    {
    // Try to retransmit pending ATT Response (if any)
    SimpleBLEPeripheral_sendAttRsp();
    }
    }
    else
    {
    // Process inter-task message
    safeToDealloc = SimpleBLEPeripheral_processStackMsg((ICall_Hdr *)pMsg);
    }
    }

    if (pMsg && safeToDealloc)
    {
    ICall_freeMsg(pMsg);
    }
    }

    // If RTOS queue is not empty, process app message.
    if (events & SBP_QUEUE_EVT)
    {
    while (!Queue_empty(appMsgQueue))
    {
    sbpEvt_t *pMsg = (sbpEvt_t *)Util_dequeueMsg(appMsgQueue);
    if (pMsg)
    {
    // Process message.
    SimpleBLEPeripheral_processAppMsg(pMsg);

    // Free the space from the message.
    ICall_free(pMsg);
    }
    }
    }

    if (events & SBP_PERIODIC_EVT)
    {
    Util_startClock(&periodicClock);

    // Perform periodic application task
    SimpleBLEPeripheral_performPeriodicTask();
    }
    }
    }
    }
    void SimpleBLE_SPI_init(void)
    {
    SPI_init();
    // Init SPI and specify non-default parameters
    SPI_Params_init(&spi_params);
    spi_params.bitRate = 1000000;
    spi_params.frameFormat = SPI_POL0_PHA0;
    spi_params.dataSize = 8; //SPI_POL0_PHA0;
    spi_params.mode = SPI_SLAVE;
    spi_params.transferMode = SPI_MODE_CALLBACK;
    spi_params.transferCallbackFxn = SPI_transferCallback;
    // Configure the transaction
    spi_transaction.count = 11;
    spi_transaction.txBuf = tbuf;
    spi_transaction.rxBuf = rbuf;
    // Open the SPI and initiate the first transfer
    spi_handle = SPI_open(Board_SPI0, &spi_params);
    if (!spi_handle) {
    Display_printf(dispHandle,0,0,"SPI do not open\n");
    }
    else{
    Display_printf(dispHandle,0,0,"SPI open successfully\n");
    }
    Display_printf(dispHandle,0,0,"Ready to receive the data\n");


    }
    void SimpleBLE_SPI_transferdata(void)
    {


    status = SPI_transfer(spi_handle, &spi_transaction);

    if (status) {
    Display_printf(dispHandle,0,0,"Successfully receive the data SPI\n");

    }
    else{
    Display_printf(dispHandle,0,0,"UnSuccessfully receive SPI\n");
    }


    Display_print1(dispHandle, 0, 0, "received Ack from ESP32 rbuf[0]: %d\n", rbuf[0]);
    Display_print1(dispHandle, 0, 0, "received Ack from ESP32 rbuf[1]: %d\n", rbuf[1]);
    Display_print1(dispHandle, 0, 0, "received Ack from ESP32 rbuf[2]: %d\n", rbuf[2]);
    }

    from BLE app when i receiving the data then i init SPI and transfer the data
  • When you are in debug mode, you are able to see the data in rbuf right? Then will you be able to print the data in rbuf?
  • yes in debug mode i am able to see the data in expression and i did not get what are you saying
  • parth parth said:
    yes in debug mode i am able to see the data in expression and i did not get what are you saying

    hi

    i am really confuse why the rbuf is not displaying the data

     spi_handle = SPI_open(Board_SPI0, &spi_params);

       if (!spi_handle) {

           Display_printf(dispHandle,0,0,"SPI do not open\n");

       }

       else{

           Display_printf(dispHandle,0,0,"SPI open successfully\n");

       }

       Display_printf(dispHandle,0,0,"Ready to receive the data\n");

        spi_transaction.count = 10;

        spi_transaction.txBuf = tbuf;

        spi_transaction.rxBuf = rbuf;

        status = SPI_transfer(spi_handle, &spi_transaction);

        if (status) {

          Display_printf(dispHandle,0,0,"Successfully receive the data SPI\n");

       }

        else{

          Display_printf(dispHandle,0,0,"UnSuccessfully receive SPI\n");

        }

        Display_print1(dispHandle, 0, 0, "received Ack from ESP32 rbuf[1]: %02x\n",rbuf[1]);

        if(rbuf[1] == 0x04)

        {

            Display_printf(dispHandle,0,0,"Successfully receive 0x04SPI\n");

        }

        else

        {

            Display_printf(dispHandle,0,0,"did not receive 0x04SPI\n");

  • i cannot see in expression but i can see the vale at that adress 0x04
  • Hi,

    I am a bit confused by the memory map. It looks like that your display handle and spi handle are both 0. Then you won't be able to print and run SPI transaction at all.

    Also SPI transaction should be symmetrical (number of bytes on txbuffer and rxbuffer should be the same). However, in your code, your tx buf is 12 bytes and your rx buf is 2 bytes. Then in your spi init, the transaction count is 11... I am not sure what you are trying here.

    You can take a look at the SPI.h which contains example code.
  • the application is first master send me one bytes and on receiving one bytes slave transfer 12 bytes
  • Please take a look at SPI definition here : en.wikipedia.org/.../Serial_Peripheral_Interface_Bus
    Under Data transmission section:
    "During each SPI clock cycle, a full duplex data transmission occurs. The master sends a bit on the MOSI line and the slave reads it, while the slave sends a bit on the MISO line and the master reads it. This sequence is maintained even when only one-directional data transfer is intended."

    Therefore you need to make sure your txBuffer size is the same as your rxBuffer size. Please fix that in the code and test it stand alone SPI code before you integrate it into simple_peripheral
  • hi thanks for the reply

    I am been working with same buff size for tx and rx