使用STM32红牛开发的GPIO模拟I2C控制八个AT24C02的读写
#ifndef __STM32F10x_I2C_H
#define __STM32F10x_I2C_H
/* Includes ------------------------------------------------------------------*/
#include "stm32f10x_map.h"
/* Exported types ------------------------------------------------------------*/ /* I2C Init structure definition */
void I2C_GenerateSTART(void);
void I2C_GenerateSTOP(void);
void I2C_SendData(u8 Data);
u8 I2C_ReceiveData(void);
void Ack(void);
bool WaitAck(void);
void NAck(void);
void wait(u16 Data);
void GPIOC_Config_OUT(void);
void GPIOC_Config_IN(void);
#endif /*__STM32F10x_I2C_H */
//C文件
/******************** (C) COPYRIGHT 2011 STMicroelectronics ********************
* File Name : stm32f10x_i2c.c
* Author : Tanglin
* Version : V2.0.1
* Date : 11/9/2011
* Description : This file provides all the I2C firmware functions.
********************************************************************************
/* Includes ------------------------------------------------------------------*/
#include "stm32f10x_i2c.h"
#include "stm32f10x_rcc.h"
#include "i2c_ee.h"
void I2C_GenerateSTART(void)
{
SDAH;//SDA=1;
wait(10);
SCLH;//SCL=1;
wait(10);
SDAL;//SDA=0;