49 #define CR1_PE_Set ((uint16_t)0x0001) 50 #define CR1_PE_Reset ((uint16_t)0xFFFE) 53 #define CR1_START_Set ((uint16_t)0x0100) 54 #define CR1_START_Reset ((uint16_t)0xFEFF) 57 #define CR1_STOP_Set ((uint16_t)0x0200) 58 #define CR1_STOP_Reset ((uint16_t)0xFDFF) 61 #define CR1_ACK_Set ((uint16_t)0x0400) 62 #define CR1_ACK_Reset ((uint16_t)0xFBFF) 65 #define CR1_ENGC_Set ((uint16_t)0x0040) 66 #define CR1_ENGC_Reset ((uint16_t)0xFFBF) 69 #define CR1_SWRST_Set ((uint16_t)0x8000) 70 #define CR1_SWRST_Reset ((uint16_t)0x7FFF) 73 #define CR1_PEC_Set ((uint16_t)0x1000) 74 #define CR1_PEC_Reset ((uint16_t)0xEFFF) 77 #define CR1_ENPEC_Set ((uint16_t)0x0020) 78 #define CR1_ENPEC_Reset ((uint16_t)0xFFDF) 81 #define CR1_ENARP_Set ((uint16_t)0x0010) 82 #define CR1_ENARP_Reset ((uint16_t)0xFFEF) 85 #define CR1_NOSTRETCH_Set ((uint16_t)0x0080) 86 #define CR1_NOSTRETCH_Reset ((uint16_t)0xFF7F) 89 #define CR1_CLEAR_Mask ((uint16_t)0xFBF5) 92 #define CR2_DMAEN_Set ((uint16_t)0x0800) 93 #define CR2_DMAEN_Reset ((uint16_t)0xF7FF) 96 #define CR2_LAST_Set ((uint16_t)0x1000) 97 #define CR2_LAST_Reset ((uint16_t)0xEFFF) 100 #define CR2_FREQ_Reset ((uint16_t)0xFFC0) 103 #define OAR1_ADD0_Set ((uint16_t)0x0001) 104 #define OAR1_ADD0_Reset ((uint16_t)0xFFFE) 107 #define OAR2_ENDUAL_Set ((uint16_t)0x0001) 108 #define OAR2_ENDUAL_Reset ((uint16_t)0xFFFE) 111 #define OAR2_ADD2_Reset ((uint16_t)0xFF01) 114 #define CCR_FS_Set ((uint16_t)0x8000) 117 #define CCR_CCR_Set ((uint16_t)0x0FFF) 120 #define FLAG_Mask ((uint32_t)0x00FFFFFF) 123 #define ITEN_Mask ((uint32_t)0x07000000) 193 uint16_t tmpreg = 0, freqrange = 0;
194 uint16_t result = 0x04;
195 uint32_t pclk1 = 8000000;
215 freqrange = (uint16_t)(pclk1 / 1000000);
231 result = (uint16_t)(pclk1 / (I2C_InitStruct->
I2C_ClockSpeed << 1));
241 I2Cx->
TRISE = freqrange + 1;
249 result = (uint16_t)(pclk1 / (I2C_InitStruct->
I2C_ClockSpeed * 3));
254 result = (uint16_t)(pclk1 / (I2C_InitStruct->
I2C_ClockSpeed * 25));
263 result |= (uint16_t)0x0001;
268 I2Cx->
TRISE = (uint16_t)(((freqrange * (uint16_t)300) / (uint16_t)1000) + (uint16_t)1);
284 tmpreg |= (uint16_t)((uint32_t)I2C_InitStruct->
I2C_Mode | I2C_InitStruct->
I2C_Ack);
479 tmpreg |= (uint16_t)((uint16_t)Address & (uint16_t)0x00FE);
560 I2Cx->
CR2 &= (uint16_t)~I2C_IT;
588 return (uint8_t)I2Cx->
DR;
638 __IO uint32_t tmp = 0;
644 tmp = (uint32_t) I2Cx;
648 return (*(
__IO uint16_t *) tmp);
830 return ((I2Cx->
SR2) >> 8);
1032 uint32_t lastevent = 0;
1033 uint32_t flag1 = 0, flag2 = 0;
1043 flag2 = flag2 << 16;
1046 lastevent = (flag1 | flag2) &
FLAG_Mask;
1049 if ((lastevent & I2C_EVENT) == I2C_EVENT)
1080 uint32_t lastevent = 0;
1081 uint32_t flag1 = 0, flag2 = 0;
1089 flag2 = flag2 << 16;
1092 lastevent = (flag1 | flag2) &
FLAG_Mask;
1136 __IO uint32_t i2creg = 0, i2cxbase = 0;
1143 i2cxbase = (uint32_t)I2Cx;
1146 i2creg = I2C_FLAG >> 28;
1159 I2C_FLAG = (uint32_t)(I2C_FLAG >> 16);
1164 if(((*(
__IO uint32_t *)i2cxbase) & I2C_FLAG) != (uint32_t)
RESET)
1214 uint32_t flagpos = 0;
1221 I2Cx->
SR1 = (uint16_t)~flagpos;
1249 uint32_t enablestatus = 0;
1256 enablestatus = (uint32_t)(((I2C_IT &
ITEN_Mask) >> 16) & (I2Cx->
CR2)) ;
1262 if (((I2Cx->
SR1 & I2C_IT) != (uint32_t)
RESET) && enablestatus)
1309 uint32_t flagpos = 0;
1316 I2Cx->
SR1 = (uint16_t)~flagpos;
void I2C_FastModeDutyCycleConfig(I2C_TypeDef *I2Cx, uint16_t I2C_DutyCycle)
Selects the specified I2C fast mode duty cycle.
#define IS_I2C_CLEAR_FLAG(FLAG)
void I2C_Init(I2C_TypeDef *I2Cx, I2C_InitTypeDef *I2C_InitStruct)
Initializes the I2Cx peripheral according to the specified parameters in the I2C_InitStruct.
#define CR1_NOSTRETCH_Reset
void I2C_DeInit(I2C_TypeDef *I2Cx)
Deinitializes the I2Cx peripheral registers to their default reset values.
#define IS_I2C_CONFIG_IT(IT)
#define IS_I2C_EVENT(EVENT)
#define RCC_APB1Periph_I2C1
#define CR1_NOSTRETCH_Set
uint16_t I2C_AcknowledgedAddress
void I2C_ARPCmd(I2C_TypeDef *I2Cx, FunctionalState NewState)
Enables or disables the specified I2C ARP.
#define IS_I2C_REGISTER(REGISTER)
void I2C_DMALastTransferCmd(I2C_TypeDef *I2Cx, FunctionalState NewState)
Specifies if the next DMA transfer will be the last one.
#define IS_I2C_SMBUS_ALERT(ALERT)
#define I2C_DutyCycle_16_9
#define IS_I2C_NACK_POSITION(POSITION)
#define IS_I2C_PEC_POSITION(POSITION)
void assert_param(int val)
static I2C_TypeDef * I2Cx
void I2C_AcknowledgeConfig(I2C_TypeDef *I2Cx, FunctionalState NewState)
Enables or disables the specified I2C acknowledge feature.
#define IS_FUNCTIONAL_STATE(STATE)
void I2C_NACKPositionConfig(I2C_TypeDef *I2Cx, uint16_t I2C_NACKPosition)
Selects the specified I2C NACK position in master receiver mode. This function is useful in I2C Maste...
static volatile uint8_t * status
void I2C_TransmitPEC(I2C_TypeDef *I2Cx, FunctionalState NewState)
Enables or disables the specified I2C PEC transfer.
#define I2C_Direction_Transmitter
void I2C_SendData(I2C_TypeDef *I2Cx, uint8_t Data)
Sends a data byte through the I2Cx peripheral.
#define I2C_NACKPosition_Next
#define I2C_AcknowledgedAddress_7bit
ErrorStatus I2C_CheckEvent(I2C_TypeDef *I2Cx, uint32_t I2C_EVENT)
I2C State Monitoring Functions.
FlagStatus I2C_GetFlagStatus(I2C_TypeDef *I2Cx, uint32_t I2C_FLAG)
Checks whether the specified I2C flag is set or not.
#define IS_I2C_ACK_STATE(STATE)
#define I2C_PECPosition_Next
void I2C_ClearFlag(I2C_TypeDef *I2Cx, uint32_t I2C_FLAG)
Clears the I2Cx's pending flags.
#define I2C_SMBusAlert_Low
void RCC_APB1PeriphResetCmd(uint32_t RCC_APB1Periph, FunctionalState NewState)
Forces or releases Low Speed APB (APB1) peripheral reset.
void I2C_Cmd(I2C_TypeDef *I2Cx, FunctionalState NewState)
Enables or disables the specified I2C peripheral.
ITStatus I2C_GetITStatus(I2C_TypeDef *I2Cx, uint32_t I2C_IT)
Checks whether the specified I2C interrupt has occurred or not.
void I2C_SMBusAlertConfig(I2C_TypeDef *I2Cx, uint16_t I2C_SMBusAlert)
Drives the SMBusAlert pin high or low for the specified I2C.
uint8_t I2C_ReceiveData(I2C_TypeDef *I2Cx)
Returns the most recent received data by the I2Cx peripheral.
#define IS_I2C_OWN_ADDRESS1(ADDRESS1)
#define IS_I2C_MODE(MODE)
#define IS_I2C_DIRECTION(DIRECTION)
void I2C_GenerateSTART(I2C_TypeDef *I2Cx, FunctionalState NewState)
Generates I2Cx communication START condition.
#define I2C_SMBusAlert_High
This file contains all the functions prototypes for the RCC firmware library.
void I2C_ClearITPendingBit(I2C_TypeDef *I2Cx, uint32_t I2C_IT)
Clears the I2Cx’s interrupt pending bits.
void I2C_OwnAddress2Config(I2C_TypeDef *I2Cx, uint8_t Address)
Configures the specified I2C own address2.
I2C Init structure definition.
uint8_t I2C_GetPEC(I2C_TypeDef *I2Cx)
Returns the PEC value for the specified I2C.
void I2C_DMACmd(I2C_TypeDef *I2Cx, FunctionalState NewState)
Enables or disables the specified I2C DMA requests.
void I2C_DualAddressCmd(I2C_TypeDef *I2Cx, FunctionalState NewState)
Enables or disables the specified I2C dual addressing mode.
#define OAR2_ENDUAL_Reset
#define IS_I2C_GET_IT(IT)
#define IS_I2C_CLEAR_IT(IT)
#define IS_I2C_ACKNOWLEDGE_ADDRESS(ADDRESS)
void I2C_GenerateSTOP(I2C_TypeDef *I2Cx, FunctionalState NewState)
Generates I2Cx communication STOP condition.
#define I2C_NACKPosition_Current
#define IS_I2C_CLOCK_SPEED(SPEED)
#define IS_I2C_GET_FLAG(FLAG)
Inter-integrated Circuit Interface.
void RCC_GetClocksFreq(RCC_ClocksTypeDef *RCC_Clocks)
Returns the frequencies of different on chip clocks; SYSCLK, HCLK, PCLK1 and PCLK2.
#define I2C_PECPosition_Current
void I2C_PECPositionConfig(I2C_TypeDef *I2Cx, uint16_t I2C_PECPosition)
Selects the specified I2C PEC position.
This file contains all the functions prototypes for the I2C firmware library.
void I2C_Send7bitAddress(I2C_TypeDef *I2Cx, uint8_t Address, uint8_t I2C_Direction)
Transmits the address byte to select the slave device.
void I2C_StretchClockCmd(I2C_TypeDef *I2Cx, FunctionalState NewState)
Enables or disables the specified I2C Clock stretching.
void I2C_SoftwareResetCmd(I2C_TypeDef *I2Cx, FunctionalState NewState)
Enables or disables the specified I2C software reset.
void I2C_CalculatePEC(I2C_TypeDef *I2Cx, FunctionalState NewState)
Enables or disables the PEC value calculation of the transferred bytes.
#define IS_I2C_DUTY_CYCLE(CYCLE)
uint32_t I2C_GetLastEvent(I2C_TypeDef *I2Cx)
Returns the last I2Cx Event.
void I2C_ITConfig(I2C_TypeDef *I2Cx, uint16_t I2C_IT, FunctionalState NewState)
Enables or disables the specified I2C interrupts.
#define RCC_APB1Periph_I2C2
void I2C_StructInit(I2C_InitTypeDef *I2C_InitStruct)
Fills each I2C_InitStruct member with its default value.
uint16_t I2C_ReadRegister(I2C_TypeDef *I2Cx, uint8_t I2C_Register)
Reads the specified I2C register and returns its value.
void I2C_GeneralCallCmd(I2C_TypeDef *I2Cx, FunctionalState NewState)
Enables or disables the specified I2C general call feature.
#define IS_I2C_ALL_PERIPH(PERIPH)