STM8L15x Standard Peripherals Drivers: I2C

STM8L15x/16x Standard Peripherals Drivers

STM8L15x Standard Peripherals Drivers

I2C driver modules. More...

Modules

 I2C_Exported_Types
 I2C_Exported_Constants
 I2C_Exported_Macros
 I2C_Private_Define
 I2C_Private_Functions
 GPIO_Exported_Types
 GPIO_Exported_Macros

Functions

void GPIO_DeInit (GPIO_TypeDef *GPIOx)
 Deinitializes the GPIOx peripheral registers to their default reset values.
void GPIO_ExternalPullUpConfig (GPIO_TypeDef *GPIOx, uint8_t GPIO_Pin, FunctionalState NewState)
 Configures the external pull-up on GPIOx pins.
void GPIO_Init (GPIO_TypeDef *GPIOx, uint8_t GPIO_Pin, GPIO_Mode_TypeDef GPIO_Mode)
 Initializes the GPIOx according to the specified parameters.
uint8_t GPIO_ReadInputData (GPIO_TypeDef *GPIOx)
 Reads the specified GPIO input data port.
BitStatus GPIO_ReadInputDataBit (GPIO_TypeDef *GPIOx, GPIO_Pin_TypeDef GPIO_Pin)
 Reads the specified GPIO input data pin.
uint8_t GPIO_ReadOutputData (GPIO_TypeDef *GPIOx)
 Reads the specified GPIO output data port.
BitStatus GPIO_ReadOutputDataBit (GPIO_TypeDef *GPIOx, GPIO_Pin_TypeDef GPIO_Pin)
 Reads the specified GPIO Output data pin.
void GPIO_ResetBits (GPIO_TypeDef *GPIOx, uint8_t GPIO_Pin)
 Writes low level to the specified GPIO pins.
void GPIO_SetBits (GPIO_TypeDef *GPIOx, uint8_t GPIO_Pin)
 Writes high level to the specified GPIO pins.
void GPIO_ToggleBits (GPIO_TypeDef *GPIOx, uint8_t GPIO_Pin)
 Toggles the specified GPIO pins.
void GPIO_Write (GPIO_TypeDef *GPIOx, uint8_t GPIO_PortVal)
 Writes data to the specified GPIO data port.
void GPIO_WriteBit (GPIO_TypeDef *GPIOx, GPIO_Pin_TypeDef GPIO_Pin, BitAction GPIO_BitVal)
 Sets or clears the selected data port bit.
void I2C_AcknowledgeConfig (I2C_TypeDef *I2Cx, FunctionalState NewState)
 Enable or Disable the I2C acknowledge feature.
void I2C_AckPositionConfig (I2C_TypeDef *I2Cx, I2C_AckPosition_TypeDef I2C_AckPosition)
 Selects the specified I2C Ack position.
void I2C_ARPCmd (I2C_TypeDef *I2Cx, FunctionalState NewState)
 Enables or disables the I2C ARP.
void I2C_CalculatePEC (I2C_TypeDef *I2Cx, FunctionalState NewState)
 Enables or disables PEC calculation.
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.
void I2C_Cmd (I2C_TypeDef *I2Cx, FunctionalState NewState)
 Enables or disables the I2C peripheral.
void I2C_DeInit (I2C_TypeDef *I2Cx)
 Deinitializes the I2C peripheral registers to their default reset values.
void I2C_DMACmd (I2C_TypeDef *I2Cx, FunctionalState NewState)
 Enables or disables the I2C DMA requests .
void I2C_DMALastTransferCmd (I2C_TypeDef *I2Cx, FunctionalState NewState)
 Specifies that the next DMA transfer is the last one .
void I2C_DualAddressCmd (I2C_TypeDef *I2Cx, FunctionalState NewState)
 Enables or disables the specified I2C dual addressing mode.
void I2C_FastModeDutyCycleConfig (I2C_TypeDef *I2Cx, I2C_DutyCycle_TypeDef I2C_DutyCycle)
 Selects I2C fast mode duty cycle.
void I2C_GeneralCallCmd (I2C_TypeDef *I2Cx, FunctionalState NewState)
 Enables or disables the I2C General Call feature.
void I2C_GenerateSTART (I2C_TypeDef *I2Cx, FunctionalState NewState)
 Generates I2C communication START condition.
void I2C_GenerateSTOP (I2C_TypeDef *I2Cx, FunctionalState NewState)
 Generates I2C communication STOP condition.
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.
uint8_t I2C_GetPEC (I2C_TypeDef *I2Cx)
 Returns PEC value.
void I2C_Init (I2C_TypeDef *I2Cx, uint32_t OutputClockFrequency, uint16_t OwnAddress, I2C_Mode_TypeDef I2C_Mode, I2C_DutyCycle_TypeDef I2C_DutyCycle, I2C_Ack_TypeDef I2C_Ack, I2C_AcknowledgedAddress_TypeDef I2C_AcknowledgedAddress)
 Initializes the I2C according to the specified parameters in standard or fast mode.
void I2C_ITConfig (I2C_TypeDef *I2Cx, I2C_IT_TypeDef I2C_IT, FunctionalState NewState)
 Enables or disables the specified I2C interrupt.
void I2C_OwnAddress2Config (I2C_TypeDef *I2Cx, uint8_t Address)
 Configures the specified I2C own address2.
