Could two I2C START signals be sent one after another without a STOP signal sent in between? Below is an example of bit banging, where there is not STOP between the first and second START:
int16_t BMP180_readRegister16(uint8_t reg) {
i2c_start();
i2c_writeByte(BMP180_ADDRESS);
if(!i2c_check_ack()){
i2c_stop();
return(0);
}
i2c_writeByte(reg);
if(!i2c_check_ack()){
i2c_stop();
return(0);
}
i2c_start();
i2c_writeByte(BMP180_ADDRESS+1);
if(!i2c_check_ack()){
//os_printf("slave not ack..\n return \n");
i2c_stop();
return(0);
}
uint8_t msb = i2c_readByte();
i2c_send_ack(1);
uint8_t lsb = i2c_readByte();
i2c_send_ack(0);
i2c_stop();
int16_t res = msb << 8;
res += lsb;
return res;
}
Doesn't each START sequence have to be closed by a STOP sequence?
Thanks
Answer
Yes, this is called a "repeated start". Per the Wikipedia page:
In a combined message, each read or write begins with a START and the slave address. After the first START in a combined message these are also called repeated START bits. Repeated START bits are not preceded by STOP bits, which is how slaves know the next transfer is part of the same message.
In a multi-master configuration, a repeated start also ensures that another master can't grab the bus between two different transactions.
No comments:
Post a Comment