STM8L15x Standard Peripherals Drivers
|
Interrupts, events and flags management functions. More...
Functions | |
ErrorStatus | I2C_CheckEvent (I2C_TypeDef *I2Cx, I2C_Event_TypeDef I2C_Event) |
=============================================================================== 1. | |
void | I2C_ClearFlag (I2C_TypeDef *I2Cx, I2C_FLAG_TypeDef I2C_FLAG) |
Clear flags. | |
void | I2C_ClearITPendingBit (I2C_TypeDef *I2Cx, I2C_IT_TypeDef I2C_IT) |
Clear IT pending bit. | |
FlagStatus | I2C_GetFlagStatus (I2C_TypeDef *I2Cx, I2C_FLAG_TypeDef I2C_FLAG) |
=============================================================================== 3. | |
ITStatus | I2C_GetITStatus (I2C_TypeDef *I2Cx, I2C_IT_TypeDef I2C_IT) |
Checks whether the specified I2C interrupt has occurred or not. | |
I2C_Event_TypeDef | I2C_GetLastEvent (I2C_TypeDef *I2Cx) |
=============================================================================== 2. | |
void | I2C_ITConfig (I2C_TypeDef *I2Cx, I2C_IT_TypeDef I2C_IT, FunctionalState NewState) |
Enables or disables the specified I2C interrupt. | |
uint8_t | I2C_ReadRegister (I2C_TypeDef *I2Cx, I2C_Register_TypeDef I2C_Register) |
Reads the specified I2C register and returns its value. |
Detailed Description
Interrupts, events and flags management functions.
=============================================================================== Interrupts, events and flags management functions =============================================================================== This section provides functions allowing to configure the I2C Interrupts sources and check or clear the flags or pending bits status. The user should identify which mode will be used in his application to manage the communication: Polling mode, Interrupt mode or DMA mode. =============================================================================== I2C State Monitoring Functions =============================================================================== This I2C driver provides three different ways for I2C state monitoring depending on the application requirements and constraints: 1. Basic state monitoring (Using I2C_CheckEvent() function) ----------------------------------------------------------- It compares the status registers (SR1, SR2 and SR3) content to a given event (can be the combination of one or more flags). It returns SUCCESS if the current status includes the given flags and returns ERROR if one or more flags are missing in the current status. - When to use: - This function is suitable for most applications as well as for startup activity since the events are fully described in the product reference manual (RM0031). - It is also suitable for users who need to define their own events. - Limitations: - If an error occurs (ie. error flags are set besides to the monitored flags), the I2C_CheckEvent() function may return SUCCESS despite the communication hold or corrupted real state. In this case, it is advised to use error interrupts to monitor the error events and handle them in the interrupt IRQ handler. @note For error management, it is advised to use the following functions: - I2C_ITConfig() to configure and enable the error interrupts (I2C_IT_ERR). - I2Cx_IRQHandler() which is called when the I2C interrupts occur. Where x is the peripheral instance (I2C1,...) - I2C_GetFlagStatus() or I2C_GetITStatus() to be called into the I2Cx_IRQHandler() function in order to determine which error occurred. - I2C_ClearFlag() or I2C_ClearITPendingBit() and/or I2C_SoftwareResetCmd() and/or I2C_GenerateStop() in order to clear the error flag and source and return to correct communication status. 2. Advanced state monitoring (Using the function I2C_GetLastEvent()) -------------------------------------------------------------------- Using the function I2C_GetLastEvent() which returns the image of both SR1 & SR3 status registers in a single word (uint16_t) (Status Register 3 value is shifted left by 8 bits and concatenated to Status Register 1). - When to use: - This function is suitable for the same applications above but it allows to overcome the limitations of I2C_GetFlagStatus() function (see below). The returned value could be compared to events already defined in the library (stm8l15x_i2c.h) or to custom values defined by user. - This function is suitable when multiple flags are monitored at the same time. - At the opposite of I2C_CheckEvent() function, this function allows user to choose when an event is accepted (when all events flags are set and no other flags are set or just when the needed flags are set like I2C_CheckEvent() function). - Limitations: - User may need to define his own events. - Same remark concerning the error management is applicable for this function if user decides to check only regular communication flags (and ignores error flags). 3. Flag-based state monitoring (Using the function I2C_GetFlagStatus()) ----------------------------------------------------------------------- Using the function I2C_GetFlagStatus() which simply returns the status of one single flag (ie. I2C_FLAG_RXNE ...). - When to use: - This function could be used for specific applications or in debug phase. - It is suitable when only one flag checking is needed (most I2C events are monitored through multiple flags). - Limitations: - When calling this function, the Status register is accessed. Some flags are cleared when the status register is accessed. So checking the status of one Flag, may clear other ones. - Function may need to be called twice or more in order to monitor one single event. For detailed description of Events, please refer to section I2C_Events in stm8l15x_i2c.h file.
Function Documentation
ErrorStatus I2C_CheckEvent | ( | I2C_TypeDef * | I2Cx, |
I2C_Event_TypeDef | I2C_Event | ||
) |
=============================================================================== 1.
Basic state monitoring =============================================================================== Checks whether the last I2Cx Event is equal to the one passed as parameter.
- Note:
- : For detailed description of Events, please refer to section I2C_Events in stm8l15x_i2c.h file.
Definition at line 1038 of file stm8l15x_i2c.c.
References __IO, ERROR, I2C_EVENT_SLAVE_ACK_FAILURE, I2C_SR2_AF, IS_I2C_EVENT, I2C_struct::SR1, I2C_struct::SR2, I2C_struct::SR3, and SUCCESS.
void I2C_ClearFlag | ( | I2C_TypeDef * | I2Cx, |
I2C_FLAG_TypeDef | I2C_FLAG | ||
) |
Clear flags.
- Note:
- STOPF (STOP detection) is cleared by software sequence: a read operation to I2C_SR1 register (I2C_GetFlagStatus()) followed by a write operation to I2C_CR2 register.
- ADD10 (10-bit header sent) is cleared by software sequence: a read operation to I2C_SR1 (I2C_GetFlagStatus()) followed by writing the second byte of the address in DR register.
- BTF (Byte Transfer Finished) is cleared by software sequence: a read operation to I2C_SR1 register (I2C_GetFlagStatus()) followed by a read/write to I2C_DR register (I2C_SendData()).
- ADDR (Address sent) is cleared by software sequence: a read operation to I2C_SR1 register(I2C_GetFlagStatus()) followed by a read operation to I2C_SR3 register ((void)(I2Cx->SR3)).
- SB (Start Bit) is cleared software sequence: a read operation to I2C_SR1 register (I2C_GetFlagStatus()) followed by a write operation to I2C_DR register (I2C_SendData()).
Definition at line 1223 of file stm8l15x_i2c.c.
References FLAG_Mask, IS_I2C_CLEAR_FLAG, and I2C_struct::SR2.
void I2C_ClearITPendingBit | ( | I2C_TypeDef * | I2Cx, |
I2C_IT_TypeDef | I2C_IT | ||
) |
Clear IT pending bit.
- Note:
- STOPF (STOP detection) is cleared by software sequence: a read operation to I2C_SR1 register (I2C_GetITStatus()) followed by a write operation to I2C_CR2 register (I2C_AcknowledgeConfig() to configure the I2C peripheral Acknowledge).
- ADD10 (10-bit header sent) is cleared by software sequence: a read operation to I2C_SR1 (I2C_GetITStatus()) followed by writing the second byte of the address in I2C_DR register.
- BTF (Byte Transfer Finished) is cleared by software sequence: a read operation to I2C_SR1 register (I2C_GetITStatus()) followed by a read/write to I2C_DR register (I2C_SendData()).
- ADDR (Address sent) is cleared by software sequence: a read operation to I2C_SR1 register (I2C_GetITStatus()) followed by a read operation to I2C_SR3 register ((void)(I2Cx->SR3)).
- SB (Start Bit) is cleared by software sequence: a read operation to I2C_SR1 register (I2C_GetITStatus()) followed by a write operation to I2C_DR register (I2C_SendData()).
Definition at line 1334 of file stm8l15x_i2c.c.
References FLAG_Mask, IS_I2C_CLEAR_IT, and I2C_struct::SR2.
FlagStatus I2C_GetFlagStatus | ( | I2C_TypeDef * | I2Cx, |
I2C_FLAG_TypeDef | I2C_FLAG | ||
) |
=============================================================================== 3.
Flag-based state monitoring =============================================================================== Checks whether the specified I2C flag is set or not.
Definition at line 1146 of file stm8l15x_i2c.c.
References IS_I2C_GET_FLAG, RESET, SET, I2C_struct::SR1, I2C_struct::SR2, and I2C_struct::SR3.
ITStatus I2C_GetITStatus | ( | I2C_TypeDef * | I2Cx, |
I2C_IT_TypeDef | I2C_IT | ||
) |
Checks whether the specified I2C interrupt has occurred or not.
Definition at line 1258 of file stm8l15x_i2c.c.
References __IO, IS_I2C_GET_IT, ITEN_Mask, I2C_struct::ITR, REGISTER_Mask, REGISTER_SR1_Index, RESET, SET, I2C_struct::SR1, and I2C_struct::SR2.
I2C_Event_TypeDef I2C_GetLastEvent | ( | I2C_TypeDef * | I2Cx | ) |
=============================================================================== 2.
Advanced state monitoring =============================================================================== Returns the last I2C Event.
- Note:
- : For detailed description of Events, please refer to section I2C_Events in stm8l15xx_i2c.h file.
Definition at line 1089 of file stm8l15x_i2c.c.
References __IO, I2C_EVENT_SLAVE_ACK_FAILURE, I2C_SR2_AF, I2C_struct::SR1, I2C_struct::SR2, and I2C_struct::SR3.
void I2C_ITConfig | ( | I2C_TypeDef * | I2Cx, |
I2C_IT_TypeDef | I2C_IT, | ||
FunctionalState | NewState | ||
) |
Enables or disables the specified I2C interrupt.
Definition at line 948 of file stm8l15x_i2c.c.
References DISABLE, IS_FUNCTIONAL_STATE, IS_I2C_CONFIG_IT, and I2C_struct::ITR.
uint8_t I2C_ReadRegister | ( | I2C_TypeDef * | I2Cx, |
I2C_Register_TypeDef | I2C_Register | ||
) |
Reads the specified I2C register and returns its value.
Definition at line 988 of file stm8l15x_i2c.c.
References __IO, and IS_I2C_REGISTER.