共3条
1/1 1 跳转至页
i2c,AT24C01,eeprom,eeprom 模拟i2c外接AT24C01 eeprom,如何知道eeprom器件地址
问
#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
请问怎么知道对某一片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
共3条
1/1 1 跳转至页
回复
有奖活动 | |
---|---|
【有奖活动】分享技术经验,兑换京东卡 | |
话不多说,快进群! | |
请大声喊出:我要开发板! | |
【有奖活动】EEPW网站征稿正在进行时,欢迎踊跃投稿啦 | |
奖!发布技术笔记,技术评测贴换取您心仪的礼品 | |
打赏了!打赏了!打赏了! |