printing complete status infos

This commit is contained in:
hugo LAMY
2025-03-16 17:36:48 +01:00
parent 35582f4286
commit e4bbf40bb8
4 changed files with 173 additions and 49 deletions

View File

@@ -71,7 +71,7 @@ void i2c_send_addr_r(uint8_t slave_address) {
// }
}
void i2c_write(unsigned char data) {
void i2c_write(uint8_t data) {
if (i2c_status == STOP) {
return;
}
@@ -85,18 +85,20 @@ void i2c_write(unsigned char data) {
// }
}
void i2c_read(void) {
uint8_t i2c_read(void) {
if (i2c_status == STOP) {
return;
}
// TWDR = data; // 22.9.4 : (Data Register) load data into TWDR register
// TWCR = SEND_CONTINUE_TRANSMISSION; // p225 example code : Load DATA into TWDR Register. Clear TWINT bit in TWCR to start transmission of data
// while (!(TEST(TWCR, TWINT))); // p225 example code : Wait for TWINT Flag set. This indicates that the DATA has been transmitted, and ACK/NACK has been received
TWCR = SEND_CONTINUE_TRANSMISSION; // 22.7.1 : Master Transmitter Mode
while (!(TEST(TWCR, TWINT))); // 22.7.1 : Wait for TWINT Flag set. This indicates that the SLA+R/W has been transmitted, and ACK/NACK has been received
// uint8_t status = TWSR & 0b11111000; // p225 example code : Check status for Receiver mode. Mask prescaler bits. If status different from MT_DATA_ACK go to ERROR
// if (status != TW_MT_DATA_ACK) {
// return i2c_stop();
// }
return TWDR; // 22.9.4 : (Data Register) load data into TWDR register
}
void i2c_stop(void) {