📄 i2c.h
字号:
/******************************************************************************
COPYRIGHT 2001 STMicroelectronics
Source File Name : I2C.h
Group : IPSW,CMG-IPDF
Author : MCD Application Team
Date First Issued: 04/03/2002
********************************Documentation**********************************
General Purpose - Contains prototypes for all the functions of I2C
********************************Revision History*******************************
_______________________________________________________________________________
Date :04/03/2002 Release:1.0
******************************************************************************/
#ifndef I2C_H
#define I2C_H
#include "ST7lib_config.h"
/*----------------------------------ENUMS------------------------------------*/
/* Parameters for initialisation of I2C control register */
typedef enum {
I2C_DEFAULT_PARAM1 = (unsigned char) 0x00,
I2C_ENABLE_ACK = (unsigned char) 0x04,
I2C_IT_ENABLE = (unsigned char) 0x01
}I2C_InitParam;
/* Parameters for configuring I2C in transmitter/ receiver mode */
typedef enum {
I2C_TX_MODE = (unsigned char) 0x00,
I2C_RX_MODE = (unsigned char) 0x01,
I2C_SUB_ADD = (unsigned char) 0x20
}I2C_Mode;
/* Parameters for selecting the speed mode */
typedef enum {
I2C_DEFAULT_PARAM2 = (unsigned char) 0x00,
I2C_FASTSPEED = (unsigned char) 0x80
}I2C_SpeedParam;
/* Transmission status parameters */
typedef enum {
I2C_TX_BUFFER_ONGOING = (unsigned char) 0xFF,
I2C_TX_STRING_ONGOING = (unsigned char) 0xFE,
I2C_HEADERADD_TX_OK = (unsigned char) 0x40,
I2C_TX_AF = (unsigned char) 0x10,
I2C_START_OK = (unsigned char) 0x08,
I2C_TX_ARLO = (unsigned char) 0x04,
I2C_TX_BERR = (unsigned char) 0x02,
I2C_ADD_TX_OK = (unsigned char) 0x01,
I2C_DATA_TX_OK = (unsigned char) 0x00
}I2C_TxErrCode_t;
/* Reception status parameters */
typedef enum {
I2C_RX_BUFFER_ONGOING = (unsigned char) 0xFF,
I2C_RX_DATA_EMPTY = (unsigned char) 0xFE,
I2C_RX_BERR = (unsigned char) 0x02,
I2C_RX_ARLO = (unsigned char) 0x04,
I2C_RX_AF = (unsigned char) 0x10,
I2C_DATA_RX_OK = (unsigned char) 0x00
}I2C_RxErrCode_t;
/* Parameters for enabling or disabling ACK bit */
typedef enum {
I2C_ACK_ENABLE = (unsigned char) 0x04,
I2C_ACK_DISABLE = (unsigned char) 0x00
}I2C_ACK_Param;
/*---------------------------------MACROS------------------------------------*/
#define I2C_Generate_Start() (I2CCR |= 0x08) /* Generate start condition */
#define I2C_Peripheral_Disable() (I2CCR &= 0x1F) /* Disables I2C */
/*-----------------------------FUNCTION PROTOTYPES---------------------------*/
/* Description of all the functions defined in this module */
void I2C_Init (I2C_InitParam Init_Value) ; /* Initialise I2C */
#if (defined I2C_72F521 || defined I2C_72F63 || defined I2C_72F264)
void I2C_MultiMaster_Config (void);
/* Configure I2C as multimaster I2C device */
#endif
/* RBuider can override this function by adding #define REM_I2C_SELECT_SPEED */
#ifndef REM_I2C_SELECT_SPEED
void I2C_Select_Speed (I2C_SpeedParam Speed_Value, unsigned int I2C_Speed);
/* Selects the I2C clock speed both in standard and fast speed mode */
#endif /* REM_I2C_SELECT_SPEED */
void I2C_Load_Address (unsigned char Addr_Byte, I2C_Mode Mode_Value);
/* Transmits slave address */
void I2C_PutByte (unsigned char Tx_Data); /* Transmits single byte of data */
I2C_TxErrCode_t I2C_IsTransmitCompleted (void); /* Checks error and pending
request status in transmission and return the status */
unsigned char I2C_GetByte (void); /* Returns the received single data byte */
I2C_RxErrCode_t I2C_IsReceptionCompleted (void);
/* Checks the reception status and returns it */
void I2C_Error_Clear (void); /* Clears all error flags */
void I2C_Generate_Stop (void); /* Generate stop condition */
BOOL I2C_IsStopGen (void) ; /* Checks if STOP condition is successful */
void I2C_ACK (I2C_ACK_Param ACK_Value);
/* Enables or disables acknowledge bit */
void I2C_Generate_9Stops (void);
/*Generate 9 consecutive stop bits to re-synchronize I2C bus */
void I2C_IT_Function (void); /* I2C interrupt service function for
communication in interrupt driven without buffer mode */
#ifdef I2C_POLLING_TX
I2C_TxErrCode_t I2C_PutString (const unsigned char *PtrToString);
/* Transmits data string for
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -