模拟I2C控制24C02

上传人:云**** 文档编号:209169333 上传时间:2021-11-08 格式:DOCX 页数:16 大小:18.92KB
返回 下载 相关 举报
模拟I2C控制24C02_第1页
第1页 / 共16页
模拟I2C控制24C02_第2页
第2页 / 共16页
亲,该文档总共16页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述

《模拟I2C控制24C02》由会员分享,可在线阅读,更多相关《模拟I2C控制24C02(16页珍藏版)》请在金锄头文库上搜索。

1、模拟I2C控制24C02 使用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 */ /#defin

2、e 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_CL

3、K 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 #defi

4、ne 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

5、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_WaitEepromStandbySta

6、te(void); void SEND_0(void); void SEND_1(void); void wait(u16 Data); #endif /* _I2C_EE_H */ 使用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(

7、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 2021 STMicroelectronics * *

8、File Name : stm32f10x_i2c.c * Author : Tanglin * Version : V2.0.1 * Date : 11/9/2021 * 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=

9、1; wait(10); SDAL;/SDA=0; 使用STM32红牛开发的GPIO模拟I2C掌握八个AT24C02的读写 SCLL; wait(10); void GPIOC_Config_IN(void) GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIO_MONII2C_SDA | RCC_APB2Periph_GPIOC , ENABLE); /* moni SPI pins: SDA */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;

10、GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; /输入上拉 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOC, GPIO_InitStructure); void GPIOC_Config_OUT(void) GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIO_MONII2C_SDA | RCC_APB2Periph_GPIOC , ENABLE); /* mon

11、i SPI pins: SDA */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD; /开漏输出 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOC, GPIO_InitStructure); void I2C_EE_PageRead(u8* pBuffer, u16 ReadAddr, u16 NumByteToRead) u16 i=0; /* Send START cond

12、ition */ I2C_GenerateSTART(); I2C_SendData(I2C_SLAVE_ADDRESS7_W); /I2C_SLAVE_ADDRESS7=0xa0,伪写操作 WaitAck(); /* Send the EEPROMs internal address to write to */ I2C_SendData(ReadAddr); WaitAck(); /* Send STRAT condition a second time */ I2C_GenerateSTART(); I2C_SendData(I2C_SLAVE_ADDRESS7_R); /I2C_SLAVE_ADDRESS7=0xa1,读操作 使用STM32红牛开发的GPIO模拟I2C掌握八个AT24C02的读写 for(i=0;iNu

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 办公文档 > 总结/报告

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号