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

DS1305 NV RAM read/write

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



Joined: 08 Aug 2016
Posts: 22

View user's profile Send private message

DS1305 NV RAM read/write
PostPosted: Tue Jun 22, 2021 9:35 am     Reply with quote

I may be missing something and wanted input here before reporting as a bug, but in the DS1305 driver that is included with PIC-C (using 5.104 compiler)

The functions rtc_write_nvr and rtc_read_nvr appear to OR a 0x20 (write does 0xA0) - the upper most bit (0x80) should be high for a write and low for a read, but why does bit 5 need to be high? This excludes address 0x40 to 0x5F is there a reason or was this just an oversight?
_________________
“Computer science education cannot make anybody an expert programmer any more than studying brushes and pigment can make somebody an expert painter.”
- Eric S. Raymond
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jun 22, 2021 10:17 am     Reply with quote

It looks like someone was trying to put in a safety feature to prevent the user from over-writing the 0-0x1F block. They just did it wrong.
They should have tested the address.
Ttelmah



Joined: 11 Mar 2010
Posts: 19503

View user's profile Send private message

PostPosted: Tue Jun 22, 2021 11:59 am     Reply with quote

If you look the address byte is 0x20 to 0x7F for a read, and 0xA0 to 0xFF
for a write. Figure 2 Hex Address. So the OR makes sense. If this is on a
numeric value for the address to access.
TimothyCarter



Joined: 08 Aug 2016
Posts: 22

View user's profile Send private message

PostPosted: Tue Jun 22, 2021 3:27 pm     Reply with quote

Ttelmah, but if you OR 0x20 then you will skip addresses 0x40 to 0x5F which are still valid addresses; as PCM programmer points out, it should be an add 0x20, rather than an OR. That way you could start with address "0" which would get added to 0x20.
_________________
“Computer science education cannot make anybody an expert programmer any more than studying brushes and pigment can make somebody an expert painter.”
- Eric S. Raymond
TimothyCarter



Joined: 08 Aug 2016
Posts: 22

View user's profile Send private message

Work-around
PostPosted: Tue Jun 22, 2021 3:34 pm     Reply with quote

If anyone else has an issue with this, the work around is to not use the rtc_read_nvr and rtc_write_nvr functions and use the read_ds1305 and write_ds1305 respectively. The caveat is that you need to make absolutely sure that your code does not write to addresses 0-0x1F.
_________________
“Computer science education cannot make anybody an expert programmer any more than studying brushes and pigment can make somebody an expert painter.”
- Eric S. Raymond
Ttelmah



Joined: 11 Mar 2010
Posts: 19503

View user's profile Send private message

PostPosted: Tue Jun 22, 2021 10:52 pm     Reply with quote

That makes total sense.
The error should be pointed out to CCS
I'd say that the rtc_read_nvr should use something like a test for the incoming
address being>0x5F (returning an error if it is), and adding 0x20.
The write should do the same and add 0xa0.
TimothyCarter



Joined: 08 Aug 2016
Posts: 22

View user's profile Send private message

PostPosted: Wed Jun 23, 2021 12:41 pm     Reply with quote

and just like that CCS emailed me a fix this morning...
_________________
“Computer science education cannot make anybody an expert programmer any more than studying brushes and pigment can make somebody an expert painter.”
- Eric S. Raymond
Ttelmah



Joined: 11 Mar 2010
Posts: 19503

View user's profile Send private message

PostPosted: Thu Jun 24, 2021 12:11 am     Reply with quote

Don't get ne wrong, but this is the key to why the 'old hands' here, like
CCS.... Very Happy
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