3.15.1 SD Card, USB Data Logger Application on SAM L22 Xplained Pro Evaluation Kit

Download

Description

This application shows an example of using the MPLAB Harmony v3 File System to store the sensor data (light intensity values) and temperature values into a SD card using the SDSPI and a SPI driver. The SD card is enumerated as a MSD(Mass Storage Device) device on the PC(USB Host) enabling logged data viewing.

The SDSPI driver uses an instance of the SPI driver to communicate to the SD card over the SPI bus. The application creates a directory named Dir1 in the root directory and creates a new file named DATA_LOG.txt. The application writes the light sensor and temperature values into this newly created file every 1 second and display it on the SLCD. If the directory and file already exists the values are logged into the existing file itself. The logged light intensity and temperature values along with time stamp are read via USB with the SD card enumerated as an MSD( Mass Storage Device). The application parallel continues to log the data with the SD card enumerated as an MSD.

Modules/Technology Used

  • Peripheral Modules:
    • Timer
    • DMAC
    • ADC
      • PORTS
      • EVENT SYSTEM
      • SERCOM (USART)
      • SERCOM (SPI)
      • SERCOM (I2C)
      • RTC
  • Drivers:
    • SDSPI Driver
      • USB Full Speed Driver
      • SPI Driver
      • SLCD
  • Libraries:
    • USB MSD Library
    • File System Library
    • Debug System service Library
    • STDIO Library

Hardware Used

Software/Tools Used

This project has been verified to work with the following versions of software tools:

Refer Project Manifest present in harmony-manifest-success.yml under the project folder firmware/src/config/sam_l22_xpro.

  • Refer the Release Notes to know the MPLAB X IDE and MCC Plugin version.

Because Microchip regularly updates tools, occasionally issue(s) could be discovered while using the newer versions of the tools. If the project does not seem to work and version incompatibility is suspected. It is recommended to double-check and use the same versions that the project was tested with. To download original version of MPLAB Harmony v3 packages, refer to document How to Use the MPLAB Harmony v3 Project Manifest Feature (DS90003305).

Setup

  • Verify that the I/O1 Xplained Pro Extension Kit is connected to Extension Header 1 (EXT1) on the SAM L22 Xplained Pro Evaluation Kit.
  • Insert microSD(upto 32GB) card on to the I/O1 Xplained Pro Extension Kit.
  • Insert the Touch SLCD1 Xplained pro into EXT 5.
  • The SAM L22 Xplained Pro Evaluation Kit allows using the Embedded Debugger (EDBG) for debugging. Connect the Type-A male to micro-B USB cable to micro-B DEBUG USB port to power and debug the SAM L22 Xplained Pro Evaluation Kit.
  • SAM L22 Xplained pro will be in battery backup mode initially. The device is not woken up when switched from battery backup power to Main Power. Press the RESET push button on the SAM L22 Xplained pro to wake up the device.
  • Place the jumper between CAP and PB03 in the VBAT select jumper.
  • The system time can be set via the Terminal.Open a terminal application on the host PC for the virtual COM port of the connected SAML22-Xpro Development board, with 115200-8-None-1 settings. If using Tera Term Choose Local echo option under Setup->Terminal to see the input characters
  • Press any character to enter the time to be set.Set the Date in DD:MM:YY and Time in HH:MM:YY(24Hrs format).
  • "Time Set!" message is displayed after date and time is set sucessfully.

Programming Hex File

The pre-built hex file can be programmed by following the below steps

Steps to program the hex file
  • Open MPLAB X IDE
  • Close all existing projects in IDE, if any project is opened.
  • Go to File -> Import -> Hex/ELF File.
  • In the Import Image File window,
    1. Create Prebuilt Project,
      • Click the Browse button to select the prebuilt hex file.
      • Select Device as ATSAML22N18A.
      • Ensure the proper tool is selected under Hardware Tool and click on Next button.
    2. Select Project Name and Folder,
      • Select appropriate project name and folder and click on Finish button
  • In MPLAB X IDE, click on Make and Program Device button to program the device.
  • Follow the steps in Running the Demo section below.

Programming/Debugging Application Project

  • Open the project (saml22_sdcard_usb_slcd__datalogger/firmware/sam_l22_xpro.X) in MPLAB X IDE
  • Ensure SAM L22 Xplained Pro is selected as hardware tool to program/debug the application
  • Build the code and program the device by clicking on the Make and Program button in MPLAB X IDE tool bar
  • Follow the steps in Running the Demo section below

Running the Demo

  1. When Powered up, the Application shows the light intensity (ALS in Lux) and temperature (TEMP in °C) on the SLCD.
  2. Light intensity ADC count, Light intensity and temperature values are stored every 1 second along with time stamp. This is indicated by toggling of LED0.
  3. To read the logged light intensity values, connect the Target USB port on the board to the computer using a micro USB cable.
  4. Press SW0.This stops the logging of data to the text file and LED0 is turned off. Access the DATA_LOG.txt via enumerated USB drive inside the Dir1 folder.(see below image)
  5. The sample log file looks as below.
  6. Always close the DATA_LOG.txt file and eject the USB drive before removing it.

  7. To resume the datalogging press the SW0 on the SAM L22 Xpro kit.

    Attention: Always read the logged data via USB after pressing SW0. Ensure that data is not logged (LED0 toggling stopped) at the time of reading so as to prevent file corruption.

Comments