With the continuous development of flash memory technology, flash memory cards (such as SD cards, MMC cards, etc.) have been increasingly widely used in the field of embedded storage due to their 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 flash memory cards 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. Due to the disadvantages of low measurement accuracy, susceptibility to interference, complex hardware, and cumbersome debugging in traditional analog sensor temperature measurement systems, the new single-chip digital temperature sensor has the advantages of high measurement accuracy, strong anti-interference ability, convenient operation, and low power consumption, and its application range is becoming more and more extensive. 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, providing an ideal solution for temperature acquisition and recording and data storage in embedded systems.
1 Hardware Design
The hardware circuit of this temperature recorder is simple to implement, and mainly includes two parts: SD card read/write unit circuit and ADT75 temperature measurement unit circuit. As shown in Figure 1, LPC2148 reads/writes SD card through SPI bus and reads/writes ADT75 through I2C bus to realize temperature collection.
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. Due to its advantages of high security, large capacity, small size, low power consumption and non-volatility, it has been widely used in embedded systems.
SD cards support two interface modes: SD card mode and SPI mode[1]. The SD card mode uses four data lines for parallel transmission, which is fast, but the protocol implementation is complex; although the speed performance of the SPI mode is inferior to that of the SD mode, the protocol implementation is simple and easy to operate.
SD card has 9 pins in total. The definition of each pin is different in SD mode and SPI mode. In SPI mode, SD card pins 1 to 7 are chip select pin CS, data input DI, power ground, power supply VDD, clock signal CLK, power ground, data output DO, and pins 8 and 9 are reserved in SPI mode. Since the SPI bus communication protocol requires that the SPI bus should maintain a high level when idle, CS, DI, DO, and CLK should be connected to a pull-up resistor of about 10 kΩ.
1.2 ADT75 temperature measurement working principle
ADT75ARZ is a low-power, high-resolution temperature sensor launched by Analog Devices. It contains a 12-bit A/D converter, an SMBus/I2C compatible interface, an over-temperature indication output pin, a rated operating temperature range of -55 to +125°C, a resolution of up to 0.0625°C, low power consumption, and an operating voltage of 3 to 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. If it exceeds the set value, the pin OS outputs a valid level. The valid level of the OS pin output can be set in the configuration register.
There are 5 registers inside ADT75: 4 data registers and 1 address pointer register. The 4 data registers are configuration register, temperature data register, THYST constant register, and TOS constant register. The configuration register is an 8-bit read/write register that can set ADT75 to various modes, such as shutdown, over-temperature interrupt, single-step, SMBus alarm enable, OS/ALERT pin polarity, etc. The 16-bit temperature data register is a read-only register, in which the temperature value is stored in binary complement form. When reading, read the high 8 bits first and then the low 8 bits; THYST constant register and TOS constant register are both 16-bit read/write registers, and the 16-bit data are stored in binary complement form. Their default limit temperatures are +75 ℃ and +80 ℃ respectively (TOS stores the over-temperature limit value, THYST stores the hysteresis temperature limit value. When the measured temperature is ≥ the temperature value set by TOS, the OS pin outputs a valid level, and the OS pin output level will not become an invalid level until the temperature drops below THYST). The address register is an 8-bit register. When reading/writing the internal registers of 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, which needs to be connected to a pull-up resistor when communicating with other I2C devices; the other I2C interface has an internal pull-up resistor, so it does not need an external pull-up resistor.
1.3 32-bit microcontroller LPC2148
LPC2148 is a 32-bit/16-bit microcontroller with ARM7TDMIS core that supports real-time simulation and is 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. LPC2148 contains a PLL phase-locked loop component that can increase the main frequency to 60 MHz. LPC2148 supports Thumb instructions and can run in Thumb state when the code size is constrained. LPC2148 uses an ultra-small LQFP64 package and operates at a 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 utilizes its SPI bus interface, I2C interface, RTC real-time clock and rich RAM resources and other functional units. The clock source of 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 pin VBAT, which can be powered by an external battery. This collector uses a 32.768 kHz external crystal oscillator and uses a battery to power it, so that the RTC real-time clock can continue to run after the collector loses power. [page]
2 Analysis of SD card FAT16 file system
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. Among them, FAT16 means that a partition of the disk contains at most 2 to the 16th power clusters. Since the maximum storage space of each cluster is only 32 KB, the maximum storage capacity of a partition of the disk is 2 GB. Since the capacity of a general SD card does not exceed 2 GB, an SD card is usually used as only one partition.
SD cards support FAT12 and FAT16 file systems [5]. Table 1 describes the file system structure of the 512 MB SD card in this paper.
Table 1 512 MB SD card file system structure
The reserved sectors in the SD card should not be used to write data. 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) 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 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 (i.e. the partition record sector) are BPB. Table 2 gives the content and description of each field of BPB.
Table 2 512 MB SD card BPB field contents
Since the FAT file system adopts the chain storage principle, the FAT table records the starting cluster number, subsequent cluster number, and ending cluster number of each file. 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 starts to store the starting cluster number and ending cluster number of the file 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 a file, and the values of 0x0002 to 0xFFFE are used to indicate the starting cluster number and the cluster number of the next cluster storing the subsequent content. If a file ends in the storage space with cluster number i, 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.
If you create a new FAT file on an SD card, you should first search for unused cluster numbers in the FAT table to determine the file's starting cluster number, and determine the file's ending cluster number in the FAT table based on the file's size, and write the starting and ending cluster numbers in the corresponding FAT[i]. Then you should apply for a registration item in the DIR area, which actually creates a 32-byte file directory in the DIR area. Finally, write the file data to the sector in the data area that corresponds to the file.
3 Software Design
3.1 Low-level software interface design between SD card and LPC2148
After power-on reset, the SD card automatically enters SD mode. Therefore, the underlying software interface design between the SD card and LPC2148 in this design mainly refers to how to make the SD card enter SPI mode and implement read/write operations on the memory unit of the SD card in SPI mode.
Figure 2 SD card initialization process
Figure 2 describes the initialization process of the SD card after power-on reset. After the SD card is powered on and reset, the SD card controller should send at least 74 clock cycles to the SD card before sending any command to the SD card to wait for the SD card to complete the power-on reset process, and the controller should set the chip select signal line high at this time. After the power-on reset is completed, the chip select signal line CS is set low, that is, the SD card is selected, and the software reset command (CMD0) is sent. The SD card can enter the SPI mode and is in an idle state. After that, if you want to read and write operations on the SD card, the host-side LPC2148 should continue to send activation commands (CMD1) until it receives the correct response data 0x00 from the SD card, indicating that the SD card has exited the idle state and can read/write the SD card registers and realize data transmission operations. [page]
After completing the above operations, the length of the data to be written or read from the SD card should be set at one time. This can be achieved by sending the Set Block Length Command (CMD16). In this design, the length of the data block to be read/written at one time is set to 512 bytes. When you want to read or write the contents of a data block on the SD card, you can do so by sending the Read Data Command (CMD17) or the Write Data Block Command (CMD24).
3.2 Reading temperature value
When LPC2148 wants to read the contents of each register of ADT75, it needs to go through the steps of writing first and then reading. When writing ADT75, the address pointer register needs to point out the register address to be read. Figure 3 describes the timing of reading ADT75 temperature data.
Figure 3 Timing of reading ADT75 temperature data
Since the address value of the temperature data register is 0x0, the content written to the address register is 0. After ADT75 gives a response signal, LPC2148 gives a read signal, that is, the data line SDA is set to a high level in the 9th clock cycle, indicating that data is read. After that, LPC2148 reads the upper 8 bits of the temperature data, and then reads the lower 8 bits of the data, and LPC2148 should give a low-level response signal after each byte of data is read. When the temperature data is completed, LPC2148 transmits the end sequence and ends the data read operation. In the 12-bit temperature data format, the lower 4 bits of the read 16-bit temperature data are 0. After taking its complement and dividing it by 16 (floating-point division), it is the measured temperature.
3.3 Main software process
In the design of this temperature recorder, the second interrupt, minute interrupt, and day interrupt functions provided by the LPC2148 on-chip RTC real-time clock are used to realize the regular collection, storage, and file creation of ADT75 temperature data.
When the second interrupt of RTC occurs, LPC2148 reads the temperature data of ADT75 at a rate of 400 kHz through I2C bus and stores the temperature data in the internal RAM of LPC2148. In order to facilitate users to read the stored temperature data on PC using card reader, the data stored in RAM per second is 22 bytes, and all of them are ASCII characters. The data format is listed in Table 3.
Table 3 Storage data format
The first 4 bytes are the real-time temperature acquisition time, and the stored time content is hours, minutes, and seconds. The first temperature data is expressed in hexadecimal; the second 8-byte temperature data is the actual temperature value after conversion, and each record ends with a carriage return (ASCII code is 0x0D) and a line feed (ASCII code is 0x0A). For example, the temperature data collected at 12:00:59 is 0x1910, and the data stored in RAM is "120059 1910+025.625
When the RTC is interrupted, LPC2148 will store the data temporarily stored in RAM into the SD card. This can reduce the number of write operations to the SD card and extend the service life of the SD card.
When the RTC is interrupted, LPC2148 will create a new notepad file (.txt file) on the SD card. The file name is the date of the day. For example, the file name created on October 6, 2007 is "071006.txt". Since the data written to the SD card every minute is 22×60=1320 bytes, the maximum capacity of each file is 1856 KB. For a 512 MB SD card, about 1 year of temperature data can be saved.
Figure 4 describes the main software flow of this design. Before realizing the collection and storage of temperature data, the SPI bus control register, I2C control register and RTC real-time clock register of LPC2148 need to be correctly configured.
Conclusion
ADT75 is a complete digital temperature sensor with an I2C bus interface; LPC2148 is powerful and has rich peripheral interface resources. By combining LPC2148 and ADT75 through the I2C bus, distributed multi-point temperature acquisition can be achieved. The implementation of the SD card FAT16 file system makes it convenient for users to read and analyze the collected temperature data. This article provides a practical solution for the storage of embedded system data, distributed collection and recording of temperature data.
Figure 4 Main software process
References
[1] 2000 SD Group. SD Memory Card Specifications Physical Layer Specification. Part 1. Version 1.0, March 2000.
[2] Analog Devices. ±1°C Accurate, 12Bit Digital, Temperature Sensor. Rev. 0.
2005. [3] Zhou Ligong, Zhang Hua. A Simple Introduction to ARM7 - LPC213x/LPC214x (Volume 2) [M]. Beijing: Beijing University of Aeronautics and Astronautics Press, 2006.
[4] Microsoft Corporation. FAT: General Overview of OnDisk Format. Version 1.02. May 5, 1999.
[5] 2000 SD Group. SD Memory Card Specifications Physical Layer Specification. Part 2. Version 1.0. Februay 2000.
Previous article:Transplantation of embedded file system YAFFS based on ARM
Next article:Design of embedded system based on PXA270
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Which environment setup tutorial should I watch? -- ESP series development environment setup video navigation directory
- Problems with opening KEIL in WIN10
- MSP430 MCU Development Record (25)
- BK3432 BK3432 BLE Bluetooth Chip DataSheet & Hardware Layout Guide
- Test the SCI (UART) communication of 28379D
- msp430fr2311 MCU ADC serial channel sampling
- [Flower carving hands-on] Interesting and fun music visualization series projects (30)--P6 LED unit board
- (There are three lights in the room, how to distinguish them) How to solve this interview question? ?
- EEWORLD University Hall----Live Replay: Littelfuse Silicon Carbide (SiC) MOSFET and Schottky Diode Product Introduction and Related Applications
- Communication between STM32 and AD5761R