使用STM32红牛开发的GPIO模拟I2C控制八个AT24C02的读写
//头文件
#ifndef __I2C_EE_H
#define __I2C_EE_H
/* Includes ------------------------------------------------------------------*/
#include "stm32f10x_lib.h"
/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/* The M24C08W contains 4 blocks (128byte each) with the adresses below: E2 = 0 */
/* EEPROM Addresses defines */
//#define EEPROM_Block0_ADDRESS 0xA0 /* E2 = 0 */
//#define EEPROM_Block1_ADDRESS 0xA2 /* E2 = 0 */
//#define EEPROM_Block2_ADDRESS 0xA4 /* E2 = 0 */
//#define EEPROM_Block3_ADDRESS 0xA6 /* E2 = 0 */
#define GPIO_MONII2C_CLK GPIOA
#define RCC_APB2Periph_GPIO_MONII2C_CLK RCC_APB2Periph_GPIOA #define GPIO_Pin_CLK GPIO_Pin_All
#define GPIO_MONII2C_SDA GPIOC
#define RCC_APB2Periph_GPIO_MONII2C_SDA RCC_APB2Periph_GPIOC #define GPIO_Pin_SDA GPIO_Pin_All
#define SCLH GPIOA->BSRR = GPIO_Pin_All
#define SCLL GPIOA->BRR = GPIO_Pin_All
#define SDAH GPIOC->BSRR = GPIO_Pin_All
#define SDAL GPIOC->BRR = GPIO_Pin_All
#define SDAread GPIOC->IDR & GPIO_Pin_7 //通过修改这句来控制多个芯片读写
/* Exported macro ------------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */
void I2C_EE_Init(void);
void I2C_EE_ByteWrite(u8* pBuffer, u16 WriteAddr);
void I2C_EE_PageWrite(u8* pBuffer, u16 WriteAddr, u16 NumByteToWrite);
void I2C_EE_BufferWrite(u8* pBuffer, u16 WriteAddr, u16 NumByteToWrite);
void I2C_EE_BufferRead(u8* pBuffer, u16 ReadAddr, u16 NumByteToRead);
void I2C_EE_PageRead(u8* pBuffer, u16 ReadAddr, u16 NumByteToRead);
void I2C_EE_Current_Read(u8* pBuffer);
void I2C_EE_Continue_Read(u8* pBuffer, u16 ReadAddr, u16 NumByteToRead); //void I2C_EE_WaitEepromStandbyState(void);
void SEND_0(void);
void SEND_1(void);
void wait(u16 Data);
#endif /* __I2C_EE_H */