Fx2lib
0.2
|
#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 |
Utilities for reading and writing to i2c devices and as eeproms.
Definition in file i2c.h.
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.
prom_addr | eeprom i2c address |
addr | address of bytes to start reading |
len | number of bytes to read |
buf | data buffer |
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.
prom_addr | eeprom i2c address |
addr | address of bytes to start writing |
len | number of bytes to write |
buf | data buffer |
read data on the i2c bus.
addr | i2c address |
len | number of bytes to read |
buf | buffer to store data |
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.
addr | i2c address |
len1 | length of addr data |
addr_buf | addr data |
len2 | length of data |
data_buf | data bytes |
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).