void I2C_PECPositionConfig (I2C_TypeDef *I2Cx, I2C_PECPosition_TypeDef I2C_PECPosition)
 Selects I2C PEC position.
uint8_t I2C_ReadRegister (I2C_TypeDef *I2Cx, I2C_Register_TypeDef I2C_Register)
 Reads the specified I2C register and returns its value.
uint8_t I2C_ReceiveData (I2C_TypeDef *I2Cx)
 Returns the most recent received data.
void I2C_Send7bitAddress (I2C_TypeDef *I2Cx, uint8_t Address, I2C_Direction_TypeDef I2C_Direction)
 Transmits the 7-bit address (to select the) slave device.
void I2C_SendData (I2C_TypeDef *I2Cx, uint8_t Data)
 Send a byte by writing in the DR register.
void I2C_SMBusAlertConfig (I2C_TypeDef *I2Cx, I2C_SMBusAlert_TypeDef I2C_SMBusAlert)
 Drives the SMBusAlert pin high or low.
void I2C_SoftwareResetCmd (I2C_TypeDef *I2Cx, FunctionalState NewState)
 Enables or disables I2C software reset.
void I2C_StretchClockCmd (I2C_TypeDef *I2Cx, FunctionalState NewState)
 Enables or disables the I2C clock stretching.
void I2C_TransmitPEC (I2C_TypeDef *I2Cx, FunctionalState NewState)
 Enables or disables PEC transfer.

Detailed Description

I2C driver modules.


Function Documentation

void GPIO_DeInit ( GPIO_TypeDef GPIOx)

Deinitializes the GPIOx peripheral registers to their default reset values.

Parameters:
GPIOx,:Select the GPIO peripheral number (x = A to I).
Return values:
None

Definition at line 90 of file stm8l15x_gpio.c.

References GPIO_struct::CR1, GPIO_struct::CR2, GPIO_struct::DDR, GPIO_CR1_RESET_VALUE, GPIO_CR2_RESET_VALUE, GPIO_DDR_RESET_VALUE, GPIO_ODR_RESET_VALUE, and GPIO_struct::ODR.

void GPIO_ExternalPullUpConfig ( GPIO_TypeDef GPIOx,
uint8_t  GPIO_Pin,
FunctionalState  NewState 
)

Configures the external pull-up on GPIOx pins.

Parameters:
GPIOx: Select the GPIO peripheral number (x = A to I).
GPIO_Pin: Specifies the pin number This parameter can be one of the following values:
  • GPIO_Pin_0: Pin 0
  • GPIO_Pin_1: Pin 1
  • GPIO_Pin_2: Pin 2
  • GPIO_Pin_3: Pin 3
  • GPIO_Pin_4: Pin 4
  • GPIO_Pin_5: Pin 5
  • GPIO_Pin_6: Pin 6
  • GPIO_Pin_7: Pin 7
NewState: The new state of the pull up pin. Can be ENABLE or DISABLE
Return values:
None

Definition at line 203 of file stm8l15x_gpio.c.

References GPIO_struct::CR1, DISABLE, IS_FUNCTIONAL_STATE, and IS_GPIO_PIN.

void GPIO_Init ( GPIO_TypeDef GPIOx,
uint8_t  GPIO_Pin,
GPIO_Mode_TypeDef  GPIO_Mode 
)

Initializes the GPIOx according to the specified parameters.

Parameters:
GPIOx: Select the GPIO peripheral number (x = A to I).
GPIO_Pin: This parameter contains the pin number This parameter can be one of the following values:
  • GPIO_Pin_0: Pin 0
  • GPIO_Pin_1: Pin 1
  • GPIO_Pin_2: Pin 2
  • GPIO_Pin_3: Pin 3
  • GPIO_Pin_4: Pin 4
  • GPIO_Pin_5: Pin 5
  • GPIO_Pin_6: Pin 6
  • GPIO_Pin_7: Pin 7
GPIO_Mode: This parameter can be a value of the This parameter can be one of the following values:
  • GPIO_Mode_In_FL_No_IT: Input floating, no external interrupt
  • GPIO_Mode_In_PU_No_IT: Input pull-up, no external interrupt
  • GPIO_Mode_In_FL_IT: Input pull-up, external interrupt
  • GPIO_Mode_Out_OD_Low_Fast: Output open-drain, low level, 10MHz
  • GPIO_Mode_Out_PP_Low_Fast: Output push-pull, low level, 10MHz
  • GPIO_Mode_Out_OD_Low_Slow: Output open-drain, low level, 2MHz
  • GPIO_Mode_Out_PP_Low_Slow: Output push-pull, low level, 2MHz
  • GPIO_Mode_Out_OD_HiZ_Fast: Output open-drain, high-impedance level, 10MHz
  • GPIO_Mode_Out_PP_High_Fast: Output push-pull, high level, 10MHz
  • GPIO_Mode_Out_OD_HiZ_Slow: Output open-drain, high-impedance level, 2MHz
  • GPIO_Mode_Out_PP_High_Slow: Output push-pull, high level, 2MHz
Return values:
None

Definition at line 127 of file stm8l15x_gpio.c.

References GPIO_struct::CR1, GPIO_struct::CR2, GPIO_struct::DDR, IS_GPIO_MODE, IS_GPIO_PIN, and GPIO_struct::ODR.

