Other Parts Discussed in Thread: CC1310
Good afternoon,
I have an issue and I can't seem to find why it won't work.
I have an SD card module attached to the SPI pins of the CC1310 launchpad. When using the code snippit below, I can open the SD card, create a file, write in it and close it. This works perfectly fine.
/* * ======== sdraw.c ======== */ #include <stddef.h> #include <stdint.h> #include <stdlib.h> #include <string.h> #include <time.h> #include <String.h> /* Driver Header files */ #include <ti/drivers/GPIO.h> #include <ti/drivers/SD.h> #include <ti/display/Display.h> #include <third_party/fatfs/ff.h> #include <third_party/fatfs/diskio.h> #include <third_party/fatfs/ffcio.h> #include <third_party/fatfs/ffconf.h> #include "ti/drivers/SDFatFS.h" /* Example/Board Header files */ #include "Board.h" int32_t fatfs_getFatTime(void){ time_t seconds; uint32_t fatTime; struct tm *pTime; /* * TI time() returns seconds elapsed since 1900, while other tools * return seconds from 1970. However, both TI and GNU localtime() * sets tm tm_year to number of years since 1900. */ seconds = time(NULL); pTime = localtime(&seconds); /* * localtime() sets pTime->tm_year to number of years * since 1900, so subtract 80 from tm_year to get FAT time * offset from 1980. */ fatTime = ((uint32_t)(pTime->tm_year - 80) << 25) | ((uint32_t)(pTime->tm_mon) << 21) | ((uint32_t)(pTime->tm_mday) << 16) | ((uint32_t)(pTime->tm_hour) << 11) | ((uint32_t)(pTime->tm_min) << 5) | ((uint32_t)(pTime->tm_sec) >> 1); return ((int32_t)fatTime); } SDFatFS_Object myObj; SDFatFS_Config SDFatFS_config[] = { { &myObj }, NULL }; uint_least8_t SDFatFS_count = sizeof(SDFatFS_config) / sizeof(SDFatFS_config[0]) - 1; void createTxtFileOnSD(uint32_t BASEID, float data, uint32_t IDSENSOR, uint8_t time, uint8_t date){ FIL fsrc; /* File objects */ FRESULT fr; /* FatFs function common result code */ UINT bw; /* File read/write count */ SD_init(); SDFatFS_Handle sd_handle; SDFatFS_init(); sd_handle = SDFatFS_open(Board_SD0,0); if (sd_handle == NULL) { } uint32_t TXTID = BASEID; int TXTFILENAME; char TXTNAME[15]; TXTFILENAME = snprintf(TXTNAME, 15, "%d.txt", TXTID); fr = f_open(&fsrc, TXTNAME, FA_OPEN_EXISTING | FA_WRITE); switch (fr) { case FR_NO_FILE: fr = f_open(&fsrc, TXTNAME, FA_CREATE_NEW | FA_WRITE); case FR_OK: f_open(&fsrc, TXTNAME, FA_OPEN_APPEND | FA_WRITE); default: break; } if(fr != 0) { } char buffer[100]; char buffer2[100]; int cx; int cx2; int counter = 0; while(counter <1) { cx = snprintf (buffer, sizeof(buffer), "\{\"%d\":\[", BASEID); cx2 = snprintf (buffer2, sizeof(buffer2), "\"ID\":\"%d\"\, \"Data\":%0.2f\," "\"time\":\"%d\"\, \"date\":\"%d\"\}\]\}\r\n", IDSENSOR, data, time, date); fr = f_write(&fsrc, buffer, cx, &bw); fr = f_write(&fsrc, buffer2, cx2, &bw); CPUdelay(8000 * (100)); counter++; if(fr != 0) { } /* Try to sync */ fr = f_sync(&fsrc); if(fr != 0){ } } /* Close open files */ fr = f_close(&fsrc); } void *mainThread(void *arg0) { Display_init(); GPIO_init(); uint32_t BASEID = 113400; uint32_t SENSID = 123; uint32_t SENSID2 = 1234; float temperature = 34.9; float temperature2 = 35.7; uint8_t time = 13; uint8_t date = 15; createTxtFileOnSD(BASEID, temperature, SENSID, time, date); createTxtFileOnSD(BASEID, temperature2, SENSID2, time, date); createTxtFileOnSD(BASEID, temperature, SENSID, time, date); return(NULL); }
In the code below, I receive an RF packet, decode and unpack it using my custom libraries and code, and then move on to the next packet in the queue. This works perfectly fine as well.
/* * Copyright (c) 2019, Texas Instruments Incorporated * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of Texas Instruments Incorporated nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /***** Includes *****/ /* Standard C Libraries */ #include <stdlib.h> /* TI Drivers */ #include <time.h> #include <ti/drivers/rf/RF.h> #include <ti/drivers/PIN.h> #include <ti/drivers/gpio.h> /* Driverlib Header files */ #include DeviceFamily_constructPath(driverlib/rf_prop_mailbox.h) /* Board Header files */ #include "Board.h" /* Application Header files */ #include "RFQueue.h" #include "smartrf_settings/smartrf_settings.h" /* Custom header files*/ #include <Manchester.h> #include <CRC8.h> /***** Defines *****/ /* Packet RX Configuration */ #define DATA_ENTRY_HEADER_SIZE 9 /* Constant header size of a Generic Data Entry */ #define MAX_LENGTH 19 /* Max length byte the radio will accept */ #define NUM_DATA_ENTRIES 2 /* NOTE: Only two data entries supported at the moment */ #define NUM_APPENDED_BYTES 2 /* The Data Entries data field will contain: * 1 Header byte (RF_cmdPropRx.rxConf.bIncludeHdr = 0x1) * Max 30 payload bytes * 1 status byte (RF_cmdPropRx.rxConf.bAppendStatus = 0x1) */ /***** Prototypes *****/ static void callback(RF_Handle h, RF_CmdHandle ch, RF_EventMask e); /***** Variable declarations *****/ static RF_Object rfObject; static RF_Handle rfHandle; /* Pin driver handle */ static PIN_Handle ledPinHandle; static PIN_State ledPinState; /* Buffer which contains all Data Entries for receiving data. * Pragmas are needed to make sure this buffer is 4 byte aligned (requirement from the RF Core) */ #if defined(__TI_COMPILER_VERSION__) #pragma DATA_ALIGN (rxDataEntryBuffer, 4); static uint8_t rxDataEntryBuffer[RF_QUEUE_DATA_ENTRY_BUFFER_SIZE(NUM_DATA_ENTRIES, MAX_LENGTH, NUM_APPENDED_BYTES)]; #elif defined(__IAR_SYSTEMS_ICC__) #pragma data_alignment = 4 static uint8_t rxDataEntryBuffer[RF_QUEUE_DATA_ENTRY_BUFFER_SIZE(NUM_DATA_ENTRIES, MAX_LENGTH, NUM_APPENDED_BYTES)]; #elif defined(__GNUC__) static uint8_t rxDataEntryBuffer[RF_QUEUE_DATA_ENTRY_BUFFER_SIZE(NUM_DATA_ENTRIES, MAX_LENGTH, NUM_APPENDED_BYTES)] __attribute__((aligned(4))); #else #error This compiler is not supported. #endif /* Receive dataQueue for RF Core to fill in data */ static dataQueue_t dataQueue; static rfc_dataEntryGeneral_t* currentDataEntry; static uint8_t packetLength; static uint8_t* packetDataPointer; uint8_t payload[19]; static uint8_t packet[MAX_LENGTH + NUM_APPENDED_BYTES - 1]; /* The length byte is stored in a separate variable */ uint16_t count = 0; void toggle(); void toggle(){ uint8_t CRC_OK_NOK = 0; float DataCalc = 0; float degC = 0; float hum = 0; float vbat = 0; uint8_t LENGTH =0; uint8_t ID0=0; uint8_t ID1=0; uint8_t ID2=0; uint32_t ID_FULL = 0; uint8_t TYPE=0; uint8_t DATA0=0; uint8_t DATA1=0; uint16_t DATA_FULL = 0; uint8_t CRC=0; uint8_t nCRC=0; uint32_t temp_id = 0; uint16_t temp_id5 = 0; int c = 0; for (c = 0; c < 19; c++) { payload[c] = manDecode(packet[c]); } LENGTH |= payload[0]; LENGTH <<= 4; LENGTH |= payload[1]; GPIO_toggle(Board_GPIO_RLED); if(LENGTH == 5){ ID0 |= payload[4]; ID0 <<= 4; ID0 |= payload[5]; ID1 |= payload[2]; ID1 <<= 4; ID1 |= payload[3]; DATA0 |= payload[6]; DATA0 <<= 4; DATA0 |= payload[7]; DATA1 |= payload[8]; DATA1 <<= 4; DATA1 |= payload[9]; CRC |= payload[10]; CRC <<= 4; CRC |= payload[11]; CRC_OK_NOK = doCrc(LENGTH, ID0, ID1, 0, 0, DATA0, DATA1, CRC, 0); DATA_FULL |= DATA0; DATA_FULL <<=8; DATA_FULL |= DATA1; DataCalc = DATA_FULL; ID_FULL |= ID0; ID_FULL <<=8; ID_FULL |= ID1; if(CRC_OK_NOK == 1) { DataCalc /= 100; DataCalc *=0.78125; // IF LAATSTE BIT ID 1 IS DAN IS HET TEMP temp_id5 = ID_FULL; temp_id5 <<= 15; temp_id5 >>= 15; if(temp_id5 == 1) { degC = DataCalc; } else { hum = DataCalc; } } } if(LENGTH == 7) { ID0 |= payload[6]; ID0 <<= 4; ID0 |= payload[7]; ID1 |= payload[4]; ID1 <<= 4; ID1 |= payload[5]; ID2 |= payload[2]; ID2 <<= 4; ID2 |= payload[3]; TYPE |= payload[8]; TYPE <<= 4; TYPE |= payload[9]; DATA0 |= payload[10]; DATA0 <<= 4; DATA0 |= payload[11]; DATA1 |= payload[12]; DATA1 <<= 4; DATA1 |= payload[13]; CRC |= payload[14]; CRC <<= 4; CRC |= payload[15]; nCRC |= payload[16]; nCRC <<= 4; nCRC |= payload[17]; CRC_OK_NOK = doCrc(LENGTH, ID0, ID1, ID2, TYPE, DATA0, DATA1, CRC, nCRC); DATA_FULL |= DATA0; DATA_FULL <<=8; DATA_FULL |= DATA1; ID_FULL |= ID0; ID_FULL <<=8; ID_FULL |= ID1; ID_FULL <<=8; ID_FULL |= ID2; if(CRC_OK_NOK == 1) { switch (TYPE) { case 32: //20, CHECKED: TC77 OR MCP9808 DATA_FULL <<= 3; degC = DATA_FULL; degC /= 100; degC *= 0.09765625; break; case 0x48: //30, NOT CHECKED: T6613 // not used break; case 64: //40, CHECKED: SHT10 temp_id = 0; temp_id = ID_FULL; temp_id <<= 31; temp_id >>= 31; // IF LAATSTE BIT ID 1 IS DAN IS HET HUM if(temp_id == 1) { //IF HUM: float tempHum = DATA_FULL * DATA_FULL; tempHum *=1.5955E-6; hum = DATA_FULL; hum *= 0.0367; hum -= 2.0468; hum -= tempHum; } else{ degC = DATA_FULL; degC *= 0.01; degC -= 39.6; } break; case 80: //50, NOT CHECKED //HDS1080 // //IF HUM: // hum = DATA; // hum *= 0.152587890625; // // // IF TEMP: // degC = DATA; // degC *= 0.25177001953125; // degC -= 4000; break; case 224: //E0 CHECKED: temp pt100 degC = DATA_FULL; degC /= 100; degC *= 0.390625; break; case 240: //F0, CHECKED bat volt vbat = 2097.152; vbat /= DATA_FULL; break; default: // UNKNOWN DataCalc = 69420; break; } } } count++; } /* * Application LED pin configuration table: * - All LEDs board LEDs are off. */ PIN_Config pinTable[] = { Board_PIN_LED2 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, PIN_TERMINATE }; /***** Function definitions *****/ void *mainThread(void *arg0) { GPIO_init(); GPIO_setConfig(Board_GPIO_RLED, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW ); RF_Params rfParams; RF_Params_init(&rfParams); if( RFQueue_defineQueue(&dataQueue, rxDataEntryBuffer, sizeof(rxDataEntryBuffer), NUM_DATA_ENTRIES, MAX_LENGTH + NUM_APPENDED_BYTES)) { /* Failed to allocate space for all data entries */ while(1); } /* Set the Data Entity queue for received data */ RF_cmdPropRx.pQueue = &dataQueue; /* Discard ignored packets from Rx queue */ RF_cmdPropRx.rxConf.bAutoFlushIgnored = 1; /* Implement packet length filtering to avoid PROP_ERROR_RXBUF */ RF_cmdPropRx.maxPktLen = MAX_LENGTH; RF_cmdPropRx.pktConf.bRepeatOk = 1; RF_cmdPropRx.pktConf.bRepeatNok = 1; /* Request access to the radio */ #if defined(DeviceFamily_CC26X0R2) rfHandle = RF_open(&rfObject, &RF_prop, (RF_RadioSetup*)&RF_cmdPropRadioSetup, &rfParams); #else rfHandle = RF_open(&rfObject, &RF_prop, (RF_RadioSetup*)&RF_cmdPropRadioDivSetup, &rfParams); #endif// DeviceFamily_CC26X0R2 /* Set the frequency */ RF_postCmd(rfHandle, (RF_Op*)&RF_cmdFs, RF_PriorityNormal, NULL, 0); /* Enter RX mode and stay forever in RX */ RF_EventMask terminationReason = RF_runCmd(rfHandle, (RF_Op*)&RF_cmdPropRx, RF_PriorityNormal, &callback, RF_EventRxEntryDone); while(1) { } } void callback(RF_Handle h, RF_CmdHandle ch, RF_EventMask e) { if (e & RF_EventRxEntryDone) { /* Toggle pin to indicate RX */ // PIN_setOutputValue(ledPinHandle, Board_PIN_LED2, // !PIN_getOutputValue(Board_PIN_LED2)); /* Get current unhandled data entry */ currentDataEntry = RFQueue_getDataEntry(); /* Handle the packet data, located at ¤tDataEntry->data: * - Length is the first byte with the current configuration * - Data starts from the second byte */ packetLength = 19; packetDataPointer = (uint8_t*)(¤tDataEntry->data + 1); /* Copy the payload + the status byte to the packet variable */ memcpy(packet, packetDataPointer, (packetLength + 1)); RFQueue_nextEntry(); toggle(); } }
But when I combine the two codes like in the code block below, it gets stuck. Using breakpoints I found it gets stuck somewhere in f_open. (As you can see I defined some dummy data to save to the SD card for test purposes.)
/* * Copyright (c) 2019, Texas Instruments Incorporated * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of Texas Instruments Incorporated nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /***** Includes *****/ /* Standard C Libraries */ #include <stdlib.h> /* TI Drivers */ #include <time.h> #include <ti/drivers/rf/RF.h> #include <ti/drivers/PIN.h> #include <ti/drivers/gpio.h> /* Driverlib Header files */ #include DeviceFamily_constructPath(driverlib/rf_prop_mailbox.h) /* Board Header files */ #include "Board.h" /* Application Header files */ #include "RFQueue.h" #include "smartrf_settings/smartrf_settings.h" /* SD driver headers */ #include <ti/drivers/SD.h> #include <ti/display/Display.h> #include <third_party/fatfs/ff.h> #include <third_party/fatfs/diskio.h> #include <third_party/fatfs/ffcio.h> #include <third_party/fatfs/ffconf.h> #include "ti/drivers/SDFatFS.h" /* Custom header files*/ #include <Manchester.h> #include <CRC8.h> /***** Defines *****/ /* Packet RX Configuration */ #define DATA_ENTRY_HEADER_SIZE 9 /* Constant header size of a Generic Data Entry */ #define MAX_LENGTH 19 /* Max length byte the radio will accept */ #define NUM_DATA_ENTRIES 2 /* NOTE: Only two data entries supported at the moment */ #define NUM_APPENDED_BYTES 2 /* The Data Entries data field will contain: * 1 Header byte (RF_cmdPropRx.rxConf.bIncludeHdr = 0x1) * Max 30 payload bytes * 1 status byte (RF_cmdPropRx.rxConf.bAppendStatus = 0x1) */ /***** Prototypes *****/ static void callback(RF_Handle h, RF_CmdHandle ch, RF_EventMask e); /***** Variable declarations *****/ static RF_Object rfObject; static RF_Handle rfHandle; /* Pin driver handle */ static PIN_Handle ledPinHandle; static PIN_State ledPinState; /* Buffer which contains all Data Entries for receiving data. * Pragmas are needed to make sure this buffer is 4 byte aligned (requirement from the RF Core) */ #if defined(__TI_COMPILER_VERSION__) #pragma DATA_ALIGN (rxDataEntryBuffer, 4); static uint8_t rxDataEntryBuffer[RF_QUEUE_DATA_ENTRY_BUFFER_SIZE(NUM_DATA_ENTRIES, MAX_LENGTH, NUM_APPENDED_BYTES)]; #elif defined(__IAR_SYSTEMS_ICC__) #pragma data_alignment = 4 static uint8_t rxDataEntryBuffer[RF_QUEUE_DATA_ENTRY_BUFFER_SIZE(NUM_DATA_ENTRIES, MAX_LENGTH, NUM_APPENDED_BYTES)]; #elif defined(__GNUC__) static uint8_t rxDataEntryBuffer[RF_QUEUE_DATA_ENTRY_BUFFER_SIZE(NUM_DATA_ENTRIES, MAX_LENGTH, NUM_APPENDED_BYTES)] __attribute__((aligned(4))); #else #error This compiler is not supported. #endif /* Receive dataQueue for RF Core to fill in data */ static dataQueue_t dataQueue; static rfc_dataEntryGeneral_t* currentDataEntry; static uint8_t packetLength; static uint8_t* packetDataPointer; uint8_t payload[19]; int32_t fatfs_getFatTime(void){ time_t seconds; uint32_t fatTime; struct tm *pTime; /* * TI time() returns seconds elapsed since 1900, while other tools * return seconds from 1970. However, both TI and GNU localtime() * sets tm tm_year to number of years since 1900. */ seconds = time(NULL); pTime = localtime(&seconds); /* * localtime() sets pTime->tm_year to number of years * since 1900, so subtract 80 from tm_year to get FAT time * offset from 1980. */ fatTime = ((uint32_t)(pTime->tm_year - 80) << 25) | ((uint32_t)(pTime->tm_mon) << 21) | ((uint32_t)(pTime->tm_mday) << 16) | ((uint32_t)(pTime->tm_hour) << 11) | ((uint32_t)(pTime->tm_min) << 5) | ((uint32_t)(pTime->tm_sec) >> 1); return ((int32_t)fatTime); } SDFatFS_Object myObj; SDFatFS_Config SDFatFS_config[] = { { &myObj }, NULL }; uint_least8_t SDFatFS_count = sizeof(SDFatFS_config) / sizeof(SDFatFS_config[0]) - 1; void createTxtFileOnSD(uint32_t BASEID, float data, uint32_t IDSENSOR, uint8_t time, uint8_t date){ FIL fsrc; /* File objects */ FRESULT fr; /* FatFs function common result code */ UINT bw; /* File read/write count */ SDFatFS_Handle sd_handle; SDFatFS_init(); sd_handle = SDFatFS_open(Board_SD0,0); if (sd_handle == NULL) { while(1); } uint32_t TXTID = BASEID; int TXTFILENAME; char TXTNAME[15]; TXTFILENAME = snprintf(TXTNAME, 15, "%d.txt", TXTID); fr = f_open(&fsrc, TXTNAME, FA_OPEN_EXISTING | FA_WRITE); switch (fr) { case FR_NO_FILE: fr = f_open(&fsrc, TXTNAME, FA_CREATE_NEW | FA_WRITE); case FR_OK: f_open(&fsrc, TXTNAME, FA_OPEN_APPEND | FA_WRITE); default: break; } if(fr != 0) { while(1); } char buffer[100]; char buffer2[100]; int cx; int cx2; int counter = 0; while(counter <1) { cx = snprintf (buffer, sizeof(buffer), "\{\"%d\":\[", BASEID); cx2 = snprintf (buffer2, sizeof(buffer2), "\"ID\":\"%d\"\, \"Data\":%0.2f\," "\"time\":\"%d\"\, \"date\":\"%d\"\}\]\}\r\n", IDSENSOR, data, time, date); fr = f_write(&fsrc, buffer, cx, &bw); fr = f_write(&fsrc, buffer2, cx2, &bw); CPUdelay(8000 * (100)); counter++; if(fr != 0) { while(1); } /* Try to sync */ fr = f_sync(&fsrc); if(fr != 0){ while(1); } } /* Close open files */ fr = f_close(&fsrc); } static uint8_t packet[MAX_LENGTH + NUM_APPENDED_BYTES - 1]; /* The length byte is stored in a separate variable */ uint16_t count = 0; void toggle(); void toggle(){ uint32_t BASEID = 113400; uint32_t SENSID = 123; float temperature = 34.9; uint8_t time = 13; uint8_t date = 15; createTxtFileOnSD(BASEID, temperature, SENSID, time, date); uint8_t CRC_OK_NOK = 0; float DataCalc = 0; float degC = 0; float hum = 0; float vbat = 0; uint8_t LENGTH =0; uint8_t ID0=0; uint8_t ID1=0; uint8_t ID2=0; uint32_t ID_FULL = 0; uint8_t TYPE=0; uint8_t DATA0=0; uint8_t DATA1=0; uint16_t DATA_FULL = 0; uint8_t CRC=0; uint8_t nCRC=0; uint32_t temp_id = 0; uint16_t temp_id5 = 0; int c = 0; for (c = 0; c < 19; c++) { payload[c] = manDecode(packet[c]); } LENGTH |= payload[0]; LENGTH <<= 4; LENGTH |= payload[1]; GPIO_toggle(Board_GPIO_RLED); if(LENGTH == 5){ ID0 |= payload[4]; ID0 <<= 4; ID0 |= payload[5]; ID1 |= payload[2]; ID1 <<= 4; ID1 |= payload[3]; DATA0 |= payload[6]; DATA0 <<= 4; DATA0 |= payload[7]; DATA1 |= payload[8]; DATA1 <<= 4; DATA1 |= payload[9]; CRC |= payload[10]; CRC <<= 4; CRC |= payload[11]; CRC_OK_NOK = doCrc(LENGTH, ID0, ID1, 0, 0, DATA0, DATA1, CRC, 0); DATA_FULL |= DATA0; DATA_FULL <<=8; DATA_FULL |= DATA1; DataCalc = DATA_FULL; ID_FULL |= ID0; ID_FULL <<=8; ID_FULL |= ID1; if(CRC_OK_NOK == 1) { DataCalc /= 100; DataCalc *=0.78125; // IF LAATSTE BIT ID 1 IS DAN IS HET TEMP temp_id5 = ID_FULL; temp_id5 <<= 15; temp_id5 >>= 15; if(temp_id5 == 1) { degC = DataCalc; } else { hum = DataCalc; } } } if(LENGTH == 7) { ID0 |= payload[6]; ID0 <<= 4; ID0 |= payload[7]; ID1 |= payload[4]; ID1 <<= 4; ID1 |= payload[5]; ID2 |= payload[2]; ID2 <<= 4; ID2 |= payload[3]; TYPE |= payload[8]; TYPE <<= 4; TYPE |= payload[9]; DATA0 |= payload[10]; DATA0 <<= 4; DATA0 |= payload[11]; DATA1 |= payload[12]; DATA1 <<= 4; DATA1 |= payload[13]; CRC |= payload[14]; CRC <<= 4; CRC |= payload[15]; nCRC |= payload[16]; nCRC <<= 4; nCRC |= payload[17]; CRC_OK_NOK = doCrc(LENGTH, ID0, ID1, ID2, TYPE, DATA0, DATA1, CRC, nCRC); DATA_FULL |= DATA0; DATA_FULL <<=8; DATA_FULL |= DATA1; ID_FULL |= ID0; ID_FULL <<=8; ID_FULL |= ID1; ID_FULL <<=8; ID_FULL |= ID2; if(CRC_OK_NOK == 1) { switch (TYPE) { case 32: //20, CHECKED: TC77 OR MCP9808 DATA_FULL <<= 3; degC = DATA_FULL; degC /= 100; degC *= 0.09765625; break; case 0x48: //30, NOT CHECKED: T6613 // not used break; case 64: //40, CHECKED: SHT10 temp_id = 0; temp_id = ID_FULL; temp_id <<= 31; temp_id >>= 31; // IF LAATSTE BIT ID 1 IS DAN IS HET HUM if(temp_id == 1) { //IF HUM: float tempHum = DATA_FULL * DATA_FULL; tempHum *=1.5955E-6; hum = DATA_FULL; hum *= 0.0367; hum -= 2.0468; hum -= tempHum; } else{ degC = DATA_FULL; degC *= 0.01; degC -= 39.6; } break; case 80: //50, NOT CHECKED //HDS1080 // //IF HUM: // hum = DATA; // hum *= 0.152587890625; // // // IF TEMP: // degC = DATA; // degC *= 0.25177001953125; // degC -= 4000; break; case 224: //E0 CHECKED: temp pt100 degC = DATA_FULL; degC /= 100; degC *= 0.390625; break; case 240: //F0, CHECKED bat volt vbat = 2097.152; vbat /= DATA_FULL; break; default: // UNKNOWN DataCalc = 69420; break; } } } count++; } /* * Application LED pin configuration table: * - All LEDs board LEDs are off. */ PIN_Config pinTable[] = { Board_PIN_LED2 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, PIN_TERMINATE }; /***** Function definitions *****/ void *mainThread(void *arg0) { GPIO_init(); GPIO_setConfig(Board_GPIO_RLED, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW ); RF_Params rfParams; RF_Params_init(&rfParams); if( RFQueue_defineQueue(&dataQueue, rxDataEntryBuffer, sizeof(rxDataEntryBuffer), NUM_DATA_ENTRIES, MAX_LENGTH + NUM_APPENDED_BYTES)) { /* Failed to allocate space for all data entries */ while(1); } /* Set the Data Entity queue for received data */ RF_cmdPropRx.pQueue = &dataQueue; /* Discard ignored packets from Rx queue */ RF_cmdPropRx.rxConf.bAutoFlushIgnored = 1; /* Implement packet length filtering to avoid PROP_ERROR_RXBUF */ RF_cmdPropRx.maxPktLen = MAX_LENGTH; RF_cmdPropRx.pktConf.bRepeatOk = 1; RF_cmdPropRx.pktConf.bRepeatNok = 1; /* Request access to the radio */ #if defined(DeviceFamily_CC26X0R2) rfHandle = RF_open(&rfObject, &RF_prop, (RF_RadioSetup*)&RF_cmdPropRadioSetup, &rfParams); #else rfHandle = RF_open(&rfObject, &RF_prop, (RF_RadioSetup*)&RF_cmdPropRadioDivSetup, &rfParams); #endif// DeviceFamily_CC26X0R2 /* Set the frequency */ RF_postCmd(rfHandle, (RF_Op*)&RF_cmdFs, RF_PriorityNormal, NULL, 0); /* Enter RX mode and stay forever in RX */ RF_EventMask terminationReason = RF_runCmd(rfHandle, (RF_Op*)&RF_cmdPropRx, RF_PriorityNormal, &callback, RF_EventRxEntryDone); while(1) { } } void callback(RF_Handle h, RF_CmdHandle ch, RF_EventMask e) { if (e & RF_EventRxEntryDone) { /* Toggle pin to indicate RX */ // PIN_setOutputValue(ledPinHandle, Board_PIN_LED2, // !PIN_getOutputValue(Board_PIN_LED2)); /* Get current unhandled data entry */ currentDataEntry = RFQueue_getDataEntry(); /* Handle the packet data, located at ¤tDataEntry->data: * - Length is the first byte with the current configuration * - Data starts from the second byte */ packetLength = 19; packetDataPointer = (uint8_t*)(¤tDataEntry->data + 1); /* Copy the payload + the status byte to the packet variable */ memcpy(packet, packetDataPointer, (packetLength + 1)); RFQueue_nextEntry(); toggle(); } }
I have stepped all the way into f_open and followed the following path:
f_open goes to find_volume, to disk_initialize, to SDFatFS_diskInitialize, to SD_initialize, to SDSPI_initialize, to SemaphoreP_pend(object->lockSem, SemaphoreP_WAIT_FOREVER) and that's as far is I can go.
It gets stuck and it has to do something with this SemaphoreP_pend in the SDSPI_initialize function in the SDSPI.c file, I just don't know what.
I have no idea why these two code blocks won't combine, it makes NO sense to me. Can someone please help make this work?
Kind regards,
Mirte H