STM32F0 CPAL I2C bibliotheek  1.0
ST Microelectronics CPALv2 bibliotheek documentatie
 All Data Structures Files Functions Variables Enumerations Enumerator Macros
stm32f0xx_i2c_cpal.h File Reference

This file contains all the functions prototypes for the I2C firmware layer. More...

#include "stm32f0xx_i2c_cpal_hal.h"
#include "stm32f0xx_i2c_cpal_conf.h"

Go to the source code of this file.

Data Structures

struct  CPAL_TransferTypeDef
 
struct  CPAL_InitTypeDef
 

Macros

#define __STM32F0XX_I2C_CPAL_H
 
#define CPAL_OPT_I2C_DUALADDR   ((uint32_t)0x00000001)
 
#define CPAL_OPT_DMATX_TCIT   ((uint32_t)0x00000100)
 
#define CPAL_OPT_DMATX_HTIT   ((uint32_t)0x00000200)
 
#define CPAL_OPT_DMATX_TEIT   ((uint32_t)0x00000400)
 
#define CPAL_OPT_DMARX_TCIT   ((uint32_t)0x00000800)
 
#define CPAL_OPT_DMARX_HTIT   ((uint32_t)0x00001000)
 
#define CPAL_OPT_DMARX_TEIT   ((uint32_t)0x00002000)
 
#define CPAL_OPT_DMATX_CIRCULAR   ((uint32_t)0x00004000)
 
#define CPAL_OPT_DMARX_CIRCULAR   ((uint32_t)0x00008000)
 
#define CPAL_OPT_NO_MEM_ADDR   ((uint32_t)0x00010000)
 
#define CPAL_OPT_16BIT_REG   ((uint32_t)0x00020000)
 
#define CPAL_OPT_I2C_GENCALL   ((uint32_t)0x00100000)
 
#define CPAL_OPT_I2C_AUTOMATIC_END   ((uint32_t)0x00200000)
 
#define CPAL_OPT_I2C_ERRIT_DISABLE   ((uint32_t)0x00400000)
 
#define CPAL_OPT_I2C_NOSTOP   ((uint32_t)0x00800000)
 
#define CPAL_OPT_I2C_NOSTOP_MODE   ((uint32_t)0x01000000)
 
#define CPAL_OPT_I2C_OA2_MASK   ((uint32_t)0x0E000000)
 
#define CPAL_OPT_I2C_10BIT_HEADR   ((uint32_t)0x10000000)
 
#define CPAL_OPT_I2C_WAKEUP_STOP   ((uint32_t)0x20000000)
 
#define CPAL_OPT_I2C_NACK_ADD   ((uint32_t)0x40000000)
 
#define CPAL_PASS   ((uint32_t)0x00000000)
 
#define CPAL_FAIL   ((uint32_t)0x00000001)
 
#define pNULL   (void*)0
 

Enumerations

enum  CPAL_DevTypeDef { CPAL_I2C1 = 0x00, CPAL_I2C2 = 0x01 }
 
enum  CPAL_DirectionTypeDef { CPAL_DIRECTION_TX = 0x01, CPAL_DIRECTION_RX = 0x02, CPAL_DIRECTION_TXRX = 0x03 }
 
enum  CPAL_ModeTypeDef { CPAL_MODE_MASTER = 0x00, CPAL_MODE_SLAVE = 0x01 }
 
enum  CPAL_ProgModelTypeDef { CPAL_PROGMODEL_INTERRUPT = 0x01, CPAL_PROGMODEL_DMA = 0x02 }
 
enum  CPAL_StateTypeDef {
  CPAL_STATE_DISABLED = 0x00, CPAL_STATE_READY = 0x01, CPAL_STATE_READY_TX = 0x03, CPAL_STATE_READY_RX = 0x05,
  CPAL_STATE_BUSY = 0x02, CPAL_STATE_BUSY_TX = 0x06, CPAL_STATE_BUSY_RX = 0x0A, CPAL_STATE_ERROR = 0x10
}
 
enum  CPAL_I2CErrorTypeDef {
  CPAL_I2C_ERR_NONE = 0x00000000, CPAL_I2C_ERR_TIMEOUT = 0x000000FF, CPAL_I2C_ERR_BERR = 0x00000100, CPAL_I2C_ERR_ARLO = 0x00000200,
  CPAL_I2C_ERR_AF = 0x00000010, CPAL_I2C_ERR_OVR = 0x00000400
}
 

Functions

uint32_t CPAL_I2C_Init (CPAL_InitTypeDef *pDevInitStruct)
 Initialize the peripheral and all related clocks, GPIOs, DMA and Interrupts according to the specified parameters in the CPAL_InitTypeDef structure. More...
 
uint32_t CPAL_I2C_DeInit (CPAL_InitTypeDef *pDevInitStruct)
 Deinitialize the peripheral and all related clocks, GPIOs, DMA and NVIC to their reset values. More...
 
uint32_t CPAL_I2C_StructInit (CPAL_InitTypeDef *pDevInitStruct)
 Initialize the peripheral structure with default values according to the specified parameters in the CPAL_I2CDevTypeDef structure. More...
 
uint32_t CPAL_I2C_Write (CPAL_InitTypeDef *pDevInitStruct)
 Allows to send a data or a buffer of data through the peripheral to a selected device in a selected location address. More...
 
uint32_t CPAL_I2C_Read (CPAL_InitTypeDef *pDevInitStruct)
 Allows to receive a data or a buffer of data through the peripheral from a selected device in a selected location address. More...
 
uint32_t CPAL_I2C_IsDeviceReady (CPAL_InitTypeDef *pDevInitStruct)
 Wait until target device is ready for communication (This function is used with Memory devices). More...
 
uint32_t CPAL_I2C_EV_IRQHandler (CPAL_InitTypeDef *pDevInitStruct)
 This function handles I2C interrupt request for preparing communication and for transfer phase in case of using Interrupt Programming Model. More...
 
uint32_t CPAL_I2C_ER_IRQHandler (CPAL_InitTypeDef *pDevInitStruct)
 Allows to handle errors occurred during initialization or communication in order to recover the correct communication status or call specific user functions. More...
 
uint32_t CPAL_TIMEOUT_UserCallback (CPAL_InitTypeDef *pDevInitStruct)
 
void CPAL_I2C_TX_UserCallback (CPAL_InitTypeDef *pDevInitStruct)
 
void CPAL_I2C_RX_UserCallback (CPAL_InitTypeDef *pDevInitStruct)
 
void CPAL_I2C_TXTC_UserCallback (CPAL_InitTypeDef *pDevInitStruct)
 
void CPAL_I2C_RXTC_UserCallback (CPAL_InitTypeDef *pDevInitStruct)
 
void CPAL_I2C_DMATXTC_UserCallback (CPAL_InitTypeDef *pDevInitStruct)
 
void CPAL_I2C_DMATXHT_UserCallback (CPAL_InitTypeDef *pDevInitStruct)
 
void CPAL_I2C_DMATXTE_UserCallback (CPAL_InitTypeDef *pDevInitStruct)
 
void CPAL_I2C_DMARXTC_UserCallback (CPAL_InitTypeDef *pDevInitStruct)
 
void CPAL_I2C_DMARXHT_UserCallback (CPAL_InitTypeDef *pDevInitStruct)
 
void CPAL_I2C_DMARXTE_UserCallback (CPAL_InitTypeDef *pDevInitStruct)
 
void CPAL_I2C_GENCALL_UserCallback (CPAL_InitTypeDef *pDevInitStruct)
 
void CPAL_I2C_DUALF_UserCallback (CPAL_InitTypeDef *pDevInitStruct)
 

Variables

CPAL_InitTypeDefI2C_DevStructures []
 

Detailed Description

This file contains all the functions prototypes for the I2C firmware layer.

Author
MCD Application Team
Version
V1.0.0
Date
20-April-2012
Attention

© COPYRIGHT 2012 STMicroelectronics

Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); You may not use this file except in compliance with the License. You may obtain a copy of the License at:

   http://www.st.com/software_license_agreement_liberty_v2

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Macro Definition Documentation

#define CPAL_FAIL   ((uint32_t)0x00000001)

This value is returned if the last operation failed

#define CPAL_OPT_16BIT_REG   ((uint32_t)0x00020000)

Enable 16-Bit Register/Physical addressing mode (two bytes, MSB first). This option is supported only when CPAL_OPT_NO_MEM_ADDR option is not set

#define CPAL_OPT_DMARX_CIRCULAR   ((uint32_t)0x00008000)

Enable the Circular Mode for DMA Receiver

#define CPAL_OPT_DMARX_HTIT   ((uint32_t)0x00001000)

Enable the Receiver DMA Half Transfer Complete interrupt

#define CPAL_OPT_DMARX_TCIT   ((uint32_t)0x00000800)

Enable the Receiver DMA Transfer Complete interrupt

#define CPAL_OPT_DMARX_TEIT   ((uint32_t)0x00002000)

Enable the Receiver DMA Half Transfer Error interrupt

#define CPAL_OPT_DMATX_CIRCULAR   ((uint32_t)0x00004000)

Enable the Circular Mode for DMA Transmitter

#define CPAL_OPT_DMATX_HTIT   ((uint32_t)0x00000200)

Enable the Transmitter DMA Half Transfer Complete interrupt

#define CPAL_OPT_DMATX_TCIT   ((uint32_t)0x00000100)

Enable the Transmitter DMA Transfer Complete interrupt

#define CPAL_OPT_DMATX_TEIT   ((uint32_t)0x00000400)

Enable the Transmitter DMA Transfer Error interrupt

#define CPAL_OPT_I2C_10BIT_HEADR   ((uint32_t)0x10000000)

Enable the send of slave address-10bit-header only when switching from master transmitter to master receiver mode with No stop generation option enabled

#define CPAL_OPT_I2C_AUTOMATIC_END   ((uint32_t)0x00200000)

Enable Automatic end mode for master

#define CPAL_OPT_I2C_DUALADDR   ((uint32_t)0x00000001)

Use Dual Address Mode (available in Slave Mode only). To use this option enable it by affecting this define and own address2 to wCPAL_Options

#define CPAL_OPT_I2C_ERRIT_DISABLE   ((uint32_t)0x00400000)

Disable I2C Errors interrupt (Bus Error, Arbitration Loss, Acknowledge Failure and Overrun/Underrun Errors). By default, errors interrupt is enabled to manage errors efficiently

#define CPAL_OPT_I2C_GENCALL   ((uint32_t)0x00100000)

Use General Call Address Mode (available in Slave Mode only) (General Call Address = 0x00)

#define CPAL_OPT_I2C_NACK_ADD   ((uint32_t)0x40000000)

Initialize the I2C Slave device without enabling the acknowledgement of its own address. This option must not be used with No Stop generation mode

#define CPAL_OPT_I2C_NOSTOP   ((uint32_t)0x00800000)

Use communication mode with no STOP generation at the end of data transfer (for multi-read/write operations)

#define CPAL_OPT_I2C_NOSTOP_MODE   ((uint32_t)0x01000000)

Start communication in No STOP generation mode and close communication by Generating stop

#define CPAL_OPT_I2C_OA2_MASK   ((uint32_t)0x0E000000)

Contain Own Address 2 Mask (OA2MSK is coded on 3 bit)

#define CPAL_OPT_I2C_WAKEUP_STOP   ((uint32_t)0x20000000)

Enable the WakeUp from stop capability for the I2C slave device

#define CPAL_OPT_NO_MEM_ADDR   ((uint32_t)0x00010000)

Enable No Memory addressing mode: only slave device address sent No Register/Physical address to be sent after slave address

#define CPAL_PASS   ((uint32_t)0x00000000)

This value is returned if the last operation succeed

#define pNULL   (void*)0

This Value is used to initialise a null pointer

Enumeration Type Documentation

Enumerator
CPAL_I2C1 

Use I2C1 device

CPAL_I2C2 

Use I2C2 device

Enumerator
CPAL_DIRECTION_TX 

Transmitter only direction

CPAL_DIRECTION_RX 

Receiver only direction

CPAL_DIRECTION_TXRX 

Transmitter and Receiver direction

Enumerator
CPAL_I2C_ERR_NONE 

No Error: This is the default state for an Idle peripheral

CPAL_I2C_ERR_TIMEOUT 

Timeout error: The specified timeout has been elapsed without any response (expected flag or data didn't happen at expected time).

CPAL_I2C_ERR_BERR 

A bus error is detected when a START or a STOP condition is detected and is not located after a multiple of 9 SCL clock pulses. The bus error flag is set only in case the I2C is involved in the transfer as master or addressed slave. In case of a misplaced START or ReSTART detection, the I2C enters address recognition state as for a correct START condition. When a bus error is detected, BERR flag is set in I2C_ISR register, and an interrupt is generated if ERRIE is set in I2C_CR1 register.

CPAL_I2C_ERR_ARLO 

An arbitration loss is detected when a high level is sent on SDA, but a low level is sampled on the SCL rising edge. ? In master mode, the arbitration loss is detected during address phase, data phase and data acknowledge phase. In that case, SDA and SCL lines are released, START control bit is cleared by hardware and the master switches automatically to slave mode. ? In slave mode, arbitration loss is detected during data phase and data acknowledge phase. In that case, the transmission is stopped, and SCL and SDA lines are released. When an arbitration loss is detected, ARLO flag is set in I2C_ISR register, and an interrupt is generated if ERRIE is set in I2C_CR1 register.

CPAL_I2C_ERR_AF 

Acknowledge Failure : NACK is considered as error only when this event is set in master mode. ? If Master: a Stop or repeated Start condition must be generated by software. When a NACK is detected, NACKF flag is set in I2C_ISR register, and an interrupt is generated if NACKIE is set in I2C_CR1 register.

CPAL_I2C_ERR_OVR 

An overrun or underrun error is detected in slave mode when NOSTRETCH=1 and: ? In reception when a new byte is received and the RXDR register has not been read yet New received byte is lost, and a NACK is automatically sent as a response to the new byte. ? In transmission : when STOPF=1 and the first data should be sent. The content of TXDATA is sent. when a new byte should be sent and the TXDR register has not been written yet. The content of TXDATA is sent (same byte is sent twice) When an overrun or underrun error is detected, OVR flag is set in I2C_ISR register, and an interrupt is generated if ERRIE is set in I2C_CR1 register.

Enumerator
CPAL_MODE_MASTER 

Use device as master

CPAL_MODE_SLAVE 

Use device as slave

Enumerator
CPAL_PROGMODEL_INTERRUPT 

Interrupt transfer programming model

CPAL_PROGMODEL_DMA 

DMA transfer programming model

Enumerator
CPAL_STATE_DISABLED 

The Disabled state indicates that the device is not configured.

CPAL_STATE_READY 

The Ready state indicates that the device is configured correctly and is ready for read or write operation and/or the last transaction has been successfully completed

CPAL_STATE_READY_TX 

The Ready_TX state indicates that the device is ready for transmission operation

CPAL_STATE_READY_RX 

The Ready_RX state indicates that the device is ready for reception operation

CPAL_STATE_BUSY 

The Busy state indicates that a Write or Read operation started

CPAL_STATE_BUSY_TX 

The Busy_TX state indicates that a transmission operation is on going

CPAL_STATE_BUSY_RX 

The Busy_RX state indicates that a reception operation is on going

CPAL_STATE_ERROR 

The Error state indicates that the last operation failed. To determine which error caused the failure, read the device status structure.

Function Documentation

uint32_t CPAL_I2C_DeInit ( CPAL_InitTypeDef pDevInitStruct)

Deinitialize the peripheral and all related clocks, GPIOs, DMA and NVIC to their reset values.

Parameters
pDevInitStruct,:Pointer to the peripheral configuration structure.
Return values
CPAL_PASSor CPAL_FAIL
Note
The Peripheral clock is disabled but the GPIO Ports clocks remains enabled after this deinitialization.
uint32_t CPAL_I2C_ER_IRQHandler ( CPAL_InitTypeDef pDevInitStruct)

Allows to handle errors occurred during initialization or communication in order to recover the correct communication status or call specific user functions.

Parameters
pDevInitStruct,:Pointer to the peripheral configuration structure.
Return values
CPAL_PASS.
uint32_t CPAL_I2C_EV_IRQHandler ( CPAL_InitTypeDef pDevInitStruct)

This function handles I2C interrupt request for preparing communication and for transfer phase in case of using Interrupt Programming Model.

Parameters
pDevInitStruct,:Pointer to the peripheral configuration structure.
Return values
CPAL_PASS.
uint32_t CPAL_I2C_Init ( CPAL_InitTypeDef pDevInitStruct)

Initialize the peripheral and all related clocks, GPIOs, DMA and Interrupts according to the specified parameters in the CPAL_InitTypeDef structure.

Parameters
pDevInitStruct: Pointer to the peripheral configuration structure.
Return values
CPAL_PASSor CPAL_FAIL
uint32_t CPAL_I2C_IsDeviceReady ( CPAL_InitTypeDef pDevInitStruct)

Wait until target device is ready for communication (This function is used with Memory devices).

Parameters
pDevInitStruct,:Pointer to the peripheral configuration structure.
Return values
CPAL_PASSor CPAL_FAIL.
uint32_t CPAL_I2C_Read ( CPAL_InitTypeDef pDevInitStruct)

Allows to receive a data or a buffer of data through the peripheral from a selected device in a selected location address.

Parameters
pDevInitStruct,:Pointer to the peripheral configuration structure.
Return values
CPAL_PASSor CPAL_FAIL.
uint32_t CPAL_I2C_StructInit ( CPAL_InitTypeDef pDevInitStruct)

Initialize the peripheral structure with default values according to the specified parameters in the CPAL_I2CDevTypeDef structure.

Parameters
pDevInitStruct,:Pointer to the peripheral configuration structure.
Return values
CPAL_PASSor CPAL_FAIL.
uint32_t CPAL_I2C_Write ( CPAL_InitTypeDef pDevInitStruct)

Allows to send a data or a buffer of data through the peripheral to a selected device in a selected location address.

Parameters
pDevInitStruct,:Pointer to the peripheral configuration structure.
Return values
CPAL_PASSor CPAL_FAIL.