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 CCS Technical Support

how to use DS1307 RAM area 0x08 ... 0x3F ?

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



Joined: 17 Nov 2011
Posts: 187

View user's profile Send private message Send e-mail

how to use DS1307 RAM area 0x08 ... 0x3F ?
PostPosted: Mon Dec 19, 2011 11:05 am     Reply with quote

I'm trying to get DS1307 external RAM to work ... but no success!
real time clock (RTC) works fine but no success to get
RAM work ...
I want to use RAM while RTC is working background

pls help

Smile
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Dec 19, 2011 12:54 pm     Reply with quote

Are you using this ds1307 driver from the Code Library ?
http://www.ccsinfo.com/forum/viewtopic.php?t=23255

If so, the following routines can be used to read/write NVRAM.
They are written in the same way as the routines in the link above,
so you can just add them to that driver file.

Remember that NVRAM starts at address 0x08.
Code:

// Read one byte from the DS1307.

int8 ds1307_read_byte(int8 addr)
{
int8 retval;

i2c_start();
i2c_write(0xD0);
i2c_write(addr);   
i2c_start();    // Re-start
i2c_write(0xD1);
retval = i2c_read(0);       
i2c_stop();

return(retval);
}

//-------------------------------------------------------------
// Write one byte to the DS1307.

void ds1307_write_byte(int8 addr, int8 data)
{
i2c_start();
i2c_write(0xD0);
i2c_write(addr);
i2c_write(data);
i2c_stop();
}
artohautala



Joined: 17 Nov 2011
Posts: 187

View user's profile Send private message Send e-mail

PostPosted: Mon Dec 19, 2011 1:39 pm     Reply with quote

thanks for your good answer...

yep I'm using that ds1307 driver and I know starting address 0x80 OK
retval = i2c_read(0); why not retval = i2c_read(); ?

but what's wrong with my code:

Code:

void rtc_memtest(void)
{

//BEFORE THIS DS1307 INITIALIZED AND REAL TIME CLOCK WORKS FINE

BYTE addr,data,read_data;

read_data = 0;

data = 50;
addr = 0x50; //THIS WORKS BUT IN DA1307 THERE IS NO SUCH ADDRESS!!! WHY!


// do not care for test purposes read_data = 0; //kirjoitetaan data muistipaikkoihin:

//for(addr = 0x08; addr<0x30;addr++) //do not care for test purposes //osoite 0x08 ... 0x3f
rw_rtcram(addr,data);
delay_ms(100);
// do not care for test purposes //luetaan data muistipaikoista:

//for(addr = 0x08; addr<0x30;addr++) //osoite 0x08 ... 0x3f
//{
read_data = read_rtcram(addr); //do not care for test purposes //luetaan data

//read_data = 21;
//data = 21;

if(read_data != data)
{
clear_text();clearTextBuffer();strcpy(teksti,"dataerror"); text_xy(0,3);text(teksti);
return;
}
//}

if(read_data == data)
{
clearTextBuffer();clear_text();
clearTextBuffer();strcpy(teksti,"memtest OK!"); text_xy(0,3);text(teksti);
}

}


void rw_rtcram(BYTE addr,BYTE data) //write to RTC RAM, addr 0x08 ... 0x3f
{
//write data to DS1307 RAM area:
i2c_start();
i2c_write(0xD0); // I2C write address
i2c_write(addr); // address
i2c_write(data); // data
i2c_stop();
}


BYTE read_rtcram(BYTE addr) //read from RTC RAM, address 0x08 ... 0x3f
{

BYTE read_data;

i2c_start();
i2c_write(0xD0); //DS1307 I2C - address
i2c_write(addr); //recister 0x08 ... 0x3f address
i2c_start();
i2c_write(0xD1); // set to read
read_data = i2c_read(); //read data
i2c_stop();
return read_data;
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Dec 19, 2011 1:52 pm     Reply with quote

Quote:
yep I'm using that ds1307 driver and I know starting address 0x80 OK

Wrong. I said it starts at 0x08.

Quote:

retval = i2c_read(0); why not retval = i2c_read(); ?

It's required. It's part of the i2c specification. Look at the bottom of
page 10. Read item #5 in the list:
http://www.nxp.com/documents/user_manual/UM10204.pdf

Quote:
but what's wrong with my code:

You are missing the NACK in the i2c_read. You didn't like the code I
posted, so you re-wrote it and it failed.


Quote:
addr = 0x50; //THIS WORKS BUT IN DA1307 THERE IS NO SUCH ADDRESS!!! WHY!

It's likely that the address is wrapping around. The ds1307 (not "DA")
likely just ignores the upper two bits and the address wraps.
artohautala



Joined: 17 Nov 2011
Posts: 187

View user's profile Send private message Send e-mail

PostPosted: Mon Dec 19, 2011 2:28 pm     Reply with quote

Quote:
Wrong. I said it starts at 0x08.


sorry typing error

sure it is 0x08 not 0x80 !
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