欢迎来到天天文库
浏览记录
ID:11422816
大小:19.27 KB
页数:7页
时间:2018-07-11
《stm32 模拟iic读写24c02程序代码》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、STM32模拟IIC读写24C02程序代码引脚定义和配置:#defineSCLGPIO_Pin_6//24C02SCL#defineSDAGPIO_Pin_7//24C02SDAvoidGPIO_Configuration(void){RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1
2、RCC_APB2Periph_GPIOA
3、RCC_APB2Periph_GPIOB
4、RCC_APB2Periph_GPIOC
5、RCC_APB2Periph_GPIOD
6、RCC_APB2Pe
7、riph_GPIOE,ENABLE);GPIO_InitStructure.GPIO_Pin=SCL;//24C02SCLGPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_OD;GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;GPIO_Init(GPIOB,&GPIO_InitStructure);GPIO_InitStructure.GPIO_Pin=SDA;//24C02SDA作为输出GPIO_InitStructure.G
8、PIO_Mode=GPIO_Mode_Out_OD;GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;GPIO_Init(GPIOB,&GPIO_InitStructure);}voidAT24C02_SDA_IO_SET(unsignedchario_set)//SDA引脚输入输出设置{if(io_set==0){GPIO_InitStructure.GPIO_Pin=SDA;//24C02SDA作为输出GPIO_InitStructure.GPIO_Mode=G
9、PIO_Mode_Out_OD;GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;GPIO_Init(GPIOB,&GPIO_InitStructure);}elseif(io_set==1){GPIO_InitStructure.GPIO_Pin=SDA;//24C02SDA作为输入GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IPU;//上拉输入GPIO_Init(GPIOB,&GPIO_InitStructure);}else{
10、;}}/////////////////主程序///////////////////intmain(void){uchari;uchardata_24c02;RCC_Configuration();//时钟配置GPIO_Configuration();//GPIO配置USARTx_configuration();//串口配置WIN24C02_init();delayms(5000);//延时for(i=0;i<20;i++)//写EEPROM数据{WIN24C02_write(0x00+i,i);delaym
11、s(100);}//存数据到EEPROMdelayms(1000);//延时while(1)//串口3发送读取的EEPROM的数据{for(i=0;i<20;i++){data_24c02=WIN24C02_read(0x00+i);//读取24C02数据USART_SendData(USART3,data_24c02);while(USART_GetFlagStatus(USART3,USART_FLAG_TC)==RESET);}delayms(5000);//延时}}//////////////////
12、///////////////////////////////////////////////////////////////////////////////////////////////WIN_24C02.H头文件/**********************中文版本*******************************//*****功能描述:STM3224C02读写程序*****//*****作者:*****//*****编写日期:2013年1月21日*****//*****版本信息:V1.0*
13、****//*****修改日期:*****//*************************************************************/#ifndef__WIN24C02_H__#define__WIN24C02_H__#include"STM32_Config.h"#defineucharunsignedchar#defineuintunsignedintucha
此文档下载收益归作者所有