STM8L15x Standard Peripherals Drivers: stm8l15x_i2c.c File Reference

STM8L15x/16x Standard Peripherals Drivers

STM8L15x Standard Peripherals Drivers

stm8l15x_i2c.c File Reference

This file provides firmware functions to manage the following functionalities of the Inter-integrated circuit (I2C)

  • Initialization and Configuration
  • Data transfers
  • PEC management
  • DMA transfers management
  • Interrupts, events and flags management.
More...
#include "stm8l15x_i2c.h" #include "stm8l15x_clk.h"

Go to the source code of this file.

Defines

#define FLAG_Mask   ((uint16_t)0x00FF)
#define ITEN_Mask   ((uint16_t)0x0700)
#define OAR1_ADD0_Reset   ((uint8_t)0xFE)
#define OAR1_ADD0_Set   ((uint8_t)0x01)
#define REGISTER_Mask   ((uint16_t)0x3000)
#define REGISTER_SR1_Index   ((uint16_t)0x0100)
#define REGISTER_SR2_Index   ((uint16_t)0x0200)

Functions

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

This file provides firmware functions to manage the following functionalities of the Inter-integrated circuit (I2C)

  • Initialization and Configuration
  • Data transfers
  • PEC management
  • DMA transfers management
  • Interrupts, events and flags management.
Author:
MCD Application Team
Version:
V1.5.0
Date:
13-May-2011
  *
  *          ===================================================================
  *                                 How to use this driver
  *          ===================================================================
  *          1. Enable peripheral clock using CLK_PeripheralClockConfig(CLK_Peripheral_I2Cx,
  *             ENABLE) function (Refer to the product datasheet for the available I2C
  *           	peripherals)
  *
  *
  *          2. Program the Mode, duty cycle , Own address, Ack, Speed and Acknowledged
  *             Address using the I2C_Init() function.
  *
  *          3. Optionally you can enable/configure the following parameters without
  *             re-initialization (i.e there is no need to call again I2C_Init() function):
  *              - Enable the acknowledge feature using I2C_AcknowledgeConfig() function
  *              - Enable the dual addressing mode using I2C_DualAddressCmd() function
  *              - Enable the general call using the I2C_GeneralCallCmd() function
  *              - Enable the clock stretching using I2C_StretchClockCmd() function
  *              - Enable the fast mode duty cycle using the I2C_FastModeDutyCycleConfig()
  *                function
  *              - Enable the PEC Calculation using I2C_CalculatePEC() function
  *              - For SMBus Mode:
  *                   - Enable the Address Resolution Protocol (ARP) using I2C_ARPCmd() function
  *                   - Configure the SMBusAlert pin using I2C_SMBusAlertConfig() function
  *
  *          4. Enable the interrupt using the function I2C_ITConfig() if you need
  *             to use interrupt mode.
  *
  *          5. When using the DMA mode
  *                   - Configure the DMA using DMA_Init() function
  *                   - Active the needed channel Request using I2C_DMACmd() or
  *                     I2C_DMALastTransferCmd() function
  *              Note: When using DMA mode, I2C interrupts may be used at the same time to
  *                    control the communication flow (Start/Stop/Ack... events and errors).
  *
  *          6. Enable the I2C using the I2C_Cmd() function.
  *
  *          7. Enable the DMA using the DMA_Cmd() function when using DMA mode in the
  *             transfers.
  *
  *         Note: The external Pull-up resistors must be connected on SDA and SCL.
  *
  *  
Attention:

THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.

© COPYRIGHT 2011 STMicroelectronics

Definition in file stm8l15x_i2c.c.

STM8S Firmware Library: Overview

 

 

 

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