Created
July 9, 2015 16:51
-
-
Save rheum/0df542360ae74347720f to your computer and use it in GitHub Desktop.
i2c_init
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void init_i2c(void) | |
{ | |
RCC_I2CCLKConfig(RCC_I2C1CLK_SYSCLK); | |
RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE); | |
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE); | |
GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_1); | |
GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_AF_1); | |
GPIO_InitTypeDef gpio_conf; | |
gpio_conf.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7; | |
gpio_conf.GPIO_Mode = GPIO_Mode_AF; | |
gpio_conf.GPIO_OType = GPIO_OType_OD; | |
gpio_conf.GPIO_PuPd = GPIO_PuPd_NOPULL; | |
gpio_conf.GPIO_Speed = GPIO_Speed_2MHz; | |
GPIO_Init(GPIOC, &gpio_conf); | |
I2C_Cmd(I2C1, DISABLE); | |
I2C_DeInit(I2C1); | |
I2C_InitTypeDef i2c_conf; | |
i2c_conf.I2C_Mode = I2C_Mode_I2C; | |
i2c_conf.I2C_AnalogFilter = I2C_AnalogFilter_Enable; | |
i2c_conf.I2C_OwnAddress1 = 0x00; | |
i2c_conf.I2C_Ack = I2C_Ack_Enable; | |
i2c_conf.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit; | |
i2c_conf.I2C_Timing = 0x1045061D; | |
I2C_Init(I2C1, &i2c_conf); | |
I2C_Cmd(I2C1, ENABLE); | |
I2C_10BitAddressHeaderCmd(I2C1, DISABLE); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment