2017-09-05 01:17 PM
I2C peripheral of STM8S005C6 stop event interrupt not triggered
:Using an external device (verified to be working), I generate an I2C signal (100KHz) to communicate withSTM8S005C6
program as aslave
receiver with the7-bit address of 0x24
.I2C interrupt service routine is triggered by an incoming I2C signal. Address match and data receive events are detected. However, stop event (I2C_EVENT_SLAVE_STOP_DETECTED) is not detected. Through a digital logic analyzer, I see that each byte received has been acknowledged. And, stop condition is present.
For firmware side
, I am using the I2C example code with modifications provided by STM :/external-link.jspa?url=http%3A%2F%2Fwww.st.com%2Fen%2Fembedded-software%2Fstsw-stm8069.html
**********************************************C
ode Below*******************************
&sharpinclude ''stm8s.h''
&sharpinclude ''stm8s_clk.h''&sharpinclude ''stm8s_i2c.h''&sharpinclude ''stm8s_gpio.h''&sharpinclude ''stm8s_it.h''void main(void){
//
**************************************
Clock setup (16 MHz Internal clock + I2C peripheral clock) CLK_DeInit();CLK_HSECmd(DISABLE);
CLK_LSICmd(DISABLE);CLK_ClockSwitchCmd(DISABLE);CLK_HSICmd(ENABLE);while(CLK_GetFlagStatus(CLK_FLAG_HSIRDY) == FALSE);
CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);
CLK_SYSCLKConfig(CLK_PRESCALER_CPUDIV1);CLK_PeripheralClockConfig(CLK_PERIPHERAL_SPI, DISABLE);
CLK_PeripheralClockConfig(CLK_PERIPHERAL_I2C, ENABLE);CLK_PeripheralClockConfig(CLK_PERIPHERAL_ADC, DISABLE);CLK_PeripheralClockConfig(CLK_PERIPHERAL_AWU, DISABLE);CLK_PeripheralClockConfig(CLK_PERIPHERAL_UART1, DISABLE);CLK_PeripheralClockConfig(CLK_PERIPHERAL_TIMER1, DISABLE);CLK_PeripheralClockConfig(CLK_PERIPHERAL_TIMER2, DISABLE);CLK_PeripheralClockConfig(CLK_PERIPHERAL_TIMER4, DISABLE);//**************************************GPIO setup
GPIO_DeInit(GPIOB);GPIO_Init(GPIOB, GPIO_PIN_4, GPIO_MODE_OUT_OD_HIZ_FAST);GPIO_Init(GPIOB, GPIO_PIN_5, GPIO_MODE_OUT_OD_HIZ_FAST);//
**************************************
I2C setup (100KHz, 7 bit address mode, all I2C interrupt enable, address: 0x24) I2C_DeInit();I2C_Init(100000, (0x24<<1), I2C_DUTYCYCLE_2, I2C_ACK_CURR, I2C_ADDMODE_7BIT, (CLK_GetClockFreq() / 1000000));I2C_Cmd(ENABLE);I2C_ITConfig((I2C_IT_TypeDef)(I2C_IT_ERR | I2C_IT_EVT | I2C_IT_BUF), ENABLE);
// ***********************************************Enable general interruptsenableInterrupts();while(1);
}
// Excerpt from file ''stm8s_it.c''
INTERRUPT_HANDLER(I2C_IRQHandler, 19)
{/* Read SR2 register to get I2C error */if ((I2C->SR2) != 0){/* Clears SR2 register */I2C->SR2 = 0;}
Event = I2C_GetLastEvent();switch (Event){/* check on EV1*/case I2C_EVENT_SLAVE_RECEIVER_ADDRESS_MATCHED:Rx_Idx = 0;
break;/* Check on EV2*/
case I2C_EVENT_SLAVE_BYTE_RECEIVED:Slave_Buffer_Rx[Rx_Idx++] = I2C_ReceiveData();break;/* Check on EV4 */
case (I2C_EVENT_SLAVE_STOP_DETECTED):/* write to CR2 to clear STOPF flag */I2C->CR2 |= I2C_CR2_ACK;break;default:
break;}}
null