主题中讨论的其他器件:CC1310
您好!
我想知道如何在回调模式下退出 SPI_TRANSMIT。
CC1310 Launchpad 作为 SPI 从设备运行。
在获取 SPI 数据时、SPI 从器件不会不时调用回调。
此时、如何退出 SPI_TRANSMIT。 或者如何调用回调函数。
下面是我的 CC1310代码。
当 SPI 从器件正常运行时、 "transferOK"变量将设置为"0"。 然后其余代码运行。
#define SPI_MSG_LENGTH (200) + 3 #define DATA_ENTRY_HEADER_SIZE 8 // Constant header size of a Generic Data Entry #define MAX_LENGTH SPI_MSG_LENGTH // Set the length of the data entry #define NUM_DATA_ENTRIES 1 #define NUM_APPENDED_BYTES 0 /* TX queue or RF Core to read data from */ static dataQueue_t dataQueue; static rfc_dataEntryGeneral_t* currentDataEntry; static uint8_t *pPacket; static uint8_t txDataEntryBuffer[RF_QUEUE_DATA_ENTRY_BUFFER_SIZE(NUM_DATA_ENTRIES, MAX_LENGTH, NUM_APPENDED_BYTES)]; /***** Variable declarations *****/ static bool transferOK; static bool transferOK2; uint8_t slaveRxBuffer[SPI_MSG_LENGTH]; /* Pin driver handle */ static PIN_Handle ledPinHandle; static PIN_State ledPinState; PIN_Config ledPinTable[] = { Board_PIN_LED0 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, Board_PIN_LED1 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, PIN_TERMINATE }; static PIN_Handle slaveRdyHandle; static PIN_State slaveRdyState; PIN_Config slaveRdyTable[] = { Board_DIO21 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_DRVSTR_MAX, PIN_TERMINATE }; static PIN_Handle masterRdyHandle; static PIN_State masterRdyState; PIN_Config masterRdyTable[] = { Board_DIO15 | PIN_INPUT_EN, PIN_TERMINATE }; static void SPIRxCallback(SPI_Handle handle, SPI_Transaction *transaction) { transferOK2 = 0; if(transaction->status == SPI_TRANSFER_COMPLETED){ // Green PIN_setOutputValue(ledPinHandle, Board_PIN_LED1, !PIN_getOutputValue(Board_PIN_LED1)); } else{ PIN_setOutputValue(ledPinHandle, Board_PIN_LED0, !PIN_getOutputValue(Board_PIN_LED0)); } } void tx_callback(RF_Handle h, RF_CmdHandle ch, RF_EventMask e) { if(e & RF_EventLastCmdDone) { //PIN_setOutputValue(ledPinHandle, Board_PIN_LED0, !PIN_getOutputValue(Board_PIN_LED0)); } } void *mainThread(void *arg0) { // RF Setting RF_Object rfObject; RF_Handle rfHandle; RF_Params rfParams; RF_Params_init(&rfParams); // SPI Rx Setting SPI_Handle slaveSpi; SPI_Params spiParams; SPI_Transaction transaction; SPI_init(); if( RFQueue_defineQueue(&dataQueue, txDataEntryBuffer, sizeof(txDataEntryBuffer), NUM_DATA_ENTRIES, MAX_LENGTH + NUM_APPENDED_BYTES)) { /* Failed to allocate space for all data entries */ while(true); } RF_cmdTxHS.pQueue = &dataQueue; RF_cmdTxHS.startTrigger.triggerType = TRIG_NOW; RF_cmdTxHS.startTrigger.pastTrig = 1; RF_cmdTxHS.startTime = 0; currentDataEntry = (rfc_dataEntryGeneral_t*)&txDataEntryBuffer; currentDataEntry->length = SPI_MSG_LENGTH; pPacket = ¤tDataEntry->data; SPI_Params_init(&spiParams); spiParams.frameFormat = SPI_POL0_PHA1; spiParams.mode = SPI_SLAVE; spiParams.transferCallbackFxn = SPIRxCallback; spiParams.transferMode = SPI_MODE_CALLBACK; spiParams.bitRate = 4000000; slaveSpi = SPI_open(Board_SPI_SLAVE, &spiParams); if (slaveSpi == NULL) { while (1); } /* Request access to the radio */ rfHandle = RF_open(&rfObject, &RF_prop_hsm, (RF_RadioSetup*)&RF_cmdRadioSetup_hsm, &rfParams); /* Set the frequency */ //{ "868.0 ", 0x0364, 0x0000, 0x0 }, //{ "915.0 ", 0x0393, 0x0000, 0x0 }, RF_cmdFs_preDef.frequency = 0x0393; RF_cmdFs_preDef.fractFreq = 0x0000; RF_postCmd(rfHandle, (RF_Op*)&RF_cmdFs_preDef, RF_PriorityNormal, NULL, 0); /* Open LED pins */ ledPinHandle = PIN_open(&ledPinState, ledPinTable); if(!ledPinHandle) { /* Error initializing board LED pins */ while(1); } /* slave Ready pin */ slaveRdyHandle = PIN_open(&slaveRdyState, slaveRdyTable); if(!slaveRdyHandle) { /* Error initializing button pins */ while(1); } /* master Ready pin */ masterRdyHandle = PIN_open(&masterRdyState, masterRdyTable); if(!masterRdyHandle) { /* Error initializing button pins */ while(1); } /* Initialize slave SPI transaction structure */ transaction.count = SPI_MSG_LENGTH; transaction.txBuf = NULL; transaction.rxBuf = (void *) slaveRxBuffer; while(1) { transferOK2 = 1; memset(slaveRxBuffer, 0, SPI_MSG_LENGTH + 1); transferOK = SPI_transfer(slaveSpi, &transaction); if (transferOK) { while(!PIN_getInputValue(Board_DIO15)); PIN_setOutputValue(slaveRdyHandle, Board_DIO21, 1); while(transferOK2); PIN_setOutputValue(slaveRdyHandle, Board_DIO21, 0); memcpy(pPacket, slaveRxBuffer, SPI_MSG_LENGTH + 1); RF_postCmd(rfHandle, (RF_Op*)&RF_cmdTxHS, RF_PriorityNormal, NULL, 0); } else { } } }