CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

external eprom extrange read problem

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
itzalak2
Guest







external eprom extrange read problem
PostPosted: Mon Mar 05, 2007 5:15 am     Reply with quote

Hi everybody.

I have an application where I read an external I2C eprom 24AA1025 (1Mega) . I have this read routine

int32 leer_int32_ext_eeprom_banco_0(EEPROM_ADDRESS_H address_h, EEPROM_ADDRESS_L address_l)
{
int1 ack;
i2c_start();
ack = i2c_write(0b10100000);
delay_ms (10);
i2c_stop();
if (ack==0)
{
int8 i;
int32 temporal=0;
int32 puntero=0;
i2c_start();
i2c_write(0b10100000);
delay_ms (10);
i2c_write(address_h);
delay_ms (10);
i2c_write(address_l);
delay_ms (10);
i2c_start();
i2c_write(0b10100001);
delay_ms (10);

for(i = 0; i < 4; ++i) //secuencial
{
*(&temporal + i) = i2c_read();
delay_ms (100);
}
i2c_stop();
return temporal;
}
}

and in the main program I read 3 different memory positions:

delay_ms(10);
maniobra_NS1=leer_int32_ext_eeprom_banco_0 (0x00,0x00);

delay_ms(10);
maniobra_NS2=leer_int32_ext_eeprom_banco_0 (0x00,0x04);

delay_ms(10);
maniobra_EW1=leer_int32_ext_eeprom_banco_0 (0xFF,0xFC);

If I read the 3 registers the first and the second returns a correct value but not the last.

If I erase the first and secodn read (maniobra_NS1 and maniobra_NS2) I the returned value of the 3th read is correct.

Any idea why happens it?

Thanks a lot.

I'm using pic 18f2525 and software I2c (I can't use hardware I2c becouse system hangs at init (don't know why)

Thanks again
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Mar 05, 2007 11:16 am     Reply with quote

Quote:
for(i = 0; i < 4; ++i) //secuencial
{
*(&temporal + i) = i2c_read();
delay_ms (100);
}
i2c_stop();

You are doing 4 i2c read operations. The last one must do a "NAK".
In CCS, this is done by using a 0 parameter. Example:

Code:
c = i2c_read(0);


You need to modify your code above, so the last i2c read does a NAK.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group