uint8_t GPIO_ReadInputData ( GPIO_TypeDef GPIOx)

Reads the specified GPIO input data port.

Note:
The port must be configured in input mode.
Parameters:
GPIOx: Select the GPIO peripheral number (x = A to I).
Return values:
TheGPIOx input data port value.

Definition at line 341 of file stm8l15x_gpio.c.

References GPIO_struct::IDR.

BitStatus GPIO_ReadInputDataBit ( GPIO_TypeDef GPIOx,
GPIO_Pin_TypeDef  GPIO_Pin 
)

Reads the specified GPIO input data pin.

Parameters:
GPIOx: Select the GPIO peripheral number (x = A to I).
GPIO_Pin: Specifies the pin number. This parameter can be one of the following values:
  • GPIO_Pin_0: Pin 0
  • GPIO_Pin_1: Pin 1
  • GPIO_Pin_2: Pin 2
  • GPIO_Pin_3: Pin 3
  • GPIO_Pin_4: Pin 4
  • GPIO_Pin_5: Pin 5
  • GPIO_Pin_6: Pin 6
  • GPIO_Pin_7: Pin 7
Return values:
BitStatus: GPIO input pin status.

Definition at line 372 of file stm8l15x_gpio.c.

References GPIO_struct::IDR.

uint8_t GPIO_ReadOutputData ( GPIO_TypeDef GPIOx)

Reads the specified GPIO output data port.

Note:
The port must be configured in input mode.
Parameters:
GPIOx: Select the GPIO peripheral number (x = A to I).
Return values:
TheGPIOx output data port value.

Definition at line 352 of file stm8l15x_gpio.c.

References GPIO_struct::ODR.

BitStatus GPIO_ReadOutputDataBit ( GPIO_TypeDef GPIOx,
GPIO_Pin_TypeDef  GPIO_Pin 
)

Reads the specified GPIO Output data pin.

Parameters:
GPIOx: Select the GPIO peripheral number (x = A to I).
GPIO_Pin: Specifies the pin number
Return values:
BitStatus: GPIO output pin status.

Definition at line 383 of file stm8l15x_gpio.c.

References GPIO_struct::ODR.

void GPIO_ResetBits ( GPIO_TypeDef GPIOx,
uint8_t  GPIO_Pin 
)

Writes low level to the specified GPIO pins.

Note:
The port must be configured in output mode.
Parameters:
GPIOx: Select the GPIO peripheral number (x = A to I).
GPIO_Pin: Specifies the pins to be turned low This parameter can be one of the following values:
  • GPIO_Pin_0: Pin 0
  • GPIO_Pin_1: Pin 1
  • GPIO_Pin_2: Pin 2
  • GPIO_Pin_3: Pin 3
  • GPIO_Pin_4: Pin 4
  • GPIO_Pin_5: Pin 5
  • GPIO_Pin_6: Pin 6
  • GPIO_Pin_7: Pin 7
Return values:
None

Definition at line 318 of file stm8l15x_gpio.c.

References GPIO_struct::ODR.

void GPIO_SetBits ( GPIO_TypeDef GPIOx,
uint8_t  GPIO_Pin 
)

Writes high level to the specified GPIO pins.

Note:
The port must be configured in output mode.
Parameters:
GPIOx: Select the GPIO peripheral number (x = A to I).
GPIO_Pin: Specifies the pins to be turned high. This parameter can be one of the following values:
  • GPIO_Pin_0: Pin 0
  • GPIO_Pin_1: Pin 1
  • GPIO_Pin_2: Pin 2
  • GPIO_Pin_3: Pin 3
  • GPIO_Pin_4: Pin 4
  • GPIO_Pin_5: Pin 5
  • GPIO_Pin_6: Pin 6
  • GPIO_Pin_7: Pin 7
Return values:
None

Definition at line 297 of file stm8l15x_gpio.c.

References GPIO_struct::ODR.

void GPIO_ToggleBits ( GPIO_TypeDef GPIOx,
uint8_t  GPIO_Pin 
)

Toggles the specified GPIO pins.

Note:
The port must be configured in output mode.
Parameters:
GPIOx: Select the GPIO peripheral number (x = A to I).
GPIO_Pin: Specifies the pins to be toggled.
Return values:
None

Definition at line 330 of file stm8l15x_gpio.c.

References GPIO_struct::ODR.

void GPIO_Write ( GPIO_TypeDef GPIOx,
uint8_t  GPIO_PortVal 
)

Writes data to the specified GPIO data port.

Note:
The port must be configured in output mode.
Parameters:
GPIOx: Select the GPIO peripheral number (x = A to I).
GPIO_PortVal: Specifies the value to be written to the port output data register.
Return values:
None

Definition at line 242 of file stm8l15x_gpio.c.

References GPIO_struct::ODR.

void GPIO_WriteBit ( GPIO_TypeDef GPIOx,
GPIO_Pin_TypeDef  GPIO_Pin,
BitAction  GPIO_BitVal 
)

Sets or clears the selected data port bit.

Parameters:
GPIOx: Select the GPIO peripheral number (x = A to I).
GPIO_Pin,:Specifies the port bit to be written. This parameter can be one of the following values:
  • GPIO_Pin_0: Pin 0
  • GPIO_Pin_1: Pin 1
  • GPIO_Pin_2: Pin 2
  • GPIO_Pin_3: Pin 3
  • GPIO_Pin_4: Pin 4
  • GPIO_Pin_5: Pin 5
  • GPIO_Pin_6: Pin 6
  • GPIO_Pin_7: Pin 7
