TA的每日心情 | 奋斗 2020-5-27 15:41 |
---|
签到天数: 868 天 连续签到: 1 天 [LV.10]以坛为家III
|
本帖最后由 wambob 于 2017-1-10 09:52 编辑
首次用mbed驱动 EEPROM失败后,自然是查找原因了,硬件问题,软件问题。
先把硬件问题除外,因为这个是最近的开发板。参考了各种资源,反复验证代码,还是不成功,再次详细查看AT24c02的手册。
Features
• Low-voltage and Standard-voltage Operation
– 2.7 (VCC = 2.7V to 5.5V)
– 1.8 (VCC = 1.8V to 5.5V)
• Internally Organized 128 x 8 (1K), 256 x 8 (2K), 512 x 8 (4K),
1024 x 8 (8K) or 2048 x 8 (16K)
• Two-wire Serial Interface
• Schmitt Trigger, Filtered Inputs for Noise Suppression
• Bidirectional Data Transfer Protocol
• 100 kHz (1.8V) and 400 kHz (2.7V, 5V) Compatibility
• Write Protect Pin for Hardware Data Protection
• 8-byte Page (1K, 2K), 16-byte Page (4K, 8K, 16K) Write Modes
• Partial Page Writes Allowed
• Self-timed Write Cycle (5 ms max)
• High-reliability
– Endurance: 1 Million Write Cycles
– Data Retention: 100 Years
• Automotive Grade and Lead-free/Halogen-free Devices Available
• 8-lead PDIP, 8-lead JEDEC SOIC, 8-lead MAP, 5-lead SOT23,
8-lead TSSOP and 8-ball dBGA2 Packages
• Die Sales: Wafer Form, Waffle Pack and Bumped Wafers
其中一句 100KHz 和400KHz兼容。
我记得我是使用的400KHz,有问题吗?
为了验证,我修改时钟为200kHz:- i2c_master.frequency(200000);
复制代码 先向24c02读写写一个字节验证,令人欣喜,读写正确,再次读写整个24c02,也正确
想看个串口结果
代码- #include "mbed.h"
- Serial pc(P0_4,P0_0);
- I2C i2c_master(P0_11,P0_10);
- char buff[256];
- char buff1[256];
- const char senddata=0xaa;
- char readdata;
- int main() {
- int i;
- i2c_master.frequency(200000);
- pc.printf(" write data:%x \r\n",senddata);
- i2c_master.start();
- i2c_master.write(0xA0);
- i2c_master.write(0x1);
- i2c_master.write(senddata);
- i2c_master.stop();
- wait(0.02);
- i2c_master.start();
- i2c_master.write(0xA0);
- i2c_master.write(0x1);
- i2c_master.start();
- i2c_master.write(0xA1);
- readdata=i2c_master.read(1);
- i2c_master.stop();
- pc.printf(" read data:%x \r\n",readdata);
- pc.printf(" write \r\n");
- for(i=0;i<256;i++){
- buff[i] =i;
- pc.printf("0x%02x ",buff[i]);
- i2c_master.start();
- i2c_master.write(0xA0);
- i2c_master.write(i);
- i2c_master.write(buff[i]);
- i2c_master.stop();
- if(i%16==15)
- pc.printf("\r\n");
- }
- wait(0.2);
- pc.printf(" read \r\n");
- for(i=0;i<256;i++){
- i2c_master.start();
- i2c_master.write(0xA0);
- i2c_master.write(i);
- i2c_master.start();
- i2c_master.write(0xA1);
- buff1[i] =i2c_master.read(1);
- i2c_master.stop();
- pc.printf("0x%02x ",buff1[i]);
- if(i%16==15)
- pc.printf("\r\n");
- }
- while(1) {
-
- }
- }
复制代码 400KHz真的不可以吗。我又改成400kHz。编译下载,打开串口助手,复位开发板
串口显示:
读数大部分正确。,但只是头2个字节有问题。使用200kHz则没这个问题。
|
评分
-
查看全部评分
|