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 sample

Other Parts Discussed in Thread: CC1310, SYSBIOS

Hi

I want to build a SPI sample based on uartEach sample that two CC1310 devices talk each other.

My code is below. Open the SPI with Master/Slave mode according to UART input. I don't know why every SPI_transfer will return FALSE, and the second SPI_transfer will not block for recieving.

#define SPI_TRANSFER_SLAVE_STRING "hello, SPI Slave..."
#define SPI_TRANSFER_MASTER_STRING "hello, SPI Master..."
Void echoFxn(UArg arg0, UArg arg1)
{
    uint8_t isTx;
    char input, output;
    UART_Handle uart;
    UART_Params uartParams;
    SPI_Handle spi;
    SPI_Params spiParams;
    SPI_Transaction spTrans;
    char buffer[128] = "\fSPI Sample:\r\n";

    /* Create a UART with data processing off. */
    UART_Params_init(&uartParams);
    uartParams.writeDataMode = UART_DATA_BINARY;
    uartParams.readDataMode = UART_DATA_BINARY;
    uartParams.readReturnMode = UART_RETURN_FULL;
    uartParams.readEcho = UART_ECHO_OFF;
    uartParams.baudRate = 9600;
    uart = UART_open(Board_UART0, &uartParams);
    
    SPI_Params_init(&spiParams);
    spiParams.bitRate           = 1000000;                     /*!< SPI bit rate in Hz */
    spiParams.frameFormat = SPI_POL1_PHA1;

    if (uart == NULL) {
        System_abort("Error opening the UART");
    }
    
    UART_write(uart, buffer, strlen(buffer));
    UART_read(uart, &input, 1);
    
    memset(&spTrans, 0, sizeof(SPI_Transaction));

    if ('1' == input) {
      spiParams.mode              = SPI_MASTER;                    /*!< Master or Slave mode */
      strcpy(buffer, "SPI open with Master mode");
      isTx = FALSE;
    } else {
      spiParams.mode              = SPI_SLAVE;                    /*!< Master or Slave mode */
      isTx = TRUE;
      strcpy(buffer, "SPI open with Slave mode");
    }
    UART_write(uart, buffer, strlen(buffer));
    
    spi = SPI_open(Board_SPI0, &spiParams);
    if (spi == NULL) {
      System_abort("Error opening the UART");
    }

    /* Loop forever echoing */
    while (1) {
      if (SPI_MASTER == spiParams.mode) {
        spTrans.count = strlen (SPI_TRANSFER_SLAVE_STRING);
        spTrans.txBuf = SPI_TRANSFER_SLAVE_STRING;
        spTrans.rxBuf = NULL;        
        SPI_transfer(spi, &spTrans);
      } else {
        spTrans.count = strlen (SPI_TRANSFER_SLAVE_STRING);
        spTrans.txBuf = NULL;
        spTrans.rxBuf = buffer;
        SPI_transfer(spi, &spTrans);
      }
    }
}

  • Hi,
    Can you check that you have pins on the two boards properly connected? Also, you can either step through the SPI_transfer() code or build with the instrumented TI-RTOS library (to get Log statements) to see why SPI_transfer() is returning false.
    To build with the instrumented TI-RTOS library, add the following to your .cfg file:

    var TIRTOS = xdc.useModule('ti.tirtos.TIRTOS');
    TIRTOS.libType = TIRTOS.LibType_NonInstrumented;

    Best regards,
    Janet
  • Hi Janet

    Thanks for your reply. SPI communication is ready now.

    And I noticed the debug function provided by TI RTOS as you said.
    I use the IAR for my production development, so how to get these debug information in my environment?

    Thanks,
    HH
  • For the TI-RTOS instrumented library, you will also need to create a Log and enable logging. The easiest way to do this is to add this line to your .cfg file:

    var LoggingSetup = xdc.useModule('ti.uia.sysbios.LoggingSetup');

    Then rebuild your application. For IAR, to view the Log records, you will need to have enabled the TI-RTOS plugin for your project. Then you should be able to view the LoggerStopMode 'Main' logger where the TI-RTOS driver log records are placed. See this wiki topic for using the TI-RTOS plugin with IAR:

    processors.wiki.ti.com/.../Creating_TI-RTOS_Applications_in_IAR_Embedded_Workbench

    Unfortunately, it doesn't show a screen shot of the LoggerStopMode plugin, but hopefully it should be straight-forward to use.
    Best regards,
    Janet