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.

CC2640 Master adding SPI driver to SimpleBLEPeripheral

Other Parts Discussed in Thread: CC2640

I am trying to add the SPI driver to SimpleBLEPeripheral.c. I am using this driver in callback mode.

I have followed all the steps outlined in the SPICC26XXDMA.h file and in the RTOS 2.12 guide.

(TI RTOS 2.13.00.06, BLE Stack 2.1.1.44627).

I am calling the SPI init function from SimpleBLEPeripheral_init.

I am unable to see the SPI CLK on the scope. The only thing I am doing differently is selecting the

slave though an IOC function call. What might be going wrong here? The SPITransferOK variable

is taking on a value of 1 as I debug.

Thanks,

Priya

static void SPI_Callback (SPI_Handle spi, SPI_Transaction *spiTransaction)
{
 //  SPI_enqueueMsg();
}

static void SPI_ACAM_initialize(void)
{

 IOCPortConfigureSet(Board_ACSN ,IOC_PORT_MCU_SSI0_FSS,IOC_IOMODE_NORMAL);

    UInt peripheralNum = 1;

 SPI_Params spiParams;


    SPI_Params_init(&spiParams);
    spiParams.bitRate = 1000000;
    spiParams.dataSize = 8;
    spiParams.frameFormat = SPI_POL0_PHA1;
    spiParams.mode = SPI_MASTER;
    spiParams.transferMode = SPI_MODE_CALLBACK;
    spiParams.transferCallbackFxn = SPI_Callback;

    spi = SPI_open(peripheralNum, &spiParams);
    if (spi == NULL){
        System_abort("Error opening SPI");
    }


    spiTransaction.count = 4;
    spiTransaction.rxBuf = NULL;
    spiTransaction.txBuf = spi_tx_buf;


    SPITransferOK = SPI_transfer(spi, &spiTransaction);
    if (!SPITransferOK){
     System_abort("Error in SPI transfer or transfer is already in progress");
    }


}

  • Could it be the hardware chip select cannot be made through the IOC function call?
    I was not able to compile using SPI_control, it did not accept the SPICC26XXDMA_SET_CSN_PIN.
    I left the default csn pin for the SPI for the external flash memory, I am now trying to use
    an external A/D convertor.

    I added IOC calls for the three other SPI pins in main.c, I also opened the SPI using Board_SPI.
    I am still not seeing any clock with the SPI driver on the scope.
    Thanks,
    Priya
  • In TI-RTOS 2.13, if SPICC26XXDMA_SET_CSN_PIN fails (SPI_STATUS_ERROR), it's probably because the CS pin was already assigned somewhere else using the PIN driver. I'd use the PIN driver instead of the IOC calls directly. All the other TI-RTOS drivers for the CC26xx utilize the PIN driver for resource management.

    SPI_open() configures the pins for you. That information is stored in the SPI driver's hardware attributes. Search for SPI_config[] and you'll see its hwattrs defined for it.
  • I am continuing to get this error when I use the SPI_control to make the hardware chip select:
    Description Resource Path Location Type
    #20 identifier "SPICC26XXDMA_SET_CSN_PIN" is undefined simpleBLEPeripheral.c /SimpleBLEPeripheral/Application line 424 C/C++ Problem

    I understand the LCD driver uses the SPI in SimpleBLEPeripheral. I commented out the Board_openLCD(); definition inside SBP.c. The Board.h has only one Board_SPI0 definition which I am using to open the SPI in my custom function. Not sure where else to find the error.
    Thanks,
    Priya
  • I forgot to include in my post the custom board is a 4x4 package. The defines option for the LCD drivers has been turned off. Not sure why this hasn't automatically taken care of turning off any connection between SPI and LCD drivers automatically in SimpleBLEPEripheral.c?
    Thanks,
    Priya
  • You are using a SPICC26XXDMA-specific feature. I assume you have #include <ti/drivers/spi/SPICC26XXDMA.h>?
  • Thank you for your reply Tom. The compile error went away and I see the HW chip select activating at the right time. For some reason, the SPI_CLK is not showing up on the scope. Something else is still causing this problem.

    Priya
  • You said you're using a custom board. Do you see any other SPI pins toggle when you call SPI_transfer()? If you see CS and MOSI toggle, then you might have something on your board interfering with CLK. Do you have any other external devices on there that might be pulling the line down/up?
  • Tom,
    I debugged the SPI_MISO, SPI_MOSI, and SPI_CLK pins on the custom board by re-configuring them to be the UART transmit. The scope output looks fine on all of them so the board tracks are reaching the point where they are being probed without any connectivity problems. When I go back to using them in the SPI initialize function, the SPI CLK does not happen.

    Ever since I commented out the Board_openLCD inside SBP.c, the transferOK signal does not get set any more.

    I am pasting my function below for any insight. I have added the IOC calls in addition to defining the pins in the SPI_Config.
    I appreciate the help.

    Thanks,
    Priya

    static void SPI_Callback (SPI_Handle spi, SPI_Transaction *spiTransaction)
    {
    // SPI_enqueueMsg();
    }
    static void SPI_ACAM_initialize(void)
    {
    IOCPortConfigureSet(Board_SPI0_CLK, IOC_PORT_MCU_SSI0_CLK,IOC_IOMODE_NORMAL);
    IOCPortConfigureSet(Board_SPI0_MISO, IOC_PORT_MCU_SSI0_TX,IOC_IOMODE_NORMAL);
    IOCPortConfigureSet(Board_SPI0_MOSI, IOC_PORT_MCU_SSI0_RX,IOC_IOMODE_NORMAL);

    SPI_Params spiParams;

    PIN_Id csnPin1 = PIN_ID(Board_ACSN);
    SPI_control(spi, SPICC26XXDMA_SET_CSN_PIN, &csnPin1);

    SPI_Params_init(&spiParams);
    spiParams.bitRate = 1000000;
    spiParams.dataSize = 8;
    spiParams.frameFormat = SPI_POL0_PHA1;
    spiParams.mode = SPI_MASTER;
    spiParams.transferMode = SPI_MODE_CALLBACK;
    spiParams.transferCallbackFxn = SPI_Callback;

    spi = SPI_open(Board_SPI0, &spiParams);
    if (spi == NULL){
    System_abort("Error opening SPI");
    }



    spiTransaction.count = 4;
    spiTransaction.rxBuf = NULL;
    spiTransaction.txBuf = spi_tx_buf;


    SPITransferOK = SPI_transfer(spi, &spiTransaction);
    if (!SPITransferOK){
    System_abort("Error in SPI transfer or transfer is already in progress");
    }


    }
  • Setting breakpoints inside this function, the execution hangs at the SPI_control(spi, SPICC26XXDMA_SET_CSN_PIN, &csnPin1);
    The hardware chip select pin for the SPI slave is getting set though.
    Thanks,
    Priya
  • Tom-- I am not aware of any external device on the custom board interfering with the SPI_CLK. Since there are two peripherals driven by the MISO pin, I added the code to avoid conflict with the pull used for the CC26XX SPI for both the MISO and the SPI_CLK pins. It made no difference. The code still hangs during SPI transfer. I defaulted the csnPin in the HWAttrs to the peripheral currently of interest which is the external A/D converter. (so I don't need to use the SPI_Control at this time).

    Is this an RTOS issue of some kind? Or memory allocation? Please advice.

    The SBP code currently has both the UART and SPI drivers. I am trying this code out with using only one driver at a time. The UART part works as it used to prior to executing any of the SPI code.

    Thanks,
    Priya
  • Today I went back to a clean version of the SimpleBLEPeripheral.c file and added only the SPI Master driver. There is no UART driver that could cause any potential conflict. I changed the SPI to be used only in blocking mode which seems to be sufficient for the needs of our application.

    I am seeing no output from the MISO or SPICLK pins on the scope. The SPI_TRANSFEROK variable is getting set and I do see a valid address for the spi handle. Board_openLCD() is not being called on the 4x4 CC2640 package.

    I must be missing something very simple. How do I track this down?

    Thanks,

    Priya

  • Could using windows 10 be a factor in any of this? My machine at work has been crashing in an odd way thrice in the past two days, I'm having to power off at the connection chord and restart-- mouse stops working. I can't get it to display the ROV to find out where the exception happens. Or I should be debugging in more complex ways to find the exception. Or the error is some thing much simpler that I haven't seen yet. I will post the current code on Monday.
    Thanks,
    Priya
  • I am trying to debug adding the SPI driver to SimpleBLEPeripheral.c.

    I have combed the board.c and board.h files many times, pins match the schematic,
    the board tracks have been verified as working.

    When I halt the debugging and run tools ROV, nothing shows up. Even when I try to view
    the ROV to a plain copy of SimpleBLEPeripheral.c, I am not able to. Why is this?

    I tried enabling add Logging Setup to my configuration and commenting out the ROM
    lines from the .cfg script. Maybe I need to do more edits, the ROV still does not show up.

    I took a look at the CFSR register. It is all 0's.

    I still need some help about what else to do. I will post a new thread if no replies show
    up on this one.

    Thanks,
    Priya
  • The problem has been solved using the DK. For some reason, the scope did not register a one time SPI transfer. When an SPI transfer was piggy backed with several UART reads, I can see the SPI signals on the scope. If new complications show up, I will be back.
    Thanks,
    Priya