I2C_24c02实验
来源:互联网 发布:三星s7解网络锁工具 编辑:程序博客网 时间:2024/06/04 23:26
一、RCC初始化
- /* Setup the microcontroller system. Initialize the Embedded Flash Interface,
- initialize the PLL and update the SystemFrequency variable. */
- SystemInit();
- /* Enable peripheral clocks --------------------------------------------------*/
- /* GPIOB Periph clock enable */
- //RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB, ENABLE);
- //启动GPIO模块时钟
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO, ENABLE);
- //把雕饰设置普通IO口
- GPIO_PinRemapConfig(GPIO_Remap_SWJ_Disable,ENABLE);
- /* I2C1 Periph clock enable */
- RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE);
二、I2C_初始化
- /* Configure I2C1 pins: SCL and SDA */
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD;
- GPIO_Init(GPIOB, &GPIO_InitStructure);
- I2C_InitTypeDef I2C_InitStructure;
- /* I2C configuration */
- I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;
- I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2;
- I2C_InitStructure.I2C_OwnAddress1 = I2C1_SLAVE_ADDRESS7;
- I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;
- I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
- I2C_InitStructure.I2C_ClockSpeed = 100000;
-
- /* I2C Peripheral Enable */
- I2C_Cmd(I2C1, ENABLE);
- /* Apply I2C configuration after enabling it */
- I2C_Init(I2C1, &I2C_InitStructure);
三、USART初始化
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
-
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
- USART_InitStructure.USART_BaudRate = 115200;
- USART_InitStructure.USART_WordLength = USART_WordLength_8b;
- USART_InitStructure.USART_StopBits = USART_StopBits_1;
- USART_InitStructure.USART_Parity = USART_Parity_No;
- USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
- USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
- USART_Init(USART1, &USART_InitStructure);
- USART_Cmd(USART1, ENABLE);
四、main函数测试程序
- while (1)
- {
- I2C_EE_BufferWrite(ReadBuff, 0, 3);
- I2C_EE_BufferRead(SendBuff, 0, 3);
- Delay(0xfffff);
- fPutString(SendBuff, 15);
- }
遇到的问题,我用以前的RCC初始化程序怎么都无法启动I2C。一直在 while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT)); 中跑。
现在还没有搞清楚,I2C需要怎么设置时钟。
0
上一篇:DMA实验总结
下一篇:sysTick系统定时器
相关热门文章
- SHTML是什么_SSI有什么用...
- 查看linux中某个端口(port)...
- 卡尔曼滤波的原理说明...
- shell中字符串操作
- 关于java中的“错误:找不到或...
给主人留下些什么吧!~~
评论热议
阅读全文
0 0
- I2C_24c02实验
- 实验
- 实验
- 实验
- 实验
- 实验
- 实验
- 实验
- 实验
- 实验
- 实验
- 实验。。
- 实验
- 实验
- 实验
- 实验
- 实验
- 实验
- 按键中断总结
- STM32串口USART通信总结
- codeforces 839B Game of the Rows(思路题)
- DMA实验总结
- C/C++时间函数
- I2C_24c02实验
- 开始新的征程~~~~从第一个python 的机器学习实验开始~~~~~SVM实验
- sysTick系统定时器
- MOSFET学习
- 晶体管电路设计学习笔记(一)
- 增强输出的电路
- 小型功率放大器的设计与制作
- SpringMVC--BeanNameUrlHandlerMapping详解
- MDK(keil)4.7中文注释乱码解决
原创粉丝点击
热门IT博客
热门问题
老师的惩罚
人脸识别
我在镇武司摸鱼那些年
重生之率土为王
我在大康的咸鱼生活
盘龙之生命进化
天生仙种
凡人之先天五行
春回大明朝
姑娘不必设防,我是瞎子
痔疮肿了很大怎么办
月子里痔疮便血怎么办
大便完痔疮疼怎么办
痔疮出血一个月怎么办
痔疮疼大便出血怎么办
医院押金条丢失怎么办
怀孕痔疮痒怎么办啊
喂奶期痔疮疼痛怎么办
痔疮在肛门外面怎么办
痔疮晚上很痒怎么办
生孩子挣出痔疮怎么办
生孩子时痔疮脱出怎么办
生孩子后痔疮疼怎么办
屁股长痔疮了怎么办
孕妇长外痔疮怎么办?
生孩子带出痔疮怎么办
生孩子痔疮掉出怎么办
上火了痔疮疼怎么办
中气下降痔疮痛怎么办
痔疮很痛怎么办啊
怀孕初期生痔疮怎么办
痔疮手术化脓了怎么办
直肠手术后便血怎么办
直肠微创手术后便血怎么办
直肠手术刀口没长好怎么办
有轻微痔疮症状怎么办
内痔疮脱落出来怎么办
本身有痔疮怀孕怎么办
怀孕中期得痔疮怎么办
痔疮手术后久坐怎么办
痔疮引起肛裂怎么办
手术后气腹怎么办
腹腔镜术后涨气怎么办
便秘没有便意怎么办
生产后痔疮严重怎么办
脱出来的痔疮怎么办
孕妇得了外痔疮怎么办
屁股长痔疮痛怎么办
肛瘘手术后痛怎么办
痔疮手术换药疼怎么办
痔疮手术瘢痕疼怎么办