Design Idea
I²C interface connects CompactFlash card to microcontroller
Expand data-storage capacity with inexpensive memory cards.
Fons Janssen, Maxim Integrated Products Inc, Sunnyvale, CA; Edited by Brad Thompson and Fran Granville -- EDN, 9/1/2006
Logging data from a large number of monitored channels usually requires a lot of memory for storing the measured data. Unfortunately, smaller microcontrollers offer only limited amounts of internal data RAM and EEPROM and may also lack spare address and data ports for adding external memory. Many low-end microcontrollers include an industry-standard I2C interface for attaching external ADCs, DACs, real-time clocks, and other peripherals.
The circuit in Figure 1 connects a CompactFlash card to a microcontroller's I2C interface through IC1, a 16-bit I2C I/O extender. In memory-mapped mode, an 8-bit-wide data bus controls the CompactFlash card. Microcontroller IC1's Port 1 (I/O lines 0 through 7) connects to the CompactFlash card's data bus and provides read and write access to the card's data registers. Port 2 provides the card's address and control registers and generates the read and write signals.
To write to a register, configure Port 1 as an output and write the data to the port. Next, write the register-control data three consecutive times to Port 2 while toggling the port's WRN pin from Logic 1 to Logic 0 to Logic 1 to generate the "write" signal. Address bits A2, A1, and A0 select the register that receives the written data. Applying Logic 0 to the CE pin while RDN rests at Logic 1 enables the CompactFlash card. To read from a register, configure Port 1 as an input port and apply three writes to Port 2 while toggling the port's RDN pin from Logic 1 to Logic 0 to Logic 1 to generate the "read" signal.
After the three writes, the microcontroller reads Port 1 and makes the data available. Address bits A2, A1, and A0 address eight internal registers and allow read and write access (Table 1). Register 0x00 contains data for exchange between the host and the CompactFlash card. Registers 0x03, 0x04, 0x05, and 0x06 specify the track for reading or writing data. Each track contains 512 data bytes. The processor indicates reading and writing tracks and other functions by writing to 0x07, the command register, and registers 0x01 and 0x07 contain error conditions and status information.
Two unused pins, 10 and 11, on Port 2 are available to drive LEDs that display circuit activity and status. As an alternative, the pins can support a user-installed configuration jumper. In this configuration, IC1's interrupt output should connect to the host microcontroller's interrupt input so that installation or removal of the jumper can signal the microcontroller to recognize or ignore the CompactFlash card. Selecting a CompactFlash-card connector with hot-plugging contacts allows insertion or removal of a card without switching off power or disturbing an ongoing data-logging process.
With software modifications, a host microcontroller can switch between two CompactFlash cards. Adding a second MAX7311 supports an additional CompactFlash card and expands the circuit's storage capacity, and the hot-plug feature supports removal of a fully loaded card for data processing on another system. Microcontrollers that include hardware-based I2C interfaces can use two relatively simple I2C software functions to read and write a CompactFlash card through IC1's I/O ports.
The first function is: Write_MAX3711(slv,prt,dat). This procedure starts the I2C bus and sends a data byte (dat) to a port (prt) on the MAX7311 using a slave address (slv). The other procedure, Read_MAX3711(slv,prt), starts the I2C bus and reads a data byte from a port on the MAX7311 at a slave address. These functions serve as foundations for two additional functions, which read and write to the CompactFlash card's registers. The first, Write_CF_REG(reg,dat), uses Write_MAX3711 to place the data on Port 1. Use the same procedure to place the register address (reg) and other control signals on Port 2. Executing this function three times while toggling WRN generates the write signal. The Read_CF_REG(reg) procedure uses Write_MAX7311 to address the CompactFlash card's register and generates the read signal. Invoking Read_MAX7311 then reads the data from the register.
These functions, which in turn read and write the card's registers, create functions that access the CompactFlash-card sectors: Write_CF(cyl,head,sec). To perform a write operation, this procedure uses Write_CF_REG to designate the CompactFlash card's target cylinder, head, and sector registers (0x03 to 0x06). Next, writing 0x30 to the command register configures the CompactFlash card to accept data. Executing Write_CF_REG 512 times writes data in the microcontroller's global array to the data register. The CompactFlash card automatically adds this data to the current track. To perform a read operation, the Read_CF(cyl,head,sec) procedure uses Write_CF_REG to designate the target cylinder, head, and sector. Next, writing 0x20 to the command register configures the CompactFlash card to deliver data to the host processor. Executing Read_CF_REG 512 times reads all 512 bytes through the data register from the current CompactFlash card's track and places the data in a global array.
If the microcontroller lacks sufficient internal memory to store 512 data bytes, the software can write each digitized data-point measurement directly to the CompactFlash card. For additional information on controlling CompactFlash cards, review the material in Reference 1.
| Reference |
|
















