2011-03-24 04:00 AM
I2C protocol STOP condition not detected in slave-transmission mode
2011-05-17 06:12 AM
Here is my Slave transmitter part in
@far @interrupt void I2C_IRQHandler(void) /* I2C Interrupt handler*/
is as follows
/*SLAVE TRANSMITTER*/
/*Data transmited from slave to master*/
/*EV3-1: TxE=1, shift register empty, data register empty, write DR register.*/
if(I2C_CheckEvent(I2C_EVENT_SLAVE_BYTE_TRANSMITTED))
{
/*Acknowledge failure*/
/*EV3-2: AF=1, AF is cleared by writing ‘0’ in AF bit of SR2 register*/
if(I2C_CheckEvent(I2C_EVENT_SLAVE_ACK_FAILURE))
{
I2C_ClearFlag(I2C_FLAG_ACKNOWLEDGEFAILURE);
}
/*EV3: TxE=1, cleared by writing DR; shift register not empty*/
I2C_SendData(SomeData);
I2C_ClearFlag(I2C_FLAG_TRANSFERFINISHED);
}
2011-05-17 06:12 AM
Here is Master-receiver implementation in I2C interrupt service routine
/*MASTER RECEIVER, read-write byte=1*/
else if(I2C_CheckEvent(I2C_EVENT_MASTER_BYTE_RECEIVED)) { /*EV7_1: RxNE=1, cleared by reading DR register, program ACK=0 and STOP request*/ if(SECOND_LAST_BYTE) { I2C_AcknowledgeConfig(I2C_ACK_NONE); I2C_CurrentReadData = I2C_ReceiveData(); } else if(LAST_BYTE) { I2C_CurrentReadData = I2C_ReceiveData(); I2C_GenerateSTOP(ENABLE); } //EV7: RxNE=1, cleared by reading DR register else { I2C_CurrentReadData = I2C_ReceiveData(); } I2C_ClearFlag(I2C_FLAG_RXNOTEMPTY); }2011-05-17 06:12 AM
The ACK failure is triggered in the slave when master sets ACK bit to 0
2011-05-17 06:12 AM
I am struggling for the last one week and have tried various combinations and permutations and have ran out of ideas - I have a requirement to implement Master-receiver and Slave-transmitter as interrupt state machines as outlined by the STM8S datasheet, polling is not an option. Any help will be highly appreciated