View previous topic :: View next topic |
Author |
Message |
TimothyCarter
Joined: 08 Aug 2016 Posts: 22
|
DS1305 NV RAM read/write |
Posted: Tue Jun 22, 2021 9:35 am |
|
|
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
|
|
Posted: Tue Jun 22, 2021 10:17 am |
|
|
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
|
|
Posted: Tue Jun 22, 2021 11:59 am |
|
|
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
|
|
Posted: Tue Jun 22, 2021 3:27 pm |
|
|
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
|
Work-around |
Posted: Tue Jun 22, 2021 3:34 pm |
|
|
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
|
|
Posted: Tue Jun 22, 2021 10:52 pm |
|
|
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
|
|
Posted: Wed Jun 23, 2021 12:41 pm |
|
|
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
|
|
Posted: Thu Jun 24, 2021 12:11 am |
|
|
Don't get ne wrong, but this is the key to why the 'old hands' here, like
CCS.... |
|
|
|