This project is extension to the previous tutorial which explains how to interface the SD card with an LPC1768. Here we will program to log the temperature reading from a LM35 sensor to a text file periodically. The ARM Cortex M3 runs on 3.3V power supply with a built in crystal frequency of 16 MHz. A 32GB SDSC card from Transcend is used in this particular project, but the code will work with most of the SD cards. The SD card is formatted with FAT32. The ultimate aim of this project is to create a file in the FAT32 file system of the SD card. For setting up the Environment for the development of ARM cortex M3 is well discussed in this article.
The LPC 1768 is ARM Cortex- M3 based Microcontrollers for embedded application features in low power consumption and a high level of integration. The ARM Cortex M3 is designed in a such way to enhance debug features and a higher level of system integration. It clocks at a CPU frequency of 100 MHz, and incorporates a 3-stage pipeline and uses a Harvard architecture with separate local instruction and data buses for third bus peripherals. The ARM Cortex- M3 CPU have an internal pre-fetch unit to support speculative branching. The peripheral components include 512KB of flash memory, 64kb of data memory, Ethernet MAC, USB OTG, 4 UART’s, 8-channel general purpose DMA controller, 2 SSP Controllers, 10-bit DAC, Quadrature encoder interface, SPI interface, 3 I2C bus interface, 2 input plus 2 outputs I2S bus interface, 4 general purpose timers, ultra-low power Real-Time Clock (RTC) with separate battery supply, and up to 70 general purpose I/O pins, 6-output general purpose PWM. The LPC1768/66/65/64 are pin-compatible with the 100-pin LPC236x ARM7-based Microcontroller series.
Fig. 1: Data logging In SD Card Using LPC1768 Prototype
A temperature data logger, is a portable measurement device that is able to recording temperature over a defined period of time automatically. The data can be retrieved and viewed after it has been recorded. In this device the temperature will record every 2 seconds in text file.
In this project we are using LM35 which is a three terminal linear temperature sensor from National semiconductors. It can measure temperature from-55c to +150C. The voltage output of the LM35 increases 10mV per degree Celsius rise in temperature. LM35 can be operated from a 5V supply and the stand by current is less than 60uA. For ADC interfacing with LPC1768 refer this article.
(For more detail in SD card interface refer SD Card interfacing with LPC1768).
To create a time stamp to be stored along with our measurements we need to access the Real Time Clock (RTC) block of the LPC1768. RTC Programming in LPC1768 is explained in this article.
Insert an SD card into the card holder and upload the sketch to your LPC1768. If the sketch is able to write to the SD card OK, it will create a text file called ‘Temperature.txt. The file is just a standard text file that can be read by any text editor. Once the file has been opened the sketch will start saving the sensor reading to it. If the file already exists it will just append the new reading onto the end. Here is what the contents of the Temperature.txt file should look like:
Fig. 2: Temperature.txt File Saving Sensor Reading In LPC1768
Temperature sensor LM35 is interfaced to the LPC1768 through the analog input pin 1.31. SD card is connected as per the SPI connections shown in the diagram. LCD is also interfaced to show the current temperature.
To log the temperature we will be repeating the following steps in software once two second:
Read the current date and time.
Read the current temperature from the LM35 connected to the analogue pin 1.31 and convert it into celcius.
Open a file on the SD card.
Save the measurement together with the date and time to the end of the file.
Close the file.
Create a project using Keil uvision4 for LPC1768 Microcontroller:
In this section, we will start creating a project in Keil MDK we have already installed Keil µVision and Co-MDK Plug-in + CoLinkEx Drivers required for the CoLinkEx programming adapter. You can start by downloading the project files and kick start your practical experiment.
The below function call is to get the current time values from the RTC
The below function calls are used to open the file and to write the values to it.
result = f_open(&file, “Temperature.txt”, FA_WRITE);//Open the file again.
result = f_lseek(&file, file.fsize);//Go to the end of the file
result = f_write(&file, buf,strlen(buf), &s1);//file type. result = f_close(&file);// Close the file.
Project Source Code
###The codes are linked in Description ###