I am trying to read a simple i2C temperature sensor. I can write to the sensors registers no problem and I receive all the ACK's as expected. The problem comes in when I try to read from the sensor. The start condition is initiated and the sensor ACK's then without doing anything else the SCL line is clocked an additional 8 times. What I am confused about is why are there additional clock cycles initiated after the start instruction? I cant tell if the master is driving the clock or if the slave is driving the clock for those 8 additional cycles.
The bus hangs because the master is not ACKING but who and why were those additional clock cycles initiated? When I debug the code the start function hangs on while(!(TWI0.MSTATUS & (TWI_WIF_bm))); so as far as i can tell it should have only clocked out the address of the slave with the read bit then waited for the ack and that's it.
void i2c_init() { //set BAUD TWI0.MBAUD = BAUD; //flush TWI0.MCTRLB |= TWI_FLUSH_bm; //enable master TWI0.MCTRLA |= TWI_ENABLE_bm | TWI_SMEN_bm; //set bus initial state to idle TWI0.MSTATUS |= TWI_BUSSTATE_IDLE_gc; } void i2c_start(uint8_t i2c_addr) { TWI0.MCTRLA |= TWI_TIMEOUT_200US_gc; //setting address automatically creates a start condition TWI0.MADDR = i2c_addr; while(!(TWI0.MSTATUS & (TWI_WIF_bm))); //During debugging the function never gets past this point so why are additional clock signals toggled? } int main(void) { i2c_init(); while (1) { i2c_start(TEMP_SEN_READ); } }