这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 综合技术 » 基础知识 » i2c,AT24C01,eeprom,eeprom 模拟i2c外接AT24C01

共3条 1/1 1 跳转至

i2c,AT24C01,eeprom,eeprom 模拟i2c外接AT24C01 eeprom,如何知道eeprom器件地址

院士
2006-09-17 18:14:16     打赏
i2c,AT24C01,eeprom,eeprom 模拟i2c外接AT24C01 eeprom,如何知道eeprom器件地址



关键词: AT24C01     eeprom     模拟     外接     如何         

院士
2006-12-22 22:43:00     打赏
2楼
问 #define EEPROM_BUS_ADDRESS 0xa0
请问怎么知道对某一片EEPROM_BUS_ADDRESS是多少 1: 1010xxxxxx是多少你自己在电路中设。
也就是接高或接地. 2: 是否把3个nc脚接地,那地址就是1010000是否把3个nc脚接地,那地址就是1010000,如果把这3个脚悬空,那地址就是1010111吗 3: 对啊,最后一位是读写位。是把A0A1A2接地。 4: 大家帮我看看以下程序,为何不可#include <mega128.h>

// I2C Bus functions
#asm
   .equ __i2c_port=0x12
   .equ __sda_bit=1
   .equ __scl_bit=0
#endasm
#include <i2c.h>
#include <delay.h>
#include <stdio.h>
#define EEPROM_BUS_ADDRESS 0x0ae


/* 从EEPROM 读一个字节 */
unsigned char eeprom_read(unsigned char address) {
unsigned char data;
i2c_start();
i2c_write(EEPROM_BUS_ADDRESS);
i2c_write(address);
i2c_start();
i2c_write(EEPROM_BUS_ADDRESS | 1);
data=i2c_read(0);
i2c_stop();
return data;
}

/* 向EEPROM 写一个字节 */
void eeprom_write(unsigned char address, unsigned char data) {
i2c_start();
i2c_write(EEPROM_BUS_ADDRESS);
i2c_write(address);
i2c_write(data);
i2c_stop();
/* 10 延时等待写操作完成 */
delay_ms(10);
}

main()
{
/* 初始化I2C 总 线 */
i2c_init();
/* 从地址0到127 写入55h */
for(j=0;j<128;j++)
  eeprom_write(j,0x55);
/* 从地址AAh 读一个字节 */
for(j=0;j<128;j++)
  Read_EEPROM[j] = eeprom_read(j);
for(j=0;j<128;j++)
  putchar(Read_EEPROM[j]);
while(1);
} 5: EEPROM_BUS_ADDRESS 0x0ae 不对 6: 见// *********************************************************************** //
// *** H_ADD is the hardware address set on the device A0,A1 & A2 pins *** //
// *** M_ADD is the devices internal memory address                    *** //
// *** Data is user data to be writen                                    *** //
// *********************************************************************** //

char EEPROM_Write(unsigned char H_ADD, unsigned int M_ADD, unsigned char * _Data,unsigned char len)
{
  char  i;
I2C_Start();                              // Set I2C start condition

  Write_I2C_Control(0x0A,H_ADD,0);       // Send the EEPROM control Byte
  Write_I2C_Byte(*(((char *)&M_ADD)+1));                   // Send the EEPROM internal Address
  Write_I2C_Byte(*((char *)&M_ADD));                   // Send the EEPROM internal Address
  for(i=0;i<len;i++)
  Write_I2C_Byte( *(_Data+i));                   // Send the EEPROM Data

I2C_Stop();                             // Set I2C Stop condition
}



// *********************************************************************** //
// *** H_ADD is the hardware address set on the device A0,A1 & A2 pins *** //
// *** M_ADD is the devices internal memory address                    *** //
// *** Data is user data to be writen                                    *** //
// *********************************************************************** //

unsigned char EEPROM_Read(unsigned char H_ADD, unsigned int M_ADD)
{
unsigned char Temp;                       // Temp RAM for EEPROM Read

I2C_Start();                              // Set I2C start condition

Write_I2C_Control(0x0A,H_ADD,0);       // Send the EEPROM control Byte
                                        // Dummy write to set address

Write_I2C_Byte(*(((char *)&M_ADD)+1));                   // Send the EEPROM internal Address
Write_I2C_Byte(*((char *)&M_ADD));                   // Send the EEPROM internal Address

I2C_Start();                              // Set I2C start condition

Write_I2C_Control(0x0A,H_ADD,1);       // Send the EEPROM control Byte

Temp = Read_I2C_Byte();               // Read data from EEPROM

I2C_Stop();                             // Set I2C Stop condition

return Temp;                           // Return data from EEPROM
}

7: 是否是因为频率原因请问你这个函数Write_I2C_Control(0x0A,H_ADD,0);       // Send the EEPROM control Byte
是自己写的吗?如果采用14M的晶体振荡器,会不会就写不进去。
我以上程序是调用cvAVR的库函数,内部库函数数是不是只在一定的频率下才有效果 8: eeprom 为400k

高工
2022-08-20 15:47:21     打赏
3楼

感谢分享


共3条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]