unsigned char i2c_read(void)
{
unsigned char read_data = 0;
//按照i2c协议
TWCR = 0xA4; // send a start bit on i2c bus
while(!(TWCR & 0x80)); // wait for confirmation of transmit
TWDR = 0x92; // load address of i2c device
TWCR = 0x84; // transmit
while(!(TWCR & 0x80)); // wait for confirmation of transmit
TWDR = 0x00; // send register number to read from
TWCR = 0x84; // transmit
while(!(TWCR & 0x80)); // wait for confirmation of transmit
TWCR = 0xA4; // send repeated start bit
while(!(TWCR & 0x80)); // wait for confirmation of transmit
TWDR = 0x93; // transmit i2c address with readbit set
TWCR = 0xC4; // clear transmit interupt flag
while(!(TWCR & 0x80)); // wait for confirmation of transmit
TWCR = 0x84; // transmit, nack ()
while(!(TWCR & 0x80)); // wait for confirmation of transmit
read_data = TWDR; // and grab the target data
TWCR = 0x84;
while(!(TWCR & 0x80));
read_data = TWDR;
TWCR = 0x94; // send a stop bit on i2c bus
return read_data;
}
用MEGA128的TWI总线读ADS7823的数据前边都对,到了最后读取的时候读第一个字节就NACK了,而且读的数据也不对
,这里是ADS7823的资料
http://pdf1.alldatasheet.com/dat ... -BROWN/ADS7823.html
哪位大神有时间帮忙看看,谢谢了,程序我在网上找了很多,就这个是最简练的,其他的程序我也都实验过了,效果都一样,排除了ADS7823出问题的可能了。是不是单片机的问题呢?