Other Parts Discussed in Thread: CC1310
Hi all.
I try to combine SPI Slave and RF Tx module.
I attached to SPI slave blocking mode in my code. It run but not correctly.
I want to work synchronize with SPI Master.
I want to set read position that no overlap.
So i think SPI slave callback mode can use like interrupt. But it doesn't work.
I have some question.
1. How can i use SPI slave callback in non-RTOS? if it can't, How can i synchronize SPI master?
2. Do you have SPI Slave Timing diagram?
Below is apart of my code.
------------------------------------------------------------------------------------------------------------------------------------------------
void *mainThread(void *arg0)
{
// RF Setting
RF_Params rfParams;
RF_Params_init(&rfParams);
RF_cmdPropTx.pktLen = SPI_MSG_LENGTH;
RF_cmdPropTx.pPkt = RFTxBuffer;//packet;
RF_cmdPropTx.startTrigger.triggerType = TRIG_NOW;
// SPI Rx Setting
SPI_Handle slaveSpi;
SPI_Params spiParams;
SPI_Transaction transaction;
GPIO_init();
SPI_init();
UART_init();
static UART_Handle uart;
static UART_Params uartParams;
/* 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 = 115200;
uart = UART_open(Board_UART0, &uartParams);
if (uart == NULL) {
/* UART_open() failed */
while (1);
}
SPI_Params_init(&spiParams);
spiParams.dataSize = 8;
spiParams.bitRate = 4000000;
spiParams.frameFormat = SPI_POL0_PHA0;
spiParams.mode = SPI_SLAVE;
spiParams.transferCallbackFxn = Callback;
spiParams.transferMode = SPI_MODE_CALLBACK;
slaveSpi = SPI_open(Board_SPI_SLAVE, &spiParams);
if (slaveSpi == NULL) {
while (1);
}
/* Open LED pins */
ledPinHandle1 = PIN_open(&ledPinState1, pinTable1);
ledPinHandle2 = PIN_open(&ledPinState2, pinTable2);
if (ledPinHandle1 == NULL || ledPinHandle2 == NULL)
{
while(1);
}
/* Request access to the radio */
rfHandle = RF_open(&rfObject, &RF_prop, (RF_RadioSetup*)&RF_cmdPropRadioDivSetup, &rfParams);
/* Set the frequency */
RF_postCmd(rfHandle, (RF_Op*)&RF_cmdFs, RF_PriorityNormal, NULL, 0);
/* Initialize slave SPI transaction structure */
transaction.count = SPI_MSG_LENGTH;
transaction.txBuf = NULL;
transaction.rxBuf = (void *) slaveRxBuffer;
while(1)
{
// SPI_transfer(slaveSpi, &transaction);
// if(packetRxCb){
// RF_postCmd(rfHandle, (RF_Op*)&RF_cmdPropTx,RF_PriorityNormal, NULL, 0);
// packetRxCb = false;
// }
SPI_transfer(slaveSpi, &transaction);
if (transferOK) {
memcpy(RFTxBuffer, slaveRxBuffer, SPI_MSG_LENGTH);
UART_write(uart, (&RFTxBuffer), SPI_MSG_LENGTH);
UART_write(uart, "\n\r", 2);
transferOK = false;
PIN_setOutputValue(ledPinHandle1, Board_PIN_LED1,!PIN_getOutputValue(Board_PIN_LED1));
}
else {
PIN_setOutputValue(ledPinHandle2, Board_PIN_LED2,!PIN_getOutputValue(Board_PIN_LED2));
}
}
}
void Callback(SPI_Handle handle, SPI_Transaction *transaction)
{
if(transaction->status == SPI_TRANSFER_COMPLETED){
transferOK = true;
}
}