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.

RTOS/CC2650: SPI Comunication

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);
}

  • Hi Ayal,

    txBuf will be used when you are transmitting data to the slave (such as if you need to set the command as it seems like you need to in this case). I can’t really say what you would need to put in your transfer though as that depends on your slave device. rxBuf is used to receive data, such as when you’re ready to receive data from the device. If you're only transmitting data you want to set rxBuf to NULL, likewise when you're only receiving you set txBuf to NULL.

    In SPI_MODE_BLOCKING mode SPI_transfer() blocks code execution until the SPI transaction has completed. In SPI_MODE_CALLBACK SPI_transfer() does not block code execution and instead calls a SPI_CallbackFxn callback function when the transaction has completed.

    The SPI driver documentation has some code examples that can help you: SPICC26XX Driver Refernce

    Thanks,
    Gerardo

  • There was a suggested answer and since there has been no active on this thread for more than a week, the suggested answer was marked as verify. Please feel free to select the "Reject Answer" button and reply with more details.