Design of component modules and implementation methods of MAX1303 driver based on ARM-Linux

Publisher:Serene123Latest update time:2022-12-07 Source: 21icKeywords:ARM-Linux  MAX1303  driver Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

In a data acquisition system, physical quantities in the natural world are usually converted into electricity through sensors. Electricity is an analog quantity and must undergo analog/digital conversion before it can be read by the system's processor. Many current microprocessors have on-chip ADs, but most of these ADs are 8-bit, 10-bit, or 12-bit, and sometimes it is difficult to meet accuracy requirements. Therefore, it is necessary to use the interface resources of the processor to expand the AD chip with higher precision. However, the higher the accuracy, the more expensive it is. Therefore, when selecting AD chips, these two aspects must be fully considered. After weighing the sampling accuracy and price, this system decided to choose a 16-bit analog/digital converter. Since the designed data acquisition system is placed in a harsh outdoor environment, all devices must meet industrial-grade standards, so MAX1303 from MAXIM Company was finally selected. The processor uses NXP's ARM9 microprocessor LPC3250. On this basis, the hardware connection and the device driver under the Linux 2.6.29 kernel were designed, and the driver was tested through the written application program.


1 Chip introduction

1.1 Introduction to LPC3250

LPC3250 is a 32-bit industrial-grade processor launched by NXP that uses a RISC structure and is based on the ARM926EJ-S core. It can work in the range of -40 to +85°C. Its maximum operating frequency can reach 266 MHz, has a complete memory management unit (MMU), and can be embedded in operating systems such as Linux/Wince that require MMU support; up to 256 kB internal SRAM can be used for data and code storage; 32 kB data high-speed cache and 32 kB instruction cache; vector floating-point coprocessor with hardware floating-point computing capabilities. In addition, the on-chip SD/MMC card host controller and Ethernet controller make it easy for the system to implement file storage and Ethernet functions, which is very useful for data acquisition systems.


1.2 Introduction to AD chip MAX1303

MAX1303 is an industrial-grade, low-power consumption, multi-range, 16-bit precision analog-to-digital conversion chip launched by MAXIM. It is powered by a +5 V single power supply and has a maximum sampling rate of 115kbps. An on-chip reference of +4.096 V or an external voltage reference between 3.800 and 4.136 V can be used. Available in 20-pin TSOP package. Its pins are shown in Figure 1.




As can be seen from the pin diagram, there are a variety of power pins outside the chip, and these pins correspond to independent functional modules inside the chip. Using an independent power supply for the chip can keep the working environment as low-noise as possible. Pins 16 and 17 are respectively connected to AVDD and the reference voltage when using an external voltage reference. When using the chip's internal reference, they can be bypassed to AGND1 through 0.01μF and 1μF capacitors respectively. Other pin functions are shown in Table 1.


CH0-CH4 supports 4 single-ended inputs or 2 differential inputs. SSTRB can indicate the conversion status in certain operating modes of the AD converter. The other four digital interfaces can be connected to systems from 2.7 V to 5.25 V through SPI/OSPI/MICROWIRE compatible serial interfaces.


MAX1303 supports 7 single-ended input ranges or 3 differential input ranges, and has 7 operating modes. These can be configured by entering control words.


2. System hardware design
has been mentioned. The analog/digital converter MAX1303 can be controlled through an SPI/QSPI/MICROWIRE compatible serial interface. Since SPI is relatively common and the protocol is simple, this system uses the SPI protocol to control the AD chip. However, although LPC3250 has a built-in SPI controller, this system chooses to use the GPI/O port of LPC3250 to simulate the SPI interface to control the MAX1303. The reasons are analyzed below.


As mentioned, MAX1303 has 7 working modes, of which 3 are used for data acquisition. These three working modes are: external clock mode; external acquisition mode; internal clock mode. Each of these 3 collection modes has its own advantages and disadvantages. The external clock mode has the highest throughput rate, and at the same time, it brings the highest burden to the processor; the internal clock mode has the second highest throughput rate, which can appropriately reduce the burden on the processor; the external acquisition mode has the lowest throughput rate, but it can maximize the Reduce processor load. Due to the powerful performance of LPC3250, the system uses an external clock mode with high throughput rate when collecting data. However, when using the external clock mode, unlike using the internal clock mode and external acquisition mode, after the processor writes the control word and conversion start word to the MAX1303, it only needs to wait for the conversion end signal output by the SSTRB pin of the MAX1303, and then it can Read the conversion results. Using the external clock mode requires precise control of the number of clocks, which requires the driver to frequently modify the SPI-related controller and determine the number of clocks through queries. It would be much simpler to use the GPI/O port of LPC3250 to simulate the SPI protocol to control the AD chip. By controlling the GPO port to continuously flip the output level, a clock signal can be generated, and the number of clocks can be controlled at will. For sending data, you only need to simply output each bit of the data byte to the AD chip through the GPI port according to the clock change. Reading data is a reverse process to sending data, but similar.


Therefore, it is very simple to use the GPI/O port to simulate the SPI bus to control the MAX1303. This system has two analog signals that need to be collected, using single-ended input, and the other two input terminals of MAX1303 are grounded. The hardware connection between LPC3250 and MAX1303 is shown in Figure 2.


3 Device driver design under Linux
The device driver is the bridge between the application and the hardware. It shields the hardware details for the application and encapsulates the hardware into a file. When an application needs to operate hardware, it only needs to operate the device file corresponding to the hardware. There are many ways to classify devices in Linux. A common classification is to divide devices into three types: character devices, block devices, and network devices. These three types of devices correspond to three types of device files. Different devices have different development modes and interfaces with the kernel. MAX1303 is a character device. This article will analyze the character device driver design method of MAX 1303 under the Linux 2.6.29 kernel.


Device drivers are different from applications. The application starts execution from the main function, while the driver starts execution from the function specified by the module_init macro when it is installed. The function specified by the module_init macro is called the module loading function, which can be regarded as the entry point of the driver program. It usually completes address mapping, registers with the kernel and initializes the cdev structure, creates device files, etc. The program flow chart of the module loading function is shown in Figure 3.


Corresponding to the module loading function, there is a module unloading function. This function is specified by the module_exit macro and is executed when the driver module is unloaded. Its main tasks include: destroying device files; unregistering the cdev structure corresponding to the device; releasing memory; and unregistering the device number.


Struct cdev is used to represent devices inside the kernel. This is a very important data structure. It has an internal member structure structfile_operations, which is used to connect the device number and driver operation. This data structure contains a set of function pointers. The implementation of this set of functions is the focus and difficulty of designing a driver program. There are many functions in this group, but according to project requirements, this system only implements four functions: open, write, read, and release.


The open field in the structure struct file_operations corresponds to the open function in the system call. In the application program, when the device file corresponding to MAX1303 is opened through the open function, the kernel will jump to this function pointer. The implementation of this function pointer mainly completes the initialization work. This includes the initial configuration of the MAX1303 and the register settings related to the LPC3250 driver. The initialization of MAX1303 includes working mode selection, measurement range selection, single-ended/differential input selection, and initialization channel selection. For these four items, this system all uses the default settings: external clock mode; measurement range from -Vref to +Vref; single-ended input; initialization input channel 0. Therefore, there is no need to configure MAX1303 in open. The register configuration of the LPC3250 is also relatively simple. The configurations that need to be completed are: pull the chip select signal high; pull the clock signal low; pull the processor output low.


The Write field needs to receive the data passed by the application from user space to the kernel, and then send this data to the MAX1303 through the GPO_17 port. These data are mainly used to modify the configuration of the MAX1303, such as channel selection. When writing data to MAX1303, you need to pay attention to the two time parameters Tcss and Tcspw in the electrical characteristics of MAX1303. Tcss corresponds to the necessary time interval from when the chip select signal of the chip is pulled low to before the arrival of the first clock. Tcspw corresponds to the time interval between any two when writing the analog input configuration byte, mode control byte, and conversion start byte. Both time parameters must be greater than 40 ns, with no upper limit. In this system, the conversion start byte is written in Read, only channel switching is done in Write, and other configurations use the default.

[1] [2]
Keywords:ARM-Linux  MAX1303  driver Reference address:Design of component modules and implementation methods of MAX1303 driver based on ARM-Linux

Previous article:Detailed explanation of ARM processing registers and user mode
Next article:Diagnosis and treatment of MCU/ARM crash or runaway

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号