Lab 2: Log Data to SD Card

Step 8: Build and Run the Application

1

Clean and build your application by clicking on the Main_Rebuild_Project.png Clean and Build Project button.

2

Program your device with the built application binary by clicking on the Main_Program_Target_Project.png Make and Program Device button.

3

Now, open the serial terminal application on your computer and connect to the serial port as shown in Figure 1 (Tera Term is used here for reference).

lab1_step11_console_setup.png
Figure 1: Open USB Serial Port using Tera Term

Note: It is not required to adjust the Baud rate as you are using a USB connection.

4

Remove the SD card from the IO1 Xplained Pro board.

5

Press the switch SW1 (the upper one) to start reading the temperature sensor value. The application informs the SD card is not inserted.

lab2_step8_05_console_nosdcard.png
Figure 2: Verify the output when SD card is not plugged in

6

Insert the SD card into the microSD slot of the IO1 Xplained Pro board and observe the data that is logged into the SD card.

lab2_step8_06_console_sdcard.png
Figure 3: Verify the output when SD card is plugged in

7

Press the switch SW1 again. That will stop the log.

8

Remove the SD card from the IO1 Xplained Pro board and insert the media into a Host machine.
Observe and verify the content of the media drive. It should contain the file dir1/log.txt.

lab2_step8_08_explorer.png
Figure 4: Verify the content of the SD card

9

Open the file dir1/log.txt in any text editor and observe the temperature sensor values recorded every 10 seconds as expected.

lab2_step8_09_log.png
Figure 5: Observe the log.txt

10

Safely remove the SD card media from the Host machine and insert the SD card into the microSD slot of the IO1 Xplained Pro board. Reset the PIC32 WFI32E Curiosity Board using the MLCR button. Last, press the switch SW1 to start the log.

Note: You can find the solution of the Lab 2 in the folder: <your unzipped folder path>\getting_started_pic32_wfi32e\Lab2\solution.

 Results

You should be able to verify the temperature logs were successfully recorded into the SD card.

 Analysis

In this lab, you have successfully added new functionality to your project. The new application writes the temperature sensor values along with current system time to a file in an SD card using the File System interface.

  • The SDSPI Driver with SPI2 Peripheral Library was used to perform operations on the SD card.
  • The RTC Peripheral Library was used to get the current system time.
  • The File System service was used to write the current system time along with temperature sensor values received from the Sensor Task to a file created on an SD card using the SDSPI Driver.
  • Some BSP features have been used to provide interaction with the user.

In the next lab, you will move the current application into an RTOS environment.

 Conclusions

In this lab, you have successfully developed a full-fledged MPLAB Harmony Application. This gives you a fair idea of how MPLAB Harmony helps application development. If you need to add the SD card and File System support to any of your existing applications, this lab can be used as a reference. This can also be a starting point for your IoT applications.



Next Step >

© 2022 Microchip Technology, Inc.
Notice: ARM and Cortex are the registered trademarks of ARM Limited in the EU and other countries.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.