模拟I2C代码
模拟I2C代码相关定义
#define EEPROM_I2C_Write 0xA0 //EEPROM的设备地址(1010 000) + 0(写)
#define EEPROM_I2C_Read 0xA1 //EEPROM的设备地址(1010 000) + 1(读)
#define EEPROM_PAGE_SIZE 8
/* I2C_SCL——PB8 */
#define I2C_SCL_PIN GPIO_Pin_8
#define I2C_SCL_GPIO_PORT GPIOB
#define I2C_SCL_GPIO_CLK RCC_AHB1Periph_GPIOB
/* I2C_SDA——PB9 */
#define I2C_SDA_PIN GPIO_Pin_9
#define I2C_SDA_GPIO_PORT GPIOB
#define I2C_SDA_GPIO_CLK RCC_AHB1Periph_GPIOB
#define I2C_SCL_1() GPIO_SetBits(I2C_SCL_GPIO_PORT, I2C_SCL_PIN) /* SCL = 1 */
#define I2C_SCL_0() GPIO_ResetBits(I2C_SCL_GPIO_PORT, I2C_SCL_PIN) /* SCL = 0 */
#define I2C_SDA_1() GPIO_SetBits(I2C_SDA_GPIO_PORT, I2C_SDA_PIN) /* SDA = 1 */
#define I2C_SDA_0() GPIO_ResetBits(I2C_SDA_GPIO_PORT, I2C_SDA_PIN) /* SDA = 0 */
#define I2C_SDA_READ() GPIO_ReadInputDataBit(I2C_SDA_GPIO_PORT, I2C_SDA_PIN) /* 读SDA口线状态 */
void I2C_Buff_Read(uint8_t ADDR , uint8_t *Data,uint16_t size);
void I2C_Buff_Write(uint8_t ADDR , uint8_t *Data,uint16_t size);
void I2C_GPIO_Config(void);
|