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.

CCS/LAUNCHXL-CC2640R2: Connecting an SPI ADC to the LAUNCHBOARD

Part Number: LAUNCHXL-CC2640R2

Tool/software: Code Composer Studio

Hello Gang,

I have this project where I want to read ADC-Values from an ADC-Chip's SPI-Interface. So I connected my device to DIO8...DIO11 (MISO, MOSI, CLK, CS).

This is what the relevant(?) code looks like.
It will be trapped inside the while loop and not print the log to uart(why?)

...
 #include <stdbool.h> 
 #include <stdint.h>
 #include <stddef.h>
...
#include <ti/drivers/SPI.h>
...
  //spi innit
  SPI_Handle      mmasterSpi_handle;
  SPI_Params      mspiParams;
  SPI_Transaction mspitransaction;
  uint32_t        spi_i;
  bool            spi_transferOK;
  int32_t         spi_status;
  SPI_Params_init(&mspiParams); // Open SPI as master (default)
  mspiParams.frameFormat = SPI_POL0_PHA1;
  mspiParams.bitRate = 4000000;
  mmasterSpi_handle = SPI_open(Board_SPI_MASTER, &mspiParams);
  if (mmasterSpi_handle == NULL) {
      Log_error0("Error initializing master SPI\n");
      while (1);
  }
  else {
      Log_info0("Master SPI initialized\n");
  }

  • I simplified the innit to this.

    //spi innit
      /* Open SPI as master (default) */
      SPI_Handle      masterSpi;
      SPI_Params      spiParams;
      SPI_Transaction transaction;
      uint32_t        i;
      bool            transferOK;
      int32_t         status;
      SPI_Params_init(&spiParams);
      spiParams.frameFormat = SPI_POL0_PHA1;
      spiParams.bitRate = 4000000;
      masterSpi = SPI_open(Board_SPI_MASTER, &spiParams);
      if (masterSpi == NULL) {
          Log_error0("Project-Zero: Error initializing master SPI\n");
          while (1);
      }
      else {
          Log_info0("Project-Zero: Master SPI initialized\n");
      }

    Now it is exactly like in the spimaster-example which passes its innitialization...

  • Hi Jakob,

    First question to ask is if you called SPI_init() before SPI_open()? If not, it will fail. If you did, I suggest you step into the SPI_open() call when in debug to find out what makes it fuzz.

  • Hello M-W,

    M-W said:

    First question to ask is if you called SPI_init() before SPI_open()...

    I think I did, looking from my code...

    M-W said:

    If you did, I suggest you step into the SPI_open() call when in debug ...

    can do! Do you know this thing when you are so cramped up about solving something that you can't think straight and don't come up woith stuff like "stepping in the method that throws the error"? ^^;

    I will try this tonight!

    Cheers
    Jakob

  • Actually I did not call it. After fixing this, unfortunatelly, now SPI_init() doesn't work either. I put the SPI into an own thread and if that thread is calling SPI_init() the whole program crashes afterwards. If I comment that SPI_init(), it will execute, and run. My SPI-Thread looks like this:

    static void SPI_taskFxn(UArg a0, UArg a1)
    {
        Task_sleep(SPICINTERVAL_MS*1000/Clock_tickPeriod); //SPI_init() causes a sleep to be necessary
        Log_info0("SPI_taskFxn: Master SPI initialized\n");
        SPI_Params mspiParams;
        SPI_Handle mmasterSpihandle;
    
        // SPI main loop
        for (;;){
    
            Log_info1("SPI_taskFxn: SPI_taskFxn did its measurement and is now sleeping for %d milliseconds after",SPICINTERVAL_MS);
            Task_sleep(SPICINTERVAL_MS*1000/Clock_tickPeriod);
        }
    }

    This is a snippet from my main.c:

    int main()
    {
    
      /* Register Application callback to trap asserts raised in the Stack */
      RegisterAssertCback(AssertHandler);
    
      PIN_init(BoardGpioInitTable);
    
    #if !defined( POWER_SAVING )
      /* Set constraints for Standby, powerdown and idle mode */
      // PowerCC26XX_SB_DISALLOW may be redundant
      Power_setConstraint(PowerCC26XX_SB_DISALLOW);
      Power_setConstraint(PowerCC26XX_IDLE_PD_DISALLOW);
    #endif // POWER_SAVING | USE_FPGA
    
    #ifdef ICALL_JT
      /* Update User Configuration of the stack */
      user0Cfg.appServiceInfo->timerTickPeriod = Clock_tickPeriod;
      user0Cfg.appServiceInfo->timerMaxMillisecond  = ICall_getMaxMSecs();
    #endif  /* ICALL_JT */
    
      /* Initialize the RTOS Log formatting and output to UART in Idle thread.
       * Note: Define xdc_runtime_Log_DISABLE_ALL to remove all impact of Log.
       * Note: NULL as Params gives 115200,8,N,1 and Blocking mode */
      UART_init();
      UartLog_init(UART_open(Board_UART0, NULL));
      SPI_init();
      /* Initialize ICall module */
      ICall_init();
    

    I used the debugger to step into the SPI_init() and I see it is calling the initFxn

  • Hi Jacob, 

    Could you have a look at this thread and see if it might be what you are seeing:

    https://e2e.ti.com/support/wireless-connectivity/bluetooth/f/538/p/881789/3261917#3261917

  • Hi M-W,

    I continued to investigate and now it looks like its not even anything with SPI_Imit(), sorry for the trouble. Instead, the error is actually thrown, if I use the spi_thread that I programmed, there seems to be a bug there. Should we close here, since it is starting to drift of the innitial topic?

    Thanks for helping and sorry for the fuzz created!

    BR

    Jakob