qazplm3218 发表于 2020-7-9 20:23:52

STM32F103驱动24C1024?

24C1024与24C02的驱动是否通用?我用24C02的驱动(模拟IO口)向24C1024的0x01地址写入数据0x01,读写都不正常?谁能提供24C1024的驱动参考下,谢谢!

陌路夕颜 发表于 2020-7-10 08:42:40

他俩肯定不能直接用,地址的位数不一样,看看24C1024的手册

qazplm3218 发表于 2020-7-10 09:09:54

陌路夕颜 发表于 2020-7-10 08:42
他俩肯定不能直接用,地址的位数不一样,看看24C1024的手册

你好,我知道地址的个数不一样,但是写0x01地址是不是一样的?

ldptest 发表于 2020-7-10 09:14:02

24c02是8bit地址
24c1024是16bit地址,地址0x01应改为0x0001


likang1202 发表于 2020-7-10 11:05:30

地址长度不一样吧

zts329547875 发表于 2020-7-10 11:10:04

1024好贵吧

qazplm3218 发表于 2020-7-10 12:40:59

ldptest 发表于 2020-7-10 09:14
24c02是8bit地址
24c1024是16bit地址,地址0x01应改为0x0001

谢谢您,晚上回去地址改成0x0001试试

qazplm3218 发表于 2020-7-10 12:43:08

ldptest 发表于 2020-7-10 09:14
24c02是8bit地址
24c1024是16bit地址,地址0x01应改为0x0001

谢谢,晚上回去地址改成0x0001试试

hujjj 发表于 2020-7-11 09:34:31

如果不是使用硬件I2C的话,不光是读写地址要改成16位的,写地址的代码也要相应变动,改成写两个字节。

qazplm3218 发表于 2020-7-11 11:18:12

hujjj 发表于 2020-7-11 09:34
如果不是使用硬件I2C的话,不光是读写地址要改成16位的,写地址的代码也要相应变动,改成写两个字节。 ...

你好,帮我看下,这个代码哪里错误,要怎么修改?谢谢
void at24c1024_response(void)       //at24c1024应答响应信号;SCL高电平下,如果at24c1024收到数据,则会SDA拉低
{
unsigned int x=0;
at24c1024_scl_set();
systick_delay_us(5);
while((at24c1024_sda_io())&&(x<5000))x++;   //等待是否有应答,如果一段时间应答不成功,则默认为应答成功
at24c1024_scl_clr();
systick_delay_us(5);
}

unsigned char at24c1024_read_byte(void)    //从at24c1024读出数据
{
unsigned char x,y;
at24c1024_scl_clr();
systick_delay_us(5);
at24c1024_sda_set();
systick_delay_us(5);
for(x=0;x<8;x++)
{
at24c1024_scl_clr();
systick_delay_us(5);
y=(y<<1)|at24c1024_sda_io();
systick_delay_us(5);
at24c1024_scl_set();
systick_delay_us(5);
}
return y;
}

void at24c1024_write_byte1(unsigned int byte)    //向at24c1024写入数据
{
unsigned int x,y;
for(x=0;x<16;x++)
{
y=byte&0x8000;
at24c1024_scl_clr();
systick_delay_us(5);
if(y==0){at24c1024_sda_clr();}
else{at24c1024_sda_set();}
systick_delay_us(5);
at24c1024_scl_set();
systick_delay_us(5);
byte=byte<<1;
systick_delay_us(5);
}
at24c1024_scl_clr();
systick_delay_us(5);
at24c1024_sda_clr();
systick_delay_us(5);
}

void at24c1024_write_data(unsigned char add,unsigned char data)    //给at24c1024指定地址写入数据
{       
at24c1024_start();
at24c1024_write_byte(0xA0);                        //0xA0:写数据,0xA1:读数据;
at24c1024_response();
at24c1024_write_byte1(add);
at24c1024_response();
at24c1024_write_byte1(data);
at24c1024_response();
at24c1024_stop();
systick_delay_ms(10);
}

unsigned char at24c1024_read_data(unsigned char add)    //从A24C1024指定地址中读出数据
{//0xA0:写数据,0xA1:读数据;
unsigned int data;
at24c1024_start();
at24c1024_write_byte1(0xA0);                       
at24c1024_response();
at24c1024_write_byte1(add);
at24c1024_response();

at24c1024_start();
at24c1024_write_byte1(0xA1);                       
at24c1024_response();
data=at24c1024_read_byte();
at24c1024_stop();
systick_delay_ms(10);
return data;
}
页: [1] 2
查看完整版本: STM32F103驱动24C1024?