|
![](static/image/common/ico_lz.png)
楼主 |
发表于 2012-4-4 10:24:21
|
显示全部楼层
本帖最后由 liuqian 于 2012-4-4 10:26 编辑
at24cxx.c中的程序
void at24cxx_write_byte(uint16_t byte_address, uint8_t byte_value) {
uint8_t pack[3];
twi_package_t twi_package;
pack[0] = (byte_address&0xFF00)>>8;
pack[1] = byte_address&0xFF;
pack[2] = byte_value;
twi_package.chip = AT24CXX_TWI_ADDRESS;
twi_package.addr_length = 1; <<<<<======不一样???
twi_package.buffer = &pack;
twi_package.length = sizeof(pack);
while(twi_master_write(AT24CXX_TWI, &twi_package)!=TWI_SUCCESS);
return;
}
void at24cxx_write_continuous(uint16_t start_address, uint16_t length, uint8_t const *wr_buffer) {
uint8_t *pack = {0};
twi_package_t twi_package;
pack[0] = (start_address&0xFF00)>>8;
pack[1] = start_address&0xFF;
uint16_t idx;
for (idx=0;idx<length;idx++)
pack[2+idx] = wr_buffer[idx];
twi_package.chip = AT24CXX_TWI_ADDRESS;
twi_package.addr_length = 0; <<<<<===== 不一样???
twi_package.buffer = &pack;
twi_package.length = sizeof(pack);
while(twi_master_write(AT24CXX_TWI, &twi_package)!=TWI_SUCCESS);
return;
}
uint8_t at24cxx_read_byte(uint16_t byte_address) {
uint8_t data;
twi_package_t twi_package;
twi_package.chip = AT24CXX_TWI_ADDRESS;
twi_package.addr_length = 0;
twi_package.buffer = &byte_address;
twi_package.length = 2;
while(twi_master_write(AT24CXX_TWI, &twi_package)!=TWI_SUCCESS);
twi_package.chip = AT24CXX_TWI_ADDRESS;
twi_package.addr_length = 0;
twi_package.buffer = &data;
twi_package.length = 1;
while(twi_master_read(AT24CXX_TWI, &twi_package)!=TWI_SUCCESS);
return data;
}
void at24cxx_read_continuous(uint16_t start_address, uint16_t length, uint8_t *rd_buffer) {
twi_package_t twi_package;
twi_package.chip = AT24CXX_TWI_ADDRESS;
twi_package.addr_length = 0;
twi_package.buffer = &start_address;
twi_package.length = 2;
while(twi_master_write(AT24CXX_TWI, &twi_package)!=TWI_SUCCESS);
twi_package.chip = AT24CXX_TWI_ADDRESS;
twi_package.addr_length = 0;
twi_package.buffer = rd_buffer;
twi_package.length = length;
while(twi_master_read(AT24CXX_TWI, &twi_package)!=TWI_SUCCESS);
}
不明白 twi_package.addr_length 是干什么用的 |
|