模拟I2C控制24C02

发布时间:2021-06-06

使用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 */

模拟I2C控制24C02.doc 将本文的Word文档下载到电脑

精彩图片

热门精选

大家正在看

× 游客快捷下载通道(下载后可以自由复制和排版)

限时特价:7 元/份 原价:20元

支付方式:

开通VIP包月会员 特价:29元/月

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219