SWRA578B October 2017 – April 2020 CC1312PSIP , CC1312R , CC1314R10 , CC1352P , CC1352P7 , CC1352R , CC2620 , CC2630 , CC2640 , CC2640R2F-Q1 , CC2642R , CC2642R-Q1 , CC2650MODA , CC2652P , CC2652R , CC2652R7 , CC2652RB , CC2652RSIP
The SPI transfer example is created in the following way:
#include <string.h>
/* Driver Header files */
#include <ti/drivers/GPIO.h>
#include <ti/drivers/SPI.h>
#include <ti/sysbios/knl/Task.h>
#include <ti/sysbios/knl/Clock.h>
#include <ti/sysbios/knl/Semaphore.h>
#include <ti/sysbios/BIOS.h>
/* Driver configuration */
#include "ti_drivers_config.h"
#define WAKEUPFREQUENCY 100
#define SPI_MSG_LENGTH (18)
#define MASTER_MSG ("Texas Instruments!")
unsigned char masterTxBuffer[SPI_MSG_LENGTH];
Semaphore_Struct semLedTask;
Semaphore_Params semParams;
void spiCallback(SPI_Handle spiHandle, SPI_Transaction *transaction);
SPI_Handle spiHandle;
SPI_Params spiParams;
SPI_Transaction transaction;
/* ======== mainThread ======== */
void *mainThread(void *arg0) {
SPI_init();
SPI_Params_init(&spiParams);
spiParams.bitRate = 1000000;
spiParams.transferMode = SPI_MODE_CALLBACK;
spiParams.transferCallbackFxn = spiCallback;
strncpy((char *) masterTxBuffer, MASTER_MSG, SPI_MSG_LENGTH);
transaction.count = SPI_MSG_LENGTH;
transaction.txBuf = (void *) masterTxBuffer;
// Create the semaphore used to wait for Sensor Controller ALERT events
Semaphore_Params_init(&semParams);
semParams.mode = Semaphore_Mode_BINARY;
Semaphore_construct(&semLedTask, 0, &semParams);
while(1){
spiHandle = SPI_open(CONFIG_SPI_MASTER, &spiParams);
SPI_transfer(spiHandle, &transaction);
Semaphore_pend(Semaphore_handle(&semLedTask), BIOS_WAIT_FOREVER);
SPI_close(spiHandle);
Task_sleep((1000000/WAKEUPFREQUENCY) / Clock_tickPeriod);
}
}
void spiCallback(SPI_Handle spiHandle, SPI_Transaction *transactions){
Semaphore_post(Semaphore_handle(&semLedTask));
}