GPIO_BitVal,:specifies the desired status to be written. This parameter can be SET or RESET
Return values:
None

Definition at line 264 of file stm8l15x_gpio.c.

References IS_GPIO_PIN, IS_STATE_VALUE, GPIO_struct::ODR, and RESET.

void I2C_AcknowledgeConfig ( I2C_TypeDef I2Cx,
FunctionalState  NewState 
)

Enable or Disable the I2C acknowledge feature.

Parameters:
I2Cx,:where x can be 1 to select the specified I2C peripheral.
NewState,:Specifies the new state of the I2C acknowledge. This parameter can be: ENABLE or DISABLE.
Return values:
None

Definition at line 465 of file stm8l15x_i2c.c.

References I2C_struct::CR2, DISABLE, I2C_CR2_ACK, and IS_FUNCTIONAL_STATE.

void I2C_AckPositionConfig ( I2C_TypeDef I2Cx,
I2C_AckPosition_TypeDef  I2C_AckPosition 
)

Selects the specified I2C Ack position.

Note:
This function must be called before data reception starts.
Parameters:
I2Cx,:where x can be 1 to select the specified I2C peripheral.
I2C_AckPosition,:specifies the Ack position. This parameter can be one of the following values:
  • I2C_AckPosition_Current: Acknowledge on the current byte
  • I2C_AckPosition_Next: Acknowledge on the next byte
Return values:
None

Definition at line 539 of file stm8l15x_i2c.c.

References I2C_struct::CR2, I2C_CR2_POS, and IS_I2C_ACK_POSITION.

void I2C_ARPCmd ( I2C_TypeDef I2Cx,
FunctionalState  NewState 
)

Enables or disables the I2C ARP.

Parameters:
I2Cx,:where x can be 1 to select the specified I2C peripheral.
NewState,:Specifies the new state of the I2C ARP This parameter can be: ENABLE or DISABLE.
Return values:
None

Definition at line 440 of file stm8l15x_i2c.c.

References I2C_struct::CR1, DISABLE, I2C_CR1_ARP, and IS_FUNCTIONAL_STATE.

void I2C_CalculatePEC ( I2C_TypeDef I2Cx,
FunctionalState  NewState 
)

Enables or disables PEC calculation.

Parameters:
I2Cx,:where x can be 1 to select the specified I2C peripheral.
NewState,:indicates the PEC calculation state. This parameter can be: ENABLE or DISABLE.
Return values:
None

Definition at line 723 of file stm8l15x_i2c.c.

References I2C_struct::CR1, DISABLE, I2C_CR1_ENPEC, and IS_FUNCTIONAL_STATE.

ErrorStatus I2C_CheckEvent ( I2C_TypeDef I2Cx,
I2C_Event_TypeDef  I2C_Event 
)

=============================================================================== 1.

================================================================================
                       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() 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() 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.
          
          

Basic state monitoring ===============================================================================

Basic state monitoring =============================================================================== Checks whether the last I2Cx Event is equal to the one passed as parameter.

Parameters:
I2Cx,:where x can be 1 to select the I2C peripheral.
I2C_EVENT,:specifies the event to be checked. This parameter can be one of the following values:
  • I2C_EVENT_SLAVE_TRANSMITTER_ADDRESS_MATCHED: EV1
  • I2C_EVENT_SLAVE_RECEIVER_ADDRESS_MATCHED: EV1
  • I2C_EVENT_SLAVE_GENERALCALLADDRESS_MATCHED: EV1
  • I2C_EVENT_SLAVE_BYTE_RECEIVED: EV2
  • (I2C_EVENT_SLAVE_BYTE_RECEIVED | I2C_FLAG_GENCALL): EV2
  • I2C_EVENT_SLAVE_BYTE_TRANSMITTED: EV3
  • (I2C_EVENT_SLAVE_BYTE_TRANSMITTED | I2C_FLAG_GENCALL): EV3
  • I2C_EVENT_SLAVE_ACK_FAILURE: EV3_2
  • I2C_EVENT_SLAVE_STOP_DETECTED: EV4
  • I2C_EVENT_MASTER_MODE_SELECT: EV5
  • I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED: EV6
  • I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED: EV6
  • I2C_EVENT_MASTER_BYTE_RECEIVED: EV7
  • I2C_EVENT_MASTER_BYTE_TRANSMITTING: EV8
  • I2C_EVENT_MASTER_BYTE_TRANSMITTED: EV8_2
  • I2C_EVENT_MASTER_MODE_ADDRESS10: EV9
Note:
: For detailed description of Events, please refer to section I2C_Events in stm8l15x_i2c.h file.
Return values:
AnErrorStatus enumeration value:
  • SUCCESS: Last event is equal to the I2C_EVENT
  • ERROR: Last event is different from the I2C_EVENT

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.

