Step 6: Modify the Temperature Sensor and SDCARD Application
The application is already developed and is available in the following files.
- app_sdcard.c
- app_sdcard.h
- app_sensor.c
- app_sensor.h
They are available under
<your unzipped folder path>\getting_started_pic32_wfi32e\Lab3\dev_files.
The application file contains the application logic. It also contains placeholders that you will populate with the necessary code.
1
Go to the <your unzipped folder path>\getting_started_pic32_wfi32e\Lab3\dev_files folder and copy the following pre-developed files:
- app_sdcard.c
- app_sdcard.h
- app_sensor.c
- app_sensor.h
Paste and replace (overwrite) your project files in <your harmony 3 project folder path>\PIC32_WFI32E\firmware\src with the copied files.
To simplify the development of Lab 3, the files app_sensor.c and app_sdcard.c have already been modified. The usage of the functions SYS_DEBUG_PRINT() and SYS_DEBUG_MESSAGE() has been replaced by the function APP_PRINT_STRING().
Tip: Search for the string "Step #" in the target file to locate the position where you are supposed to write the code.
2
Open app_sensor.c in MPLAB X IDE.
- Verify that all calls to SYS_DEBUG_PRINT() and SYS_DEBUG_MESSAGE() have been replaced by the function APP_PRINT_STRING().
3
Open app_sdcard.c.
- Verify that all calls to SYS_DEBUG_PRINT() and SYS_DEBUG_MESSAGE() have been replaced by the function APP_PRINT_STRING().
- Follow the steps below.
1
Search for "Step #1":
- Create a queue using the FreeRTOS function xQueueCreate(uxQueueLength, uxItemSize), capable of containing one float value.
- uxQueueLength is the size of the queue. Use the pre-defined macro APP_SDCARD_QUEUE_SIZE (for this queue, the size is one).
- uxItemSize is the item size in the queue. Use the pre-defined macro APP_SDCARD_QUEUE_ITEM_SIZE (for this queue, it is the size of a float).
- This function returns the reference of the queue. Use SDcardQueueHandle to store the handler.
2
Scroll-up and Search for "Step #2":
- Modify the function APP_SDCARD_Notify() to write the temperature value (float) into the queue.
- Use the FreeRTOS function xQueueOverwrite(xQueue, pvItemToQueue).
- xQueue is the handle of the current queue. Use SDcardQueueHandle.
- pvItemToQueue is the item to add into the queue. Use &temperature.
- The function returns pdTRUE if it succeeds.
3
Search for "#Step 3" and observe the code already implemented in the state APP_SDCARD_STATE_IDLE.
- The FreeRTOS function uxQueueMessagesWaiting() is used to monitor the number of items loaded into the queue.
- The FreeRTOS function xQueueReceive() will read the data placed into the queue.