#include "MyI2C.h" void I2C_Init() { /* Déclaration */ MyGPIO_Struct_TypeDef GPIOB6; // pin SCL MyGPIO_Struct_TypeDef GPIOB7; // pin SDA /* On reset les registres de l'I2C1 */ RCC->APB1RSTR |= RCC_APB1RSTR_I2C1RST; // reset en le mettant à 1 RCC->APB1RSTR &= ~RCC_APB1RSTR_I2C1RST;// et on remet le bit à 0 (reset termine) RCC->APB1ENR |=RCC_APB1ENR_I2C1EN; // clock eanble // reset software I2C1->CR1 |= I2C_CR1_SWRST; I2C1->CR1 &= ~I2C_CR1_SWRST; /* Initialisation des GPIO */ GPIOB6.GPIO = GPIOB; GPIOB6.GPIO_Pin = 6; GPIOB6.GPIO_Conf = AltOut_Ppull; GPIOB7.GPIO = GPIOB; GPIOB7.GPIO_Pin = 7; GPIOB7.GPIO_Conf = AltOut_Ppull; MyGPIO_Init(&GPIOB6); MyGPIO_Init(&GPIOB7); I2C1->CCR &= ~(0x1 << 15); // mode SM ? I2C1->CR1 |= I2C_CR1_PE; // Peripheral Enable I2C1->CR2 |= 36; // 36MHz I2C1->CCR |= 270; // on met le CCR à 270 pour avoir 100 kHz }