Parameters:
I2Cx,:where x can be 1 to select the specified I2C peripheral.
I2C_Flag,:Specifies the flag to clear This parameter can be any combination of the following values:
  • I2C_FLAG_SMBALERT: SMBus Alert flag
  • I2C_FLAG_TIMEOUT: Timeout or Tlow error flag
  • I2C_FLAG_PECERR: PEC error in reception flag
  • I2C_FLAG_WUFH: Wakeup from Halt
  • I2C_FLAG_OVR: Overrun/Underrun flag (Slave mode)
  • I2C_FLAG_AF: Acknowledge failure flag
  • I2C_FLAG_ARLO: Arbitration lost flag (Master mode)
  • I2C_FLAG_BERR: Bus error flag.
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()).
Return values:
None

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.

Parameters:
I2Cx,:where x can be 1 to select the specified I2C peripheral.
I2C_IT,:specifies the interrupt pending bit to clear. This parameter can be any combination of the following values:
  • I2C_IT_SMBALERT: SMBus Alert interrupt
  • I2C_IT_TIMEOUT: Timeout or Tlow error interrupt
  • I2C_IT_PECERR: PEC error in reception interrupt
  • I2C_IT_WUFH: Wakeup from Halt
  • I2C_IT_OVR: Overrun/Underrun interrupt (Slave mode)
  • I2C_IT_AF: Acknowledge failure interrupt
  • I2C_IT_ARLO: Arbitration lost interrupt (Master mode)
  • I2C_IT_BERR: Bus error interrupt
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()).
Return values:
None

Definition at line 1334 of file stm8l15x_i2c.c.

References FLAG_Mask, IS_I2C_CLEAR_IT, and I2C_struct::SR2.

void I2C_Cmd ( I2C_TypeDef I2Cx,
FunctionalState  NewState 
)

Enables or disables the I2C peripheral.

Parameters:
I2Cx,:where x can be 1 to select the specified I2C peripheral.
NewState,:Indicate the new I2C peripheral state. This parameter can be: ENABLE or DISABLE.
Return values:
None

Definition at line 289 of file stm8l15x_i2c.c.

References I2C_struct::CR1, DISABLE, I2C_CR1_PE, and IS_FUNCTIONAL_STATE.

void I2C_DeInit ( I2C_TypeDef I2Cx)

Deinitializes the I2C peripheral registers to their default reset values.

Parameters:
I2Cx,:where x can be 1 to select the specified I2C peripheral.
Return values:
None

Definition at line 135 of file stm8l15x_i2c.c.

References I2C_struct::CCRH, I2C_struct::CCRL, I2C_struct::CR1, I2C_struct::CR2, I2C_struct::FREQR, I2C_CCRH_RESET_VALUE, I2C_CCRL_RESET_VALUE, I2C_CR1_RESET_VALUE, I2C_CR2_RESET_VALUE, I2C_FREQR_RESET_VALUE, I2C_ITR_RESET_VALUE, I2C_OAR2_RESET_VALUE, I2C_OARH_RESET_VALUE, I2C_OARL_RESET_VALUE, I2C_TRISER_RESET_VALUE, I2C_struct::ITR, I2C_struct::OAR2, I2C_struct::OARH, I2C_struct::OARL, and I2C_struct::TRISER.

void I2C_DMACmd ( I2C_TypeDef I2Cx,
FunctionalState  NewState 
)

Enables or disables the I2C DMA requests .

Parameters:
I2Cx,:where x can be 1 to select the specified I2C peripheral.
NewState,:Indicate the new I2C DMA state. This parameter can be: ENABLE or DISABLE.
Return values:
None

Definition at line 797 of file stm8l15x_i2c.c.

References DISABLE, I2C_ITR_DMAEN, IS_FUNCTIONAL_STATE, and I2C_struct::ITR.

void I2C_DMALastTransferCmd ( I2C_TypeDef I2Cx,
FunctionalState  NewState 
)

Specifies that the next DMA transfer is the last one .

Parameters:
I2Cx,:where x can be 1 to select the specified I2C peripheral.
NewState,:Indicate the new I2C DMA state. This parameter can be: ENABLE or DISABLE.
Return values:
None

Definition at line 821 of file stm8l15x_i2c.c.

References DISABLE, I2C_ITR_LAST, IS_FUNCTIONAL_STATE, and I2C_struct::ITR.

void I2C_DualAddressCmd ( I2C_TypeDef I2Cx,
FunctionalState  NewState 
)

Enables or disables the specified I2C dual addressing mode.

Parameters:
I2Cx,:where x can be 1 or 2 to select the I2C peripheral.
NewState,:new state of the I2C dual addressing mode. This parameter can be: ENABLE or DISABLE.
Return values:
None

Definition at line 512 of file stm8l15x_i2c.c.

References DISABLE, I2C_OAR2_ENDUAL, IS_FUNCTIONAL_STATE, and I2C_struct::OAR2.

void I2C_FastModeDutyCycleConfig ( I2C_TypeDef I2Cx,
I2C_DutyCycle_TypeDef  I2C_DutyCycle 
)

Selects I2C fast mode duty cycle.

Parameters:
I2Cx,:where x can be 1 to select the specified I2C peripheral.
I2C_DutyCycle,:specifies the fast mode duty cycle. This parameter can be one of the following values:
  • I2C_DutyCycle_2: I2C fast mode Tlow/Thigh = 2
  • I2C_DutyCycle_16_9: I2C fast mode Tlow/Thigh = 16/9
Return values:
None

Definition at line 586 of file stm8l15x_i2c.c.

References I2C_struct::CCRH, I2C_CCRH_DUTY, I2C_DutyCycle_16_9, and IS_I2C_DUTY_CYCLE.

void I2C_GeneralCallCmd ( I2C_TypeDef I2Cx,
FunctionalState  NewState 
)

Enables or disables the I2C General Call feature.

Parameters:
I2Cx,:where x can be 1 to select the specified I2C peripheral.
NewState,:State of the General Call feature. This parameter can be: ENABLE or DISABLE.
Return values:
None

Definition at line 314 of file stm8l15x_i2c.c.

References I2C_struct::CR1, DISABLE, I2C_CR1_ENGC, and IS_FUNCTIONAL_STATE.

void I2C_GenerateSTART ( I2C_TypeDef I2Cx,
FunctionalState  NewState 
)

Generates I2C communication START condition.

Note:
CCR must be programmed, i.e. I2C_Init function must have been called with a valid I2C_ClockSpeed
Parameters:
I2Cx,:where x can be 1 to select the specified I2C peripheral.
NewState,:Enable or disable the start condition. This parameter can be: ENABLE or DISABLE.
Return values:
None

Definition at line 341 of file stm8l15x_i2c.c.

References I2C_struct::CR2, DISABLE, I2C_CR2_START, and IS_FUNCTIONAL_STATE.

void I2C_GenerateSTOP ( I2C_TypeDef I2Cx,
FunctionalState  NewState 
)

Generates I2C communication STOP condition.

Parameters:
I2Cx,:where x can be 1 to select the specified I2C peripheral.
NewState,:Enable or disable the stop condition. This parameter can be: ENABLE or DISABLE.
Return values:
None

Definition at line 366 of file stm8l15x_i2c.c.

References I2C_struct::CR2, DISABLE, I2C_CR2_STOP, and IS_FUNCTIONAL_STATE.

FlagStatus I2C_GetFlagStatus ( I2C_TypeDef I2Cx,
I2C_FLAG_TypeDef  I2C_FLAG 
)

=============================================================================== 3.

Flag-based state monitoring ===============================================================================

Flag-based state monitoring =============================================================================== Checks whether the specified I2C flag is set or not.

Parameters:
I2Cx,:where x can be 1 select the I2C peripheral.
I2C_FLAG,:specifies the flag to check. This parameter can be one of the following values:
  • I2C_FLAG_SMBHOST: SMBus host header (Slave mode)
  • I2C_FLAG_SMBDEFAULT: SMBus default header (Slave mode)
  • I2C_FLAG_GENCALL: General call header flag (Slave mode)
  • I2C_FLAG_TRA: Transmitter/Receiver flag
  • I2C_FLAG_BUSY: Bus busy flag
  • I2C_FLAG_MSL: Master/Slave flag
  • I2C_FLAG_SMBALERT: SMBus Alert flag
  • I2C_FLAG_TIMEOUT: Timeout or Tlow error flag
  • I2C_FLAG_PECERR: PEC error in reception flag
  • I2C_FLAG_OVR: Overrun/Underrun flag (Slave mode)
  • I2C_FLAG_AF: Acknowledge failure flag
  • I2C_FLAG_ARLO: Arbitration lost flag (Master mode)
  • I2C_FLAG_BERR: Bus error flag
  • I2C_FLAG_TXE: Data register empty flag (Transmitter)
  • I2C_FLAG_RXNE: Data register not empty (Receiver) flag
  • I2C_FLAG_STOPF: Stop detection flag (Slave mode)
  • I2C_FLAG_ADD10: 10-bit header sent flag (Master mode)
  • I2C_FLAG_BTF: Byte transfer finished flag
  • I2C_FLAG_ADDR: Address sent flag (Master mode) �ADSL� Address matched flag (Slave mode)�ENDAD�
  • I2C_FLAG_SB: Start bit flag (Master mode)
Return values:
Thenew state of I2C_FLAG (SET or RESET).

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.

Parameters:
I2Cx,:where x can be 1 to select the specified I2C peripheral.
I2C_IT,:specifies the interrupt source to check. This parameter can be one of the following values:
  • I2C_IT_SMBALERT: SMBus Alert interrupt
  • I2C_IT_TIMEOUT: Timeout or Tlow error interrupt
  • I2C_IT_PECERR: PEC error in reception interrupt
  • I2C_IT_WUFH: Wakeup from Halt
  • I2C_IT_OVR: Overrun/Underrun flag (Slave mode)
  • I2C_IT_AF: Acknowledge failure flag
  • I2C_IT_ARLO: Arbitration lost flag (Master mode)
  • I2C_IT_BERR: Bus error flag
  • I2C_IT_TXE: Data register empty flag (Transmitter)
  • I2C_IT_RXNE: Data register not empty (Receiver) flag
  • I2C_IT_STOPF: Stop detection flag (Slave mode)
  • I2C_IT_ADD10: 10-bit header sent flag (Master mode)
  • I2C_IT_BTF: Byte transfer finished flag
  • I2C_IT_ADDR: Address sent flag (Master mode) �ADSL� Address matched flag (Slave mode)�ENDAD�
  • I2C_IT_SB: Start bit flag (Master mode)
Return values:
Thenew state of I2C_IT

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 ===============================================================================

Advanced state monitoring =============================================================================== Returns the last I2C Event.

Parameters:
I2Cx,:where x can be 1 to select the specified I2C peripheral.
Note:
: For detailed description of Events, please refer to section I2C_Events in stm8l15xx_i2c.h file.
Return values:
Thelast event

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.

uint8_t I2C_GetPEC ( I2C_TypeDef I2Cx)

Returns PEC value.

Parameters:
I2Cx,:where x can be 1 to select the specified I2C peripheral.
None
Return values:
Thevalue of the PEC.

Definition at line 766 of file stm8l15x_i2c.c.

References I2C_struct::PECR.

void I2C_Init ( I2C_TypeDef I2Cx,
uint32_t  OutputClockFrequency,
uint16_t  OwnAddress,
I2C_Mode_TypeDef  I2C_Mode,
I2C_DutyCycle_TypeDef  I2C_DutyCycle,
I2C_Ack_TypeDef  I2C_Ack,
I2C_AcknowledgedAddress_TypeDef  I2C_AcknowledgedAddress 
)

Initializes the I2C according to the specified parameters in standard or fast mode.

Parameters:
I2Cx,:where x can be 1 to select the specified I2C peripheral.
OutputClockFrequency,:Specifies the output clock frequency in Hz.
OwnAddress,:Specifies the own address.
I2C_Mode,:Specifies the addressing mode to apply. This parameter can be one of the following values:
  • I2C_Mode_I2C: I2C mode
  • I2C_Mode_SMBusDevice: SMBus Device mode
  • I2C_Mode_SMBusHost: SMBus Host mode
I2C_DutyCycle,:Specifies the duty cycle to apply in fast mode. This parameter can be one of the following values:
  • I2C_DutyCycle_2: I2C fast mode Tlow/Thigh = 2
  • I2C_DutyCycle_16_9: I2C fast mode Tlow/Thigh = 16/9
Note:
The I2C_DutyCycle parameter doesn't have impact when the OutputClockFrequency is lower than 100KHz.
Parameters:
I2C_Ack,:Specifies the acknowledge mode to apply. This parameter can be one of the following values:
  • I2C_Ack_Disable: No acknowledge
  • I2C_Ack_Enable: Acknowledge Enabled
I2C_AcknowledgedAddress,:Specifies the acknowledge address to apply. This parameter can be one of the following values:
  • I2C_AcknowledgedAddress_7bit: 7-bit slave address
  • I2C_AcknowledgedAddress_10bit: 10-bit slave address
Note:
To use the I2C at 400 KHz (in fast mode), the PCLK frequency (I2C peripheral input clock) must be a multiple of 10 MHz.
Return values:
None

Definition at line 178 of file stm8l15x_i2c.c.

References I2C_struct::CCRH, I2C_struct::CCRL, CLK_GetClockFreq(), I2C_struct::CR1, I2C_struct::CR2, I2C_struct::FREQR, I2C_CCRH_CCR, I2C_CCRH_DUTY, I2C_CCRH_FS, I2C_CCRL_CCR, I2C_CR1_PE, I2C_DutyCycle_2, I2C_FREQR_FREQ, I2C_MAX_STANDARD_FREQ, I2C_OARH_ADDCONF, IS_I2C_ACK_STATE, IS_I2C_ACKNOWLEDGE_ADDRESS, IS_I2C_DUTY_CYCLE, IS_I2C_MODE, IS_I2C_OUTPUT_CLOCK_FREQ, IS_I2C_OWN_ADDRESS, I2C_struct::OARH, I2C_struct::OARL, and I2C_struct::TRISER.

void I2C_ITConfig ( I2C_TypeDef I2Cx,
I2C_IT_TypeDef  I2C_IT,
FunctionalState  NewState 
)

Enables or disables the specified I2C interrupt.

Parameters:
I2Cx,:where x can be 1 to select the specified I2C peripheral.
I2C_IT,:specifies the I2C interrupts sources to be enabled or disabled. This parameter can be any combination of the following values:
  • I2C_IT_BUF: Buffer interrupt mask
  • I2C_IT_EVT: Event interrupt mask
  • I2C_IT_ERR: Error interrupt mask
NewState,:State of the interrupt. This parameter can be: ENABLE or DISABLE.
Return values:
None

Definition at line 948 of file stm8l15x_i2c.c.

References DISABLE, IS_FUNCTIONAL_STATE, IS_I2C_CONFIG_IT, and I2C_struct::ITR.

void I2C_OwnAddress2Config ( I2C_TypeDef I2Cx,
uint8_t  Address 
)

Configures the specified I2C own address2.

Parameters:
I2Cx,:where x can be 1 to select the specified I2C peripheral.
Address,:specifies the 7bit I2C own address2.
Return values:
None.

Definition at line 488 of file stm8l15x_i2c.c.

References I2C_OAR2_ADD2, and I2C_struct::OAR2.

void I2C_PECPositionConfig ( I2C_TypeDef I2Cx,
I2C_PECPosition_TypeDef  I2C_PECPosition 
)

Selects I2C PEC position.

Parameters:
I2Cx,:where x can be 1 to select the specified I2C peripheral.
I2C_PECPosition:PECposition. This parameter can be one of the following values:
  • I2C_PECPosition_Current: Current byte in shift register is PEC
  • I2C_PECPosition_Next: Next byte in shift register is PEC
Return values:
None

Definition at line 749 of file stm8l15x_i2c.c.

References I2C_struct::CR2, I2C_CR2_POS, and IS_I2C_PEC_POSITION.

uint8_t I2C_ReadRegister ( I2C_TypeDef I2Cx,
I2C_Register_TypeDef  I2C_Register 
)

Reads the specified I2C register and returns its value.

Parameters:
I2Cx,:where x can be 1 to select the specified I2C peripheral.
I2C_Register,:specifies the register to read. This parameter can be one of the following values:
  • I2C_Register_CR1: CR1 register.
  • I2C_Register_CR2: CR2 register.
  • I2C_Register_FREQR: Frequency register.
  • I2C_Register_OARL: Own address register LSB.
  • I2C_Register_OARH: Own address register MSB
  • I2C_Register_DR: DR register.
  • I2C_Register_SR1: SR1 register.
  • I2C_Register_SR2: SR2 register.
  • I2C_Register_SR3: SR3 register.
  • I2C_Register_ITR: Interrupt and DMA register.
  • I2C_Register_CCRL: Clock control register low.
  • I2C_Register_CCRH: Clock control register high.
  • I2C_Register_TRISER: TRISE register.
  • I2C_Register_PECR: PEC register.
Return values:
Thevalue of the read register.

Definition at line 988 of file stm8l15x_i2c.c.

References __IO, and IS_I2C_REGISTER.

uint8_t I2C_ReceiveData ( I2C_TypeDef I2Cx)

Returns the most recent received data.

Parameters:
I2Cx,:where x can be 1 to select the specified I2C peripheral.
None
Return values:
Thevalue of the received byte data.

Definition at line 670 of file stm8l15x_i2c.c.

References I2C_struct::DR.

void I2C_Send7bitAddress ( I2C_TypeDef I2Cx,
uint8_t  Address,
I2C_Direction_TypeDef  I2C_Direction 
)

Transmits the 7-bit address (to select the) slave device.

Parameters:
I2Cx,:where x can be 1 to select the specified I2C peripheral.
Address,:Specifies the slave address which will be transmitted.
I2C_Direction,:specifies whether the I2C device will be a Transmitter or a Receiver. This parameter can be one of the following values
  • I2C_Direction_Transmitter: Transmitter mode
  • I2C_Direction_Receiver: Receiver mode
Return values:
None

Definition at line 615 of file stm8l15x_i2c.c.

References I2C_struct::DR, I2C_Direction_Transmitter, IS_I2C_ADDRESS, IS_I2C_DIRECTION, OAR1_ADD0_Reset, and OAR1_ADD0_Set.

void I2C_SendData ( I2C_TypeDef I2Cx,
uint8_t  Data 
)

Send a byte by writing in the DR register.

Parameters:
I2Cx,:where x can be 1 to select the specified I2C peripheral.
Data,:Byte to be sent.
Return values:
None

Definition at line 658 of file stm8l15x_i2c.c.

References I2C_struct::DR.

void I2C_SMBusAlertConfig ( I2C_TypeDef I2Cx,
I2C_SMBusAlert_TypeDef  I2C_SMBusAlert 
)

Drives the SMBusAlert pin high or low.

Parameters:
I2Cx,:where x can be 1 to select the specified I2C peripheral.
I2C_SMBusAlert,:SMBusAlert pin state. This parameter can be one of the following values:
  • I2C_SMBusAlert_High: SMBAlert pin high
  • I2C_SMBusAlert_Low: SMBAlert pin Low
Return values:
None

Definition at line 559 of file stm8l15x_i2c.c.

References I2C_struct::CR2, I2C_CR2_ALERT, I2C_SMBusAlert_High, and IS_I2C_SMBUS_ALERT.

void I2C_SoftwareResetCmd ( I2C_TypeDef I2Cx,
FunctionalState  NewState 
)

Enables or disables I2C software reset.

Parameters:
I2Cx,:where x can be 1 to select the specified I2C peripheral.
NewState,:Specifies the new state of the I2C software reset. This parameter can be: ENABLE or DISABLE.
Return values:
None

Definition at line 391 of file stm8l15x_i2c.c.

References I2C_struct::CR2, DISABLE, I2C_CR2_SWRST, and IS_FUNCTIONAL_STATE.

void I2C_StretchClockCmd ( I2C_TypeDef I2Cx,
FunctionalState  NewState 
)

Enables or disables the I2C clock stretching.

Parameters:
I2Cx,:where x can be 1 to select the specified I2C peripheral.
NewState,:Specifies the new state of the I2C Clock stretching. This parameter can be: ENABLE or DISABLE.
Return values:
None

Definition at line 415 of file stm8l15x_i2c.c.

References I2C_struct::CR1, DISABLE, I2C_CR1_NOSTRETCH, and IS_FUNCTIONAL_STATE.

void I2C_TransmitPEC ( I2C_TypeDef I2Cx,
FunctionalState  NewState 
)

Enables or disables PEC transfer.

Parameters:
I2Cx,:where x can be 1 to select the specified I2C peripheral.
NewState,:indicates the PEC transfer state. This parameter can be: ENABLE or DISABLE.
Return values:
None

Definition at line 699 of file stm8l15x_i2c.c.

References I2C_struct::CR2, DISABLE, I2C_CR2_PEC, and IS_FUNCTIONAL_STATE.

STM8S Firmware Library: Overview

 

 

 

For complete documentation on STM8L15x 8-bit microcontrollers platform visit www.st.com