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

rtcc read variables

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



Joined: 24 Jan 2015
Posts: 63

View user's profile Send private message

rtcc read variables
PostPosted: Sat Nov 14, 2020 12:39 pm     Reply with quote

I use 18f47j53 rtcc following the example and its working correct. I can read and print the date as it should. However when i store each byte to ext. ram and then try to read, i get strange values.

Code:

writeByte24AA512(0x06,log_write_address,read_clock.tm_year);
// the same for mon,mday etc..
printf(usb_cdc_putc,"\n\r20%02u/%02u/%02u %02u:%02u:%02u",readByte24AA512(0x06,num*10),readByte24AA512(0x06,num*10+1),readByte24AA512(0x06,num*10+2),readByte24AA512(0x06,num*10+3),readByte24AA512(0x06,num*10+4),readByte24AA512(0x06,num*10+5));

Don't mind about addresses . They are ok.
That's what i get on terminal for example for date:
2020/11/14 20:32:10

20201/96/255 131:00:00
and values on memory
log 10: 201
log 11: 96
log 12: 255
log 13: 131
log 14: 0
log 15: 0

All values look int8, so where could the problem be?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: rtcc read variables
PostPosted: Sat Nov 14, 2020 1:55 pm     Reply with quote

nuclear__ wrote:

writeByte24AA512(0x06, log_write_address,read_clock.tm_year);

readByte24AA512(0x06, num*10),

Don't mind about addresses . They are ok.

Apparently you are using this driver here, in the Code Library:
http://www.ccsinfo.com/forum/viewtopic.php?t=23390

Where do you get that 0x06 is the i2c slave address for the 24AA512 ?
It is not. The base address is 0xA0. It says at the top of the driver:
Code:

#define baseAddress24AA512  0xA0
 

The 24AA512 data sheet is here:
http://ww1.microchip.com/downloads/en/DeviceDoc/21754M.pdf
Look at page 9. It says:
Quote:

5.0 Device Addressing

The control byte consists of a 4-bit control code; for the
24XX512 this is set as ‘1010’ binary for read and write
operations. The next three bits of the control byte are
the Chip Select bits (A2, A1 and A0).

'1010' is 0xA, and if the next 3 address bits are tied to ground, then
in 8-bit i2c address format, this gives 0xA0 for the device address.


Last edited by PCM programmer on Sat Nov 14, 2020 11:47 pm; edited 1 time in total
nuclear__



Joined: 24 Jan 2015
Posts: 63

View user's profile Send private message

PostPosted: Sat Nov 14, 2020 2:56 pm     Reply with quote

I'm confused.
You are right, I made this pcb years ago and now i have some time to play. I have address pins tied to Vdd. So base address should be 10101110 or 0xAE . However after changing all 06 with AE memory verification fails. It's working with 06. I can't remember why i put 06.........
I will change it again to 06 and search for that later. It's working, i can write and read bytes fine! Any suggestion for rtcc? I can see it has nothing to do with memory chip.
Having year 2000, even when i do:
Code:
printf(usb_cdc_putc, "%u", read_clock.tm_year);

I get 198.
If i try %Lu (just in case) compiler finds it invalid, so it's a byte.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Nov 15, 2020 1:06 am     Reply with quote

I tested it in hardware and it worked.

I used an 18F27J53 with CCS vs. 5.096. The program shown below
displayed the following on TeraTerm:
Quote:
2020/11/14 20:54:46

Test program:
Code:

#include <18F27J53.h>
#fuses INTRC_IO, NOWDT
#fuses SOSC_HIGH, RTCOSC_T1
#use delay(clock=4M)
#use rs232(baud=9600, UART1, ERRORS)

rtc_time_t Initialize_Time;

rtc_time_t read_clock;

//==============================
void main()
{
setup_rtc(RTC_ENABLE, 0);

Initialize_Time.tm_year = 20;   // 2020
Initialize_Time.tm_mon  = 11;   // November
Initialize_Time.tm_mday = 14;   // 14th
Initialize_Time.tm_wday = 6;    // Saturday
Initialize_Time.tm_hour = 20;   // 8 pm
Initialize_Time.tm_min  = 54;   // 54 minutes
Initialize_Time.tm_sec  = 46;   // 46 seconds

rtc_write(&Initialize_Time);

rtc_read(&read_clock);

printf("\n\r20%02u/%02u/%02u %02u:%02u:%02u",
       read_clock.tm_year,
       read_clock.tm_mon,
       read_clock.tm_mday,
       read_clock.tm_hour,
       read_clock.tm_min,
       read_clock.tm_sec);
       
while(TRUE);
}


If you can't make it work, post your compiler version and post your
test program.


Last edited by PCM programmer on Mon Nov 16, 2020 11:15 pm; edited 1 time in total
nuclear__



Joined: 24 Jan 2015
Posts: 63

View user's profile Send private message

PostPosted: Sun Nov 15, 2020 2:56 am     Reply with quote

Hi
This works. It doesn't work when i do that from a function.
if printf is in main its ok.
Here its not
Code:

void write_log()
{
   rtc_time_t write_clock, read_clock;
   get_time();
   log_write_address = readByte24AA512(0x06,0);
   writeByte24AA512(0x06,0,log_write_address+10);
   printf(usb_cdc_putc,"\n\ryear %u \r\n",read_clock.tm_year);
   writeByte24AA512(0x06,log_write_address,read_clock.tm_year);
   writeByte24AA512(0x06,log_write_address+1,read_clock.tm_mon);
   writeByte24AA512(0x06,log_write_address+2,read_clock.tm_mday);
   writeByte24AA512(0x06,log_write_address+3,read_clock.tm_hour);
   writeByte24AA512(0x06,log_write_address+4,read_clock.tm_min);
   writeByte24AA512(0x06,log_write_address+5,read_clock.tm_sec);
   printf(usb_cdc_putc,"\n\r20%02u/%02u/%02u %02u:%02u:%02u",read_clock.tm_year,read_clock.tm_mon,read_clock.tm_mday,read_clock.tm_hour,read_clock.tm_min,read_clock.tm_sec);


void get_time()
{
   rtc_time_t write_clock, read_clock;
   rtc_read(&read_clock);
   printf(usb_cdc_putc,"\n\r20%02u/%02u/%02u %02u:%02u:%02u",read_clock.tm_year,read_clock.tm_mon,read_clock.tm_mday,read_clock.tm_hour,read_clock.tm_min,read_clock.tm_sec);
   
}

void main()
........
rtc_time_t write_clock, read_clock;
setup_rtc(RTC_ENABLE,127);         //enables internal RTCC
rtc_read(&read_clock);        //reads clock value from RTCC
WHILE(TRUE)
{
     if (timer0==0)
     {
          rtc_read(&read_clock);
          get_time();
      }
}


So i should first understand some critical things . Its difficult to find in datasheet how this works
rtc_time_t write_clock, read_clock;
probably replicating in function write_log() is fault while in get_time is not.
Could you please explain?
v5.046
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Nov 15, 2020 3:14 am     Reply with quote

Your get_time() function loads the time into a read_clock structure
that is local to the get_time() function.
As soon as that function exits, that structure goes bye-bye.
You can't access it outside of the get_time() function.
Look up the difference between local and global variables.
nuclear__



Joined: 24 Jan 2015
Posts: 63

View user's profile Send private message

PostPosted: Sun Nov 15, 2020 3:51 am     Reply with quote

I was aware of differences and i always try to have them global since optimization is not my concern. Now you mention i understood that
rtc_time_t is a type of variable. Its working now.
Thank you !
i will try to make them global too.
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