Embedded temperature logger using FAT16 file system

Publisher:YaqiLatest update time:2023-08-22 Source: elecfansKeywords:FAT16 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

  Embedded temperature logger using FAT16 file system

   The 32/16-bit microcontroller LPC2148 with ARM7TDMIS as the core is combined with the SD card to realize the establishment of the FAT16 file system on the SD card. The collected temperature data is stored in the SD card in FAT16 file format, which facilitates users to read and analyze the temperature data. This article describes the working principle of the temperature sensor ADT75.



  The continuous development of flash memory technology has made flash memory cards (such as SD cards, MMC cards, etc.) more and more widely used in the field of embedded storage due to their advantages of small size, large capacity, and high reliability. The FAT16 file system has excellent file management performance and can be recognized by most operating systems. Therefore, combining a flash memory card with the FAT16 file system is an ideal solution for embedded storage and recording systems. Temperature acquisition and control technology is an important part of modern measurement and control systems. Since traditional analog sensing temperature measurement systems have disadvantages such as low measurement accuracy, susceptibility to interference, complex hardware, and cumbersome debugging, the new single-chip digital temperature sensor has the advantages of high measurement accuracy, strong anti-interference ability, easy operation, and low power consumption. Low-level advantages, the scope of application is getting wider and wider. This embedded digital temperature recorder is based on the ARM7 microprocessor LPC2148 and the digital temperature sensor ADT75. It uses a large-capacity SD card as the storage medium and implements the FAT16 file system, which provides data storage for temperature acquisition and recording and embedded systems. An ideal solution.


1 Hardware design

  The hardware circuit of this temperature recorder is simple to implement and mainly consists of two parts: SD card read/write unit circuit and ADT75 temperature measurement unit circuit. As shown in Figure 1, LPC2148 reads/writes the SD card through the SPI bus, and reads/writes the ADT75 through the I2C bus to achieve temperature collection.

Click here to browse pictures in a new window
Figure 1 Temperature collector hardware circuit

1.1 Hardware interface design between SD card and LPC2148

  SD card is a memory card based on NAND Flash. Because of its advantages such as high security, large capacity, small size, low power consumption, and non-volatility, it has been increasingly widely used in embedded systems.

  SD card supports 2 interface modes: SD card mode and SPI mode[1]. The SD card mode uses 4 data lines for parallel transmission, which is fast, but the protocol implementation is complex; although the SPI mode is lacking in speed performance compared with the SD mode, the protocol implementation is simple and easy to operate.

  The SD card has a total of 9 pins, and the definitions of each pin are different in SD mode and SPI mode. In SPI mode, pins 1 to 7 of the SD card are chip select pin CS, data input DI, power ground, power supply VDD, clock signal CLK, power ground, data output DO. Pins 8 and 9 are in SPI mode. Reserved unused. Since the SPI bus communication protocol requires that the SPI bus should remain high when idle, CS, DI, DO, and CLK should be connected to an external pull-up resistor of about 10 kΩ.

1.2 Working principle of ADT75 temperature measurement

  ADT75ARZ is a low-power, high-resolution temperature sensor launched by ADI. It contains a 12-bit A/D converter, has an SMBus/I2C compatible interface, and an over-temperature indication output pin. The rated operating temperature range is -55 ~ +125 ℃, the resolution can reach 0.062 5 ℃, and the power consumption Low, the working voltage is 3~5.5 V[2]. Its typical application circuit is shown in Figure 1.

  The working process of ADT75 is as follows: ADT75 converts the collected temperature into a voltage signal through the internal temperature sensor. This voltage signal is input to the 12-bit A/D converter after passing through the internal ΣΔ regulator. The 12-bit temperature data after A/D conversion is stored in the temperature data register, and the temperature data is compared with the value of the temperature limit register. Compare, if it exceeds the set value, the pin OS outputs a valid level. The effective level of the OS pin output can be set in the configuration register.

  There are 5 registers inside the ADT75: 4 data registers and 1 address pointer register. The four data registers are configuration register, temperature data register, THYST fixed value register, and TOS fixed value register. The configuration register is an 8-bit read/write register that can set the ADT75 to various modes, such as shutdown, over-temperature interrupt, single step, SMBus alarm enable, OS/ALERT pin polarity, etc.; 16-bit temperature data register It is a read-only register, in which the temperature value is stored in two's complement form. When reading, the upper 8 bits are read first, and then the lower 8 bits are read. Both the THYST fixed value register and the TOS fixed value register are 16-bit readable/writable. Registers and 16-bit data are all stored in two's complement form. Their default limit temperatures are +75 ℃ and +80 ℃ respectively (TOS stores the over-temperature limit value, and THYST stores the hysteresis temperature limit value. When the measured temperature ≥ TOS setting When the temperature reaches a certain temperature value, the OS pin outputs a valid level. It does not change the OS pin output level to an inactive level until the temperature drops below THYST.) The address register is an 8-bit register. When reading/writing the internal registers of the ADT75, the address of the register needs to be written into the address register. For example, if you want to read the temperature data value of ADT75, you need to write the address 0x00 of the temperature data register into the address register.

  LPC2148 has two standard I2C interfaces: P0.2 and P0.3 constitute the first I2C interface. When communicating with other I2C devices, a pull-up resistor needs to be connected; the other I2C interface has an internal pull-up resistor, so it does not need to be connected externally. Pull-up resistor.


1.3 32-bit microcontroller LPC2148

  LPC2148 is a 32-bit/16-bit microcontroller with an ARM7TDMIS core that supports real-time simulation launched by Philips. It contains 40 KB of on-chip RAM and 512 KB of on-chip Flash memory, and supports ISP and IAP operations [3]. It has rich interface resources, including 2 32-bit timers, 1 USB 2.0 full-speed device controller, 2 serial UART interfaces supporting 16C550, 2 I2C interfaces supporting high-speed bus, 1 SPI interface and on-chip RTC real-time clock wait. LPC2148 contains PLL phase-locked loop components, which can increase the main frequency to operate at 60 MHz. LPC2148 supports Thumb instructions and can run in Thumb state when the code size is restricted. LPC2148 is packaged in ultra-small LQFP64 and has an operating voltage of 3.3 V. It is suitable for industrial control, medical systems, access control, communication gateways, embedded soft modems and other occasions.

  This recorder mainly uses its SPI bus interface, I2C interface, RTC real-time clock and rich RAM resources and other functional units. The clock source of the LPC2148's RTC real-time clock can be provided by an independent 32.768 kHz crystal oscillator, and the RTC component also has a dedicated power supply pin VBAT, which can be powered by an external battery. This collector uses a 32.768 kHz external crystal oscillator and is powered by a battery, so that the RTC real-time clock can continue to run after the collector is powered off.


2 SD card FAT16 file system analysis

  FAT (File Allocation Table) file management system [4] is a file management system released by Microsoft and supported by MSDOS. During the development of FAT, three versions, FAT12, FAT16, and FAT32, were released. FAT16 means that one partition of the disk can contain at most 2^16 clusters. Since the maximum storage space of each cluster is only 32 KB, the maximum storage capacity of one partition of the disk is 2 GB. Since the capacity of the general SD card does not exceed 2 GB, the SD card is usually only used as a partition.

  SD card supports FAT12 and FAT16 file systems[5]. Table 1 describes the file system structure of the 512 MB SD card in this article.

Table 1 512 MB SD card file system structure
Click here to browse pictures in a new window

  A reserved sector in the SD card. Generally, data should not be written to this sector. If incorrect data is written, the file system structure of the SD card will be destroyed, causing the SD card to be unrecognizable on the PC.

  In the FAT file system, BPB (Bios Parameter Block, partition parameter record table) is a very important parameter table. It indicates a series of important basic parameters of the partition, such as the total number of sectors, the space size of each cluster, the number of sectors occupied by the FAT table, etc. In the SD card, the 12th to 36th bytes of the first sector of the reserved sector (ie, the partition record sector) are BPB. Table 2 gives the content and description of each field of BPB.

Table 2 Contents of each field of BPB of 512 MB SD card
Click here to browse pictures in a new window

  Since the FAT file system adopts the chain storage principle, the starting cluster number, subsequent cluster number, and ending cluster number of each file are recorded in the FAT table. In this article, FAT[i] is used to indicate the content of the field with cluster number i in the FAT table, and each FAT[i] occupies 2 bytes. In the FAT16 file system, since the default values ​​of FAT[0] and FAT[1] are 0xFFFF, the FAT table stores the starting cluster number and ending cluster number of the file starting from FAT[2], so the starting cluster number of the file is 0x0002. In the FAT table, 0x0000 is used to indicate that the storage space corresponding to the cluster number is not occupied by the file, and values ​​from 0x0002 to 0xFFFE are used to indicate the starting cluster number and the cluster number of the next cluster where subsequent content is stored. If a file has a cluster number of When the storage space of i is terminated, 0xFFFF should be written in FAT[i]. After the second FAT table is the DIR area. Each FAT16 file corresponds to a directory, and the size of each directory is 32 bytes. Since DIR occupies 32 sectors, there can be a total of 512 registration entries in DIR, which can also be obtained by reading the field BPB_RootEntCnt in the BPB table.

[1] [2]
Keywords:FAT16 Reference address:Embedded temperature logger using FAT16 file system

Previous article:Design strategy of supermarket cash register system based on LPC2138
Next article:Design of 6-channel data acquisition system based on LPC2210 and AD7656 chips

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号