June 7, 2017 - 9:35am
permofrost li |
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 datsheet 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)<br />{<br /> /* In order to detect unexpected events during development,<br /> it is recommended to set a breakpoint on the following instruction.<br /> */<br /> if(I2C->SR2)<br /> {<br /> I2C->SR2 = 0;<br /> }<br /> if(I2C_GetITStatus(I2C_ITPENDINGBIT_STARTDETECTION))<br /> {<br /> I2C_ClearITPendingBit(I2C_ITPENDINGBIT_STARTDETECTION);<br /> IIC_Receive_event = 1; //START<br /> }<br /> else if(I2C_GetITStatus(I2C_ITPENDINGBIT_STOPDETECTION))<br /> {<br /> ////I2C_ClearITPendingBit(I2C_ITPENDINGBIT_STOPDETECTION);<br /> IIC_Receive_event = 3; //STOP<br /> }<br /> else if(I2C_GetITStatus(I2C_ITPENDINGBIT_RXNOTEMPTY))<br /> {<br /> //// I2C_ClearITPendingBit(I2C_ITPENDINGBIT_RXNOTEMPTY);<br /> IIC_Receive_data = I2C_ReceiveData();<br /> IIC_Receive_event = 2; //receive data<br /> }<br /> else if(I2C_GetITStatus(I2C_ITPENDINGBIT_TXEMPTY))<br /> {<br /> ////I2C_ClearITPendingBit(I2C_ITPENDINGBIT_TXEMPTY);<br /> IIC_Receive_event = 4; //send register invoid<br /> }<br /> else if(I2C_GetITStatus(I2C_ITPENDINGBIT_TRANSFERFINISHED)) //send successfully <br /> {<br /> I2C_ClearITPendingBit(I2C_ITPENDINGBIT_TRANSFERFINISHED);<br /> }<br /> else if(I2C_GetITStatus(I2C_ITPENDINGBIT_HEADERSENT)) //send successfully <br /> {<br /> I2C_ClearITPendingBit(I2C_ITPENDINGBIT_HEADERSENT); //10-bit Header sent<br /> } <br /> else if(I2C_GetITStatus(I2C_ITPENDINGBIT_ADDRESSSENTMATCHED)) //send and match address successfully <br /> {<br /> I2C_ClearITPendingBit(I2C_ITPENDINGBIT_ADDRESSSENTMATCHED); <br /> } <br /> else if(I2C_GetITStatus(I2C_ITPENDINGBIT_WAKEUPFROMHALT)) //aware<br /> {<br /> I2C_ClearITPendingBit(I2C_ITPENDINGBIT_WAKEUPFROMHALT); <br /> } <br /> else if(I2C_GetITStatus(I2C_ITPENDINGBIT_OVERRUNUNDERRUN)) //Overrun/Underrun<br /> {<br /> I2C_ClearITPendingBit(I2C_ITPENDINGBIT_OVERRUNUNDERRUN); <br /> } <br /> else if(I2C_GetITStatus(I2C_ITPENDINGBIT_ACKNOWLEDGEFAILURE)) //confirmation failed<br /> {<br /> I2C_ClearITPendingBit(I2C_ITPENDINGBIT_ACKNOWLEDGEFAILURE); <br /> } <br /> else if(I2C_GetITStatus(I2C_ITPENDINGBIT_ARBITRATIONLOSS)) //!< Arbitration Loss <br /> {<br /> I2C_ClearITPendingBit(I2C_ITPENDINGBIT_ARBITRATIONLOSS); <br /> } <br /> else if(I2C_GetITStatus(I2C_ITPENDINGBIT_BUSERROR)) //Misplaced Start or Stop condition<br /> {<br /> I2C_ClearITPendingBit(I2C_ITPENDINGBIT_BUSERROR); <br /> } <br /> else<br /> {<br /> nop();<br /> }<br /> <br />}
And the initialization is given below:
I2C_ITConfig((I2C_IT_TypeDef)(I2C_IT_ERR |I2C_IT_EVT|I2C_IT_BUF),ENABLE);<br /> I2C_Init(100000,0X51,I2C_DUTYCYCLE_2,I2C_ACK_CURR,I2C_ADDMODE_7BIT,CLK_GetClockFreq());<br /> I2C_Cmd(ENABLE);
Please give me some help!
Thanks a lot.
|
Hi,
When using ST standard peripheral library, you have to give attention to the order of the functions used in your programme.
You have to start by :
1°- Initializes the I2C according to the specified parameters --> I2C_Init().
2°- Enables or disables the specified I2C interrupt --> I2C_ITConfig().
3°- Enables the I2C peripheral --> I2C_Cmd().
You can test in which interruption your code is staked by adding an indication or display command line in every conditions.
We hope it helps.
Regards
Support Team