schorsch_76
04.09.2014, 10:51
Hallo Kollegen,
kleine Frage: Wenn ich versuche mit einem I2C Slave zu sprechen und es kommt bsp. anstatt eines mt_data_ack ein mt_data_nack, hab ich ja ein Problem. Wie bringe ich den Bus dann wieder in einen Ok zustand? Muss ich einfach eine Stop Condition senden und es später nochmal probieren?
PseudoCode:
// sent byte from the queue
send_byte(data);
.....
// check if the data was accepted
if(!is_answer_tw_mt_data_ack())
{
// data was declined, set a flag for the user
send_stop_condition();
m_error_code = rx_no_answer_tw_mt_data_ack;
return;
}
Ist das die richtige Methode den Atmega I2C Master wieder in einen guten Zustand zu bringen?
Edit: Das hab ich daszu im Datasheet des Atmega168 gefunden auf Seite 219
7. The application software should now examine the value of TWSR, to make sure that the
data packet was successfully transmitted, and that the value of the ACK bit was as
expected. If TWSR indicates otherwise, the application software might take some special
action, like calling an error routine. Assuming that the status code is as expected, the
application must write a specific value to TWCR, instructing the TWI hardware to transmit
a STOP condition. Which value to write is described later on. However, it is important that
the TWINT bit is set in the value written. Writing a one to TWINT clears the flag. The TWI
will not start any operation as long as the TWINT bit in TWCR is set. Immediately after
the application has cleared TWINT, the TWI will initiate transmission of the STOP condition.
Note that TWINT is NOT set after a STOP condition has been sent.
kleine Frage: Wenn ich versuche mit einem I2C Slave zu sprechen und es kommt bsp. anstatt eines mt_data_ack ein mt_data_nack, hab ich ja ein Problem. Wie bringe ich den Bus dann wieder in einen Ok zustand? Muss ich einfach eine Stop Condition senden und es später nochmal probieren?
PseudoCode:
// sent byte from the queue
send_byte(data);
.....
// check if the data was accepted
if(!is_answer_tw_mt_data_ack())
{
// data was declined, set a flag for the user
send_stop_condition();
m_error_code = rx_no_answer_tw_mt_data_ack;
return;
}
Ist das die richtige Methode den Atmega I2C Master wieder in einen guten Zustand zu bringen?
Edit: Das hab ich daszu im Datasheet des Atmega168 gefunden auf Seite 219
7. The application software should now examine the value of TWSR, to make sure that the
data packet was successfully transmitted, and that the value of the ACK bit was as
expected. If TWSR indicates otherwise, the application software might take some special
action, like calling an error routine. Assuming that the status code is as expected, the
application must write a specific value to TWCR, instructing the TWI hardware to transmit
a STOP condition. Which value to write is described later on. However, it is important that
the TWINT bit is set in the value written. Writing a one to TWINT clears the flag. The TWI
will not start any operation as long as the TWINT bit in TWCR is set. Immediately after
the application has cleared TWINT, the TWI will initiate transmission of the STOP condition.
Note that TWINT is NOT set after a STOP condition has been sent.