Share this

Implementation of the AD7888 and S3C2410 SPI interface and embedded driver under Linux

2026-04-06 06:22:28 · · #1
Serial Peripheral Interface (SPI) bus technology is a synchronous serial interface introduced by Motorola. It allows the CPU to communicate serially with peripheral interface devices such as TTL shift registers, A/D or D/A converters, real-time clocks (RTOs), memory, and LCD and LED display drivers. The SPI bus requires only 3-4 data and control lines to expand various I/O devices with SPI interfaces. Its hardware is powerful, and its software implementation is quite simple. Serial A/D converters are characterized by simple circuitry and reliable operation, while ARM chips are designed for handheld devices and integrated systems in common embedded applications. Combining these two practical chips with SPI bus technology is very effective for data acquisition. 1. AD7888 Function and Use: The AD7888 is a high-speed, low-power 12-bit A/D converter from Analog Devices, Inc. It operates from a single 2.7–5.25 V power supply and has a maximum throughput of 125 kSPS. The AD7888's input sample-and-hold circuitry acquires a signal within 500 ns, using a single-ended sampling mode and containing eight single-ended analog inputs with analog input voltages ranging from 0 to VREF. The AD7888 has an on-chip reference voltage of 2.5 V and can also use an external reference voltage ranging from 1.2 V to VDD. The CMOS manufacturing process ensures low power consumption, 2 mW during normal operation and 3uW in power-down mode. Multiple power management modes are selectable (including automatic power-down mode after data conversion), and it is compatible with various serial interfaces (SPI/QSPI/MICOWIRE/DSP). The AD7888 can be widely used in battery-powered systems (personal digital assistants, medical instruments, mobile communications), instrument control systems, and high-speed modulators/demodulators. This device is available in 16-pin SOIC and TSSOP packages; the outline and pin definitions are shown in Figure 1 and Table 1. [align=center][IMG=AD7888 Pin Diagram]/uploadpic/THESIS/2007/12/2007121410585775264W.jpg[/IMG] Figure 1: AD7888 Pin Diagram[/align] The AD7888's control register is an 8-bit write-only register. Data is loaded from the DIN pin on the rising edge of SCLK, simultaneously acquiring the result of the external analog-to-digital conversion. Each data transfer requires 16 consecutive clock signals to prepare. Only the information provided on the rising edges of the first 8 clock pulses after the chip select signal falls is loaded into the control register. Figure 2 shows a detailed serial interface timing diagram. The serial clock provides the conversion timing and controls the input and output of AD7888 conversion information. CS initializes data transmission and conversion processing. Input signal sampling begins 1.5 clock cycles after its falling edge, denoted as tACQ (acquisition time). The entire conversion process requires another 14.5 clock cycles to complete, denoted as tCONVERT (conversion time). The entire conversion process of acquiring data from the AD7888 requires 16 clock cycles. After the rising edge of CS, the bus returns to a high-impedance state. If CS remains low, a new round of conversion is prepared. The selection of the input channel for sampling is written to the control register in advance, so the user must write it in advance for the channel conversion. That is, when performing the current conversion, the user must write the channel address in advance for use in the next conversion. [align=center] Figure 2 Serial Interface Timing Diagram[/align] 2 Main Functions of S3C2410 The S3C2410 is a 16/32-bit microprocessor with a RISC architecture launched by Samsung. It is based on the ARM920T core, adopts a five-stage pipeline and Harvard architecture, and can reach a maximum frequency of 203 MHz. It is a high-performance and low-power hard macro unit. The ARM920T has an enhanced ARM architecture MMU (supporting WinCE, EPOC 32 and Linux), 16kB of instruction and data cache, and a high-speed AMBA bus interface. The S3C2410 is designed for integrated systems in handheld devices and general embedded applications. To reduce overall system cost, the S3C2410 also includes the following components: LCD controller (STN & TFT), NAND Flash bootloader, system management (chip select logic and SDRAM controller), 3-channel UART, 4-channel DMA, 4-channel PWM clock, I/O ports, RTC, 8-channel 10-bit ADC and touchscreen interface, IIC bus interface, IIS bus interface, USB host port and USB device port, SD host port and multimedia card interface, 2-channel SPI and 2-channel PLL. The S3C2410 has two SPI ports for serial data transmission. Each SPI interface has two shift registers responsible for receiving and transmitting data respectively. During data transmission, sending and receiving data are synchronous, and the transmission frequency can be set by the corresponding control registers. If only sending data is desired, the receiving data is dummy; if only receiving data is desired, a dummy "0xff" must be sent. The SPI interface has four pin signals: serial clock SCK (SPICLK0, 1), master-in-slave-out MISO (SPICLK0, 1), master-out-slave-in MOSI (SPIMOSI0, 1), data line, and active-low pin /SS (nSSO, 1). The S3C2410's SPI interface has the following characteristics: (1) compatible with the SPI protocol (ver. 2.11); (2) has 8-bit shift registers for sending and receiving respectively; (3) has an 8-bit register for setting the transmission frequency; (4) has three transmission modes: polling, interrupt, and DMA. 3 Interface and Driver Based on the SPI characteristics of the S3C2410 and the working principle of the AD7888, its interface is determined as shown in Figure 3. [align=center][IMG=Connection diagram of AD7888 and S3C2410]/uploadpic/THESIS/2007/12/2007121410593668804F.jpg[/IMG] Figure 3 Connection diagram of AD7888 and S3C2410[/align] In order to realize the high-speed A/D conversion of S3C2410 and AD7888 under embedded Linux, a driver program for their interface was also written. The implementation of the driver program is mainly completed by the following functions. (1) Init_SPI() completes the initialization of SPI void Init_SPI(void) { int i; rSPPRE0=0x32; rSPCON0=0x1e; for (i=0;i<10;i++) rSPTDAT0=0xff; rGPECON |=0x0a800000; rGPECON&= (~0x05400000); rGPEUP |=0x3800; //GPH5————->CS rGPHCON |=0x0400; rGPHCON&= (~0x0800); rGPHUP&= (~0x20); rGPHDAT |=0x20; } (2) ad_wr() writes to the channel requiring A/D conversion static ssize_t ad_wr(struCt file *file,const char *bur,size_t count,loft_t *offset) {int ret="0"; int i="0"; dbuf="kmalloc"(count *sizeof(unsigned char),GFP_KERNEL); copy_from_user(dbuf,bur,count); for(i=0;i ADTXdata[i]=dbuf[i]; kfree(dbuf); return ret; } (3) ad_rd() gets the result of A/D conversion statie ssize_t ad_rd(struet file *file,char *bur,size_t count,loft t *offset) {int ret="0"; int i="0"; ad_convert(); ad_convert(); dbuf="kmalloc"(count *sizeof(unsigned char), GFP KERNEL); for (i=0;i dbuf[i]=ADRXdata[i]; copy_to_user(bur,dbuf,count); kfree(dbuf); return ret; } (4) ad_convert() actually completes the A/D conversion void ad_convert(void) { rGPHDAT&=(~0x20); udelay(100000); spi_tx_data(ADTXdata[0]); ADRXdata[0]=rSPRDATO; spi_tx_data(0xff); ADRXdata[1]=rSPRDATO; rGPHDAT |=0x20; } (5) spi_tx_data() completes the data transmission void spi_tx_data(unsigned char data) { spi_poll_done(); rSPTDAT0=data; spi_poll_done(); } (6) spi_poll_done() polls the SPI status static void spi_poll_done(void) { while (!(rSPSTA0&0x01)); } Explanation: 1) ADTXdata and ADRXdata are unsigned char global array variables, responsible for storing the control register data of AD7888 and the A/D conversion result, respectively. 2) ad_rd() calls ad_convert() twice. The first call is used to notify that data from a certain channel is to be acquired, and the second call is used to obtain the A/D conversion result of that channel. Although this sacrifices some conversion speed, it makes application programming more intuitive. 4 Conclusion The application of serial A/D converters with SPI interfaces occupies less microprocessor I/O resources, the hardware connection is simple, the software is easy to implement, and the program runs efficiently. The combination of serial A/D converters with SPI interfaces and ARM microprocessors can be widely used in handheld devices and other embedded systems that implement data acquisition functions, such as medical instruments, communication equipment, meter reading equipment, etc.
Read next

CATDOLL 135CM Lucy(TPE Body with Hard Silicone Head)

Height: 135cm Weight: 24.5kg Shoulder Width: 33cm Bust/Waist/Hip: 62/57/69cm Oral Depth: 3-5cm Vaginal Depth: 3-15cm An...

Articles 2026-02-22