Part Number: CC2650
Tool/software: TI-RTOS
hi,
I'm trying to read the data from a slave (an accelerometer), and to start I just want to read it's ID. I'm not sure how exactly SPI_transfer works though.. if I just want to read data, should I set the READ command in txBuf[0] and then the specific register I want to read in txBuf[1]? what should I put in rxBuf? and what is CallBack mode good for?
my code:
// In the comments is code that maybe useful, but not in use at the moment.
/* XDCtools Header files */
#include <xdc/std.h>
#include <xdc/cfg/global.h>
#include <xdc/runtime/System.h>
#include <xdc/runtime/Error.h>
/* BIOS Header files */
#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Task.h>
/* TI-RTOS Header files */
#include <ti/drivers/GPIO.h>
#include <ti/drivers/PIN.h>
#include <ti/drivers/SPI.h>
#include <ti/drivers/pin/PINCC26XX.h>
/*Board Header files */
#include "Board.h"
#include "Adxl362.h"
#include <stdbool.h>
#include <stdio.h>
#include <driverlib/cpu.h>
PIN_Handle pinHandle;
SPI_Handle handle;
SPI_Params Params;
SPI_Transaction spiTransaction;
Task_Struct taskStart;
Task_Params taskParams;
Error_Block eb;
uint8_t txBuffer[3] = {ADXL362_READ_REG, ADXL362_REG_DEVID_MST, 0};
uint8_t rxBuffer[3];
uint8_t taskStartStack[512];
bool ret;
Void myTask(UArg arg0, UArg arg1) {
SPI_Params_init(&Params);
handle = SPI_open(Board_SPI0, &Params);
if (!handle) {
System_printf("SPI did not open");
}
spiTransaction.count = 1;
spiTransaction.txBuf = txBuffer;
spiTransaction.rxBuf = rxBuffer;
PIN_setOutputValue(pinHandle, Board_SPI0_CSN, 0);
ret = SPI_transfer(handle, &spiTransaction);
if (!ret) {
System_printf("Unsuccessful SPI transfer");
}
PIN_setOutputValue(pinHandle, Board_SPI0_CSN, 1);
}
int main(void) {
PIN_init(BoardGpioInitTable);
Board_initSPI();
Task_Params_init(&taskParams);
Error_init(&eb);
taskParams.stack = taskStartStack;
taskParams.stackSize = sizeof(taskStartStack);
Task_construct(&taskStart, myTask, &taskParams, &eb);
BIOS_start();
return (0);
}