Fx2lib  0.2
Functions | Variables
include/i2c.h File Reference
#include "fx2types.h"

Go to the source code of this file.

Functions

BOOL i2c_write (BYTE addr, WORD len1, BYTE *addr_buf, WORD len2, BYTE *data_buf)
 write data to i2c bus.
BOOL i2c_read (BYTE addr, WORD len, BYTE *buf)
 read data on the i2c bus.
BOOL eeprom_read (BYTE prom_addr, WORD addr, WORD len, BYTE *buf)
 read data from an attached eeprom.
BOOL eeprom_write (BYTE prom_addr, WORD addr, WORD len, BYTE *buf)
 write data to the eeprom

Variables

volatile __xdata BOOL cancel_i2c_trans

Detailed Description

Utilities for reading and writing to i2c devices and as eeproms.

Definition in file i2c.h.


Function Documentation

BOOL eeprom_read ( BYTE  prom_addr,
WORD  addr,
WORD  len,
BYTE buf 
)

read data from an attached eeprom.

Writes the address of the data to read then reads len bytes into buf. This function checks the I2CS register to determine if a one or two byte address eepom was detected on the i2c bus. Reading from proms at non-standard addresses my require using the i2c_read/write commands explicitly.

Parameters:
prom_addreeprom i2c address
addraddress of bytes to start reading
lennumber of bytes to read
bufdata buffer
BOOL eeprom_write ( BYTE  prom_addr,
WORD  addr,
WORD  len,
BYTE buf 
)

write data to the eeprom

This function checks the I2CS register to determin if a one or two two byte eeprom is detected. If the prom is not detected at boot time or is connected to alternate addresses, the i2c_read/write commands should be used explicitly insread of using this function.

For each byte in buf, the address is written and then the data byte. Many proms support writing multiple bytes at the same time. For these, it is also better to use i2c_read/write explicitly. This function is rather slow but is effective.

Parameters:
prom_addreeprom i2c address
addraddress of bytes to start writing
lennumber of bytes to write
bufdata buffer
BOOL i2c_read ( BYTE  addr,
WORD  len,
BYTE buf 
)

read data on the i2c bus.

Parameters:
addri2c address
lennumber of bytes to read
bufbuffer to store data
BOOL i2c_write ( BYTE  addr,
WORD  len1,
BYTE addr_buf,
WORD  len2,
BYTE data_buf 
)

write data to i2c bus.

Writes data from addr buffer 1st, then data buffer. Either buffer can be NULL (as long as you set lenN to 0).

Two buffers allows writing data all in one i2c write command without having to write a hardware address and a data byte with each i2c transaction.

Parameters:
addri2c address
len1length of addr data
addr_bufaddr data
len2length of data
data_bufdata bytes

Variable Documentation

volatile __xdata BOOL cancel_i2c_trans

i2c_write and i2c_read set this to FALSE at the beginning of a transaction. If for some reason, the read/write is taking too long or not returning, firmware can set this to TRUE to cause the routine to abort. (Usually done via an interrupt).