EN RU CN
Does anyone know that why STM8 always Interrupts
  • Hello,

    First of all,thank you for reading my post. I would like to ask some help about STM8.

    The MCU I used is STM809LWX6F, this is the datasheet of STM809LWX6F: http://www.kynix.com/uploadfiles/pdf8798/STM809LWX6F.pdf . All interrupt events I have listed out as following, I really don’t know why it still always enter into interruption?

    NTERRUPT_HANDLER(I2C_IRQHandler, 19)
    {
    /* In order to detect unexpected events during development,
    it is recommended to set a breakpoint on the following instruction.
    */
    if(I2C->SR2)
    {
    I2C->SR2 = 0;
    }
    if(I2C_GetITStatus(I2C_ITPENDINGBIT_STARTDETECTION))
    {
    I2C_ClearITPendingBit(I2C_ITPENDINGBIT_STARTDETECTION);
    IIC_Receive_event = 1; //START
    }
    else if(I2C_GetITStatus(I2C_ITPENDINGBIT_STOPDETECTION))
    {
    ////I2C_ClearITPendingBit(I2C_ITPENDINGBIT_STOPDETECTION);
    IIC_Receive_event = 3; //STOP
    }
    else if(I2C_GetITStatus(I2C_ITPENDINGBIT_RXNOTEMPTY))
    {
    //// I2C_ClearITPendingBit(I2C_ITPENDINGBIT_RXNOTEMPTY);
    IIC_Receive_data = I2C_ReceiveData();
    IIC_Receive_event = 2; //receive data
    }
    else if(I2C_GetITStatus(I2C_ITPENDINGBIT_TXEMPTY))
    {
    ////I2C_ClearITPendingBit(I2C_ITPENDINGBIT_TXEMPTY);
    IIC_Receive_event = 4; //send register invoid
    }
    else if(I2C_GetITStatus(I2C_ITPENDINGBIT_TRANSFERFINISHED)) //send successfully
    {
    I2C_ClearITPendingBit(I2C_ITPENDINGBIT_TRANSFERFINISHED);
    }
    else if(I2C_GetITStatus(I2C_ITPENDINGBIT_HEADERSENT)) //send successfully
    {
    I2C_ClearITPendingBit(I2C_ITPENDINGBIT_HEADERSENT); //10-bit Header sent
    }
    else if(I2C_GetITStatus(I2C_ITPENDINGBIT_ADDRESSSENTMATCHED)) //send and match address successfully
    {
    I2C_ClearITPendingBit(I2C_ITPENDINGBIT_ADDRESSSENTMATCHED);
    }
    else if(I2C_GetITStatus(I2C_ITPENDINGBIT_WAKEUPFROMHALT)) //aware
    {
    I2C_ClearITPendingBit(I2C_ITPENDINGBIT_WAKEUPFROMHALT);
    }
    else if(I2C_GetITStatus(I2C_ITPENDINGBIT_OVERRUNUNDERRUN)) //Overrun/Underrun
    {
    I2C_ClearITPendingBit(I2C_ITPENDINGBIT_OVERRUNUNDERRUN);
    }
    else if(I2C_GetITStatus(I2C_ITPENDINGBIT_ACKNOWLEDGEFAILURE)) //confirmation failed
    {
    I2C_ClearITPendingBit(I2C_ITPENDINGBIT_ACKNOWLEDGEFAILURE);
    }
    else if(I2C_GetITStatus(I2C_ITPENDINGBIT_ARBITRATIONLOSS)) //!< Arbitration Loss
    {
    I2C_ClearITPendingBit(I2C_ITPENDINGBIT_ARBITRATIONLOSS);
    }
    else if(I2C_GetITStatus(I2C_ITPENDINGBIT_BUSERROR)) //Misplaced Start or Stop condition
    {
    I2C_ClearITPendingBit(I2C_ITPENDINGBIT_BUSERROR);
    }
    else
    {
    nop();
    }

    }

    And the initialization is given below:

    I2C_ITConfig((I2C_IT_TypeDef)(I2C_IT_ERR |I2C_IT_EVT|I2C_IT_BUF),ENABLE);
    I2C_Init(100000,0X51,I2C_DUTYCYCLE_2,I2C_ACK_CURR,I2C_ADDMODE_7BIT,CLK_GetClockFreq());
    I2C_Cmd(ENABLE);

    Please give me some help!

    Thanks a lot.