93 #include "stm32f4xx_rcc.h" 107 #define CR1_CLEAR_MASK ((uint16_t)0xFBF5) 108 #define FLAG_MASK ((uint32_t)0x00FFFFFF) 109 #define ITEN_MASK ((uint32_t)0x07000000) 149 else if (I2Cx ==
I2C2)
182 uint16_t tmpreg = 0, freqrange = 0;
183 uint16_t result = 0x04;
184 uint32_t pclk1 = 8000000;
204 freqrange = (uint16_t)(pclk1 / 1000000);
220 result = (uint16_t)(pclk1 / (I2C_InitStruct->
I2C_ClockSpeed << 1));
230 I2Cx->
TRISE = freqrange + 1;
240 result = (uint16_t)(pclk1 / (I2C_InitStruct->
I2C_ClockSpeed * 3));
245 result = (uint16_t)(pclk1 / (I2C_InitStruct->
I2C_ClockSpeed * 25));
254 result |= (uint16_t)0x0001;
259 I2Cx->
TRISE = (uint16_t)(((freqrange * (uint16_t)300) / (uint16_t)1000) + (uint16_t)1);
275 tmpreg |= (uint16_t)((uint32_t)I2C_InitStruct->
I2C_Mode | I2C_InitStruct->
I2C_Ack);
380 tmpreg |= (uint16_t)((uint16_t)I2C_DigitalFilter &
I2C_FLTR_DNF);
509 tmpreg |= (uint16_t)((uint16_t)Address & (uint16_t)0x00FE);
768 return (uint8_t)I2Cx->
DR;
876 return ((I2Cx->
SR2) >> 8);
1068 __IO uint32_t tmp = 0;
1074 tmp = (uint32_t) I2Cx;
1075 tmp += I2C_Register;
1078 return (*(
__IO uint16_t *) tmp);
1103 I2Cx->
CR2 |= I2C_IT;
1108 I2Cx->
CR2 &= (uint16_t)~I2C_IT;
1154 uint32_t lastevent = 0;
1155 uint32_t flag1 = 0, flag2 = 0;
1165 flag2 = flag2 << 16;
1168 lastevent = (flag1 | flag2) &
FLAG_MASK;
1171 if ((lastevent & I2C_EVENT) == I2C_EVENT)
1202 uint32_t lastevent = 0;
1203 uint32_t flag1 = 0, flag2 = 0;
1211 flag2 = flag2 << 16;
1214 lastevent = (flag1 | flag2) &
FLAG_MASK;
1258 __IO uint32_t i2creg = 0, i2cxbase = 0;
1265 i2cxbase = (uint32_t)I2Cx;
1268 i2creg = I2C_FLAG >> 28;
1281 I2C_FLAG = (uint32_t)(I2C_FLAG >> 16);
1286 if(((*(
__IO uint32_t *)i2cxbase) & I2C_FLAG) != (uint32_t)
RESET)
1334 uint32_t flagpos = 0;
1341 I2Cx->
SR1 = (uint16_t)~flagpos;
1369 uint32_t enablestatus = 0;
1376 enablestatus = (uint32_t)(((I2C_IT &
ITEN_MASK) >> 16) & (I2Cx->
CR2)) ;
1382 if (((I2Cx->
SR1 & I2C_IT) != (uint32_t)
RESET) && enablestatus)
1428 uint32_t flagpos = 0;
1437 I2Cx->
SR1 = (uint16_t)~flagpos;
#define RCC_APB1Periph_I2C3
#define IS_I2C_CLEAR_FLAG(FLAG)
uint32_t I2C_GetLastEvent(I2C_TypeDef *I2Cx)
Returns the last I2Cx Event.
void I2C_TransmitPEC(I2C_TypeDef *I2Cx, FunctionalState NewState)
Enables or disables the specified I2C PEC transfer.
#define IS_I2C_CONFIG_IT(IT)
#define IS_I2C_EVENT(EVENT)
void I2C_DMACmd(I2C_TypeDef *I2Cx, FunctionalState NewState)
Enables or disables the specified I2C DMA requests.
uint8_t I2C_GetPEC(I2C_TypeDef *I2Cx)
Returns the PEC value for the specified I2C.
void I2C_SMBusAlertConfig(I2C_TypeDef *I2Cx, uint16_t I2C_SMBusAlert)
Drives the SMBusAlert pin high or low for the specified I2C.
#define RCC_APB1Periph_I2C1
void I2C_GenerateSTART(I2C_TypeDef *I2Cx, FunctionalState NewState)
Generates I2Cx communication START condition.
uint16_t I2C_AcknowledgedAddress
#define IS_I2C_REGISTER(REGISTER)
#define IS_I2C_SMBUS_ALERT(ALERT)
#define I2C_DutyCycle_16_9
#define IS_I2C_NACK_POSITION(POSITION)
#define IS_I2C_PEC_POSITION(POSITION)
FlagStatus I2C_GetFlagStatus(I2C_TypeDef *I2Cx, uint32_t I2C_FLAG)
Checks whether the specified I2C flag is set or not.
void I2C_AnalogFilterCmd(I2C_TypeDef *I2Cx, FunctionalState NewState)
Enables or disables the Analog filter of I2C peripheral.
void I2C_CalculatePEC(I2C_TypeDef *I2Cx, FunctionalState NewState)
Enables or disables the PEC value calculation of the transferred bytes.
void I2C_GeneralCallCmd(I2C_TypeDef *I2Cx, FunctionalState NewState)
Enables or disables the specified I2C general call feature.
void I2C_Init(I2C_TypeDef *I2Cx, I2C_InitTypeDef *I2C_InitStruct)
Initializes the I2Cx peripheral according to the specified parameters in the I2C_InitStruct.
void assert_param(int val)
void I2C_AcknowledgeConfig(I2C_TypeDef *I2Cx, FunctionalState NewState)
Enables or disables the specified I2C acknowledge feature.
uint16_t I2C_ReadRegister(I2C_TypeDef *I2Cx, uint8_t I2C_Register)
Reads the specified I2C register and returns its value.
static I2C_TypeDef * I2Cx
#define IS_FUNCTIONAL_STATE(STATE)
void I2C_DigitalFilterConfig(I2C_TypeDef *I2Cx, uint16_t I2C_DigitalFilter)
Configures the Digital noise filter of I2C peripheral.
static volatile uint8_t * status
#define I2C_Direction_Transmitter
#define I2C_CR1_NOSTRETCH
#define I2C_NACKPosition_Next
#define I2C_AcknowledgedAddress_7bit
#define IS_I2C_ACK_STATE(STATE)
#define I2C_PECPosition_Next
void I2C_DMALastTransferCmd(I2C_TypeDef *I2Cx, FunctionalState NewState)
Specifies that the next DMA transfer is the last one.
void I2C_Cmd(I2C_TypeDef *I2Cx, FunctionalState NewState)
Enables or disables the specified I2C peripheral.
#define I2C_SMBusAlert_Low
#define IS_I2C_DIGITAL_FILTER(FILTER)
void RCC_APB1PeriphResetCmd(uint32_t RCC_APB1Periph, FunctionalState NewState)
Forces or releases Low Speed APB (APB1) peripheral reset.
void I2C_SendData(I2C_TypeDef *I2Cx, uint8_t Data)
Sends a data byte through the I2Cx peripheral.
This file contains all the functions prototypes for the I2C firmware library.
uint8_t I2C_ReceiveData(I2C_TypeDef *I2Cx)
Returns the most recent received data by the I2Cx peripheral.
ErrorStatus I2C_CheckEvent(I2C_TypeDef *I2Cx, uint32_t I2C_EVENT)
Checks whether the last I2Cx Event is equal to the one passed as parameter.
void I2C_ClearFlag(I2C_TypeDef *I2Cx, uint32_t I2C_FLAG)
Clears the I2Cx's pending flags.
#define IS_I2C_OWN_ADDRESS1(ADDRESS1)
void I2C_ClearITPendingBit(I2C_TypeDef *I2Cx, uint32_t I2C_IT)
Clears the I2Cx's interrupt pending bits.
void I2C_ARPCmd(I2C_TypeDef *I2Cx, FunctionalState NewState)
Enables or disables the specified I2C ARP.
#define IS_I2C_MODE(MODE)
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.
#define IS_I2C_DIRECTION(DIRECTION)
void I2C_SoftwareResetCmd(I2C_TypeDef *I2Cx, FunctionalState NewState)
Enables or disables the specified I2C software reset.
void I2C_ITConfig(I2C_TypeDef *I2Cx, uint16_t I2C_IT, FunctionalState NewState)
Enables or disables the specified I2C interrupts.
#define I2C_SMBusAlert_High
void I2C_PECPositionConfig(I2C_TypeDef *I2Cx, uint16_t I2C_PECPosition)
Selects the specified I2C PEC position.
I2C Init structure definition.
void I2C_FastModeDutyCycleConfig(I2C_TypeDef *I2Cx, uint16_t I2C_DutyCycle)
Selects the specified I2C fast mode duty cycle.
void I2C_GenerateSTOP(I2C_TypeDef *I2Cx, FunctionalState NewState)
Generates I2Cx communication STOP condition.
void I2C_DualAddressCmd(I2C_TypeDef *I2Cx, FunctionalState NewState)
Enables or disables the specified I2C dual addressing mode.
#define IS_I2C_GET_IT(IT)
void I2C_OwnAddress2Config(I2C_TypeDef *I2Cx, uint8_t Address)
Configures the specified I2C own address2.
#define IS_I2C_CLEAR_IT(IT)
ITStatus I2C_GetITStatus(I2C_TypeDef *I2Cx, uint32_t I2C_IT)
Checks whether the specified I2C interrupt has occurred or not.
#define IS_I2C_ACKNOWLEDGE_ADDRESS(ADDRESS)
#define I2C_NACKPosition_Current
#define IS_I2C_CLOCK_SPEED(SPEED)
#define IS_I2C_GET_FLAG(FLAG)
Inter-integrated Circuit Interface.
void I2C_StructInit(I2C_InitTypeDef *I2C_InitStruct)
Fills each I2C_InitStruct member with its default value.
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_NACKPositionConfig(I2C_TypeDef *I2Cx, uint16_t I2C_NACKPosition)
Selects the specified I2C NACK position in master receiver mode.
#define IS_I2C_DUTY_CYCLE(CYCLE)
#define RCC_APB1Periph_I2C2
#define IS_I2C_ALL_PERIPH(PERIPH)
void I2C_DeInit(I2C_TypeDef *I2Cx)
Deinitialize the I2Cx peripheral registers to their default reset values.