Atmel website | ARM Community | AVR freaks | Technical Support
Banner
 FAQ •  Search •  Register •  Login 

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: question about using at24c02 in at91lib1.4
PostPosted: Mon Feb 02, 2009 12:31 pm 
Offline

Joined: Mon Feb 02, 2009 11:53 am
Posts: 3
Currently, I use at91sam7x256 with at24c02 eeprom, according to atmel advice, I will use twi to read & write at24c02. I download at91lib 1.4, using twi sample in at91lib 1.4.
I change the i2c slave device address from 0x50 to 0xA0, 0x50 is the atmel evb board which use at24c512, 0xA0 is the device address which I use at24c02, but I got a SANITY_CHECK error. this error is caused by "SANITY_CHECK((address & 0x80) == 0);" which can be found in TWI_StartRead and TWI_StartWrite in twi.c and twid.c.
So how to fix this question? thanks all


Top
 Profile  
 
 Post subject: Re: question about using at24c02 in at91lib1.4
PostPosted: Tue Feb 03, 2009 10:05 am 
Offline

Joined: Mon Feb 02, 2009 11:53 am
Posts: 3
It is my fault, I don't read at24c02 datasheet complete.
The at24 series eeprom device addressing is 0x50, because the A0,A1,A2 pin is pull to low. Only change the eeprom page size from 256 to 8, everything is ok.
Thanks all.


Top
 Profile  
 
 Post subject: Re: question about using at24c02 in at91lib1.4
PostPosted: Tue Jul 28, 2009 8:45 pm 
Offline

Joined: Tue Jul 28, 2009 8:37 pm
Posts: 2
Sir,
I need a code to access at24c02 connected with (8051).Please send me the code. I also generate the code but failed. I am sending that also. If you can correct it or send me the code. I will be thankful to you.

/* Program to write and then read (and dispay on lcd) data from at24c02 connected with at89s52*/
/////////////////////////////header files//////////////////////////////
#include<reg51.h>
#include<absacc.h>

////////////////////////////read/write///////////////////////////
#ifndef READ
#define READ 1
#endif
#ifndef WRITE
#define WRITE 0
#endif


//////////////////////////// sda and scl ports/////////////////////////
sbit SDA=P2^1;
sbit SCL=P2^0;

////////////////////////////lcd ports/////////////////////////////////
sbit rs=P1^2;
sbit rw=P1^3;
sbit en=P1^4;

/////////////////////////// lcd fon prototypes///////////////////////
void startlcd();
void delay(unsigned char value);
void lcdWrite(unsigned char value,bit x);

//////////////////////////// sda scl elated funtion prototypes///////
void I2CBitDly(void);
void I2CSCLHigh(void);
void I2CSendAddr(unsigned char addr, unsigned char rd);
void I2CSendByte(unsigned char bt);
unsigned char I2CGetByte(unsigned char lastone);
void I2CSendStart(void);
void I2CSendStop(void);

///////////////////////////////main body////////////////////////////
void main (void){
unsigned char chr=0x61, chr1 ;

/// Set up the serial ports///
PCON =0x00;
PCON |=0x80;
SCON = 0x50; // SCON: mode 1, 8-bit UART, enable rcvr
TMOD = 0x20; // TMOD: timer 1, mode 2, 8-bit reload
TH1=0xFE; //TL0 = (unsigned int)(256 - ( (XtalFreq / BaudRate) / 192));
TR0=1;
TR1 = 1; // TR1: timer 1 run
TI = 1; // TI: set TI to send first char of UART

///send data///
I2CSendAddr(10100110,WRITE);
I2CSendByte(2); ///address
I2CSendByte(chr);
I2CSendStop();
I2CBitDly();

///reading///
I2CSendAddr(10100110,WRITE);
I2CSendByte(2); ///address
I2CSendAddr(10100110,READ);
chr1 = I2CGetByte(1);
I2CSendStop();

///dispay on lcd///
startlcd();
lcdWrite(chr1,1);
}

void I2CBitDly(void){ // wait approximately 4.7uS
// tune to xtal. This works at 11.0592MHz
unsigned int time_end = 10;
unsigned int index;
for (index = 0; index < time_end; index++);
return;
}

void I2CSCLHigh(void){ // Set SCL high, and wait for it to go high
register int err;
SCL = 1;
while (! SCL)
{
err++;
if (!err)
{
return;
}
}
}

void I2CSendAddr(unsigned char addr, unsigned char rd)
{
I2CSendStart();
I2CSendByte(addr+rd); // send address byte
}

void I2CSendByte(unsigned char bt){
register unsigned char i;
for (i=0; i<8; i++)
{
if (bt & 0x80) SDA = 1; // Send each bit, MSB first changed 0x80 to 0x01
else SDA = 0;
I2CSCLHigh();
I2CBitDly();
SCL = 0;
I2CBitDly();
bt = bt << 1;
}
SDA = 1; // Check for ACK
I2CBitDly();
I2CSCLHigh();
I2CBitDly();
if (SDA)
SCL = 0;
I2CBitDly();
SDA = 1; // end transmission
SCL = 1;
}

unsigned char I2CGetByte(unsigned char lastone){ // last one == 1 for last byte; 0 for any other byte
register unsigned char i, res;
res = 0;
for (i=0;i<8;i++) // Each bit at a time, MSB first
{
I2CSCLHigh();
I2CBitDly();
res *= 2;
if (SDA) res++;
SCL = 0;
I2CBitDly();
}
SDA = lastone; // Send ACK according to 'lastone'
I2CSCLHigh();
I2CBitDly();
SCL = 0;
SDA = 1; // end transmission
SCL=1;
I2CBitDly();
return(res);
}

void I2CSendStart(void)
{
SCL = 1;
I2CBitDly();
SDA = 0;
I2CBitDly();
SCL = 0;
I2CBitDly();
}

void I2CSendStop(void)
{
SDA = 0;
I2CBitDly();
SCL = 1;
I2CBitDly();
SDA = 1;
I2CBitDly();
}

void delay(unsigned char value){
unsigned int x,y;
for(x=0;x<1275;x++)
for(y=0;y<value;y++);
}

void lcdWrite(unsigned char value,bit x){
delay(4);
P0=value;
rs=x;
rw=0;
en=0;
delay(1);
en=1;
return;
}

void startlcd(){
lcdWrite(0x38,0);
lcdWrite(0x0E,0);
lcdWrite(0x01,0);
}


Top
 Profile  
 
 Post subject: Re: question about using at24c02 in at91lib1.4
PostPosted: Wed Jul 29, 2009 11:15 am 
Offline

Joined: Tue Jul 28, 2009 8:37 pm
Posts: 2
please help me i am waiting for your response


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 25 guests


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 post attachments in this forum

Search for:
Jump to: