u-boot提供了I2C的接口,驱动程序在 ./cpu/arm920t/s3c24x0/i2c.c 中,在 smdk2440.h 中加入
#define CONFIG_DRIVER_S3C24X0_I2C 1 /* we use the buildin I2C controller */
#define CONFIG_HARD_I2C 1 /* I2C with hardware support */
#define CFG_I2C_SPEED 100000 /* I2C speed and slave address */
#define CFG_I2C_SLAVE 0x50
#define CFG_I2C_EEPROM_ADDR_LEN 1 /* Bytes of address */
/* mask of address bits that overflow into the "EEPROM chip address" */
#define CFG_I2C_EEPROM_ADDR_OVERFLOW 0x07
在board.c 文件中加入 write_info2eeprom() 将u-boot 生成的日期写入 24c16的 0x50位置中。
static void write_info2eeprom() { memset(uboot_info,0,sizeof(uboot_info); strcpy(uboot_info, __DATE__); i2c_init(CFG_I2C_SPEED, CFG_I2C_SLAVE); i2c_write(CFG_I2C_SLAVE, 0x50, 1, uboot_info, 6); memset(uboot_info,0,sizeof(uboot_info); i2c_read(CFG_I2C_SLAVE, 0x50, 1, uboot_info, 6); printf("read back: %s\n", uboot_info); }
|
其中读/写这2个函数的说明
/*
* Read/Write interface:
* chip: I2C chip address, range 0..127
* addr: Memory (register) address within the chip
* alen: Number of bytes to use for addr (typically 1, 2 for larger
* memories, 0 for register type devices with only one
* register)
* buffer: Where to read/write the data
* len: How many bytes to read/write
*
* Returns: 0 on success, not 0 on failure
*/
int i2c_read(uchar chip, uint addr, int alen, uchar *buffer, int len);
int i2c_write(uchar chip, uint addr, int alen, uchar *buffer, int len);
其中alen 为1,说明chip是8bit的, 为2则是 16bit的。
阅读(5678) | 评论(1) | 转发(0) |