Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

MCP79520 RTC over SPI with Bascom

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> Share your working BASCOM-AVR code here
View previous topic :: View next topic  
Author Message
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 971

poland.gif
PostPosted: Thu Oct 22, 2020 4:27 pm    Post subject: MCP79520 RTC over SPI with Bascom Reply with quote

Hello.
This is the basic example of handling this RTC with the Bascom syntax like $Tme & $Date
It work over SPI not I2C.



Chip have 64Bytes of battery keeped/powered RAM and some Eeprom.
It can tell when power was down and when it rise up again.
Ofcourse two alarms are also available.
Can be digitaly calibrated by one register.
Back to top
View user's profile Visit poster's website
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5915
Location: Holland

blank.gif
PostPosted: Fri Oct 23, 2020 12:08 pm    Post subject: Reply with quote

Excellent work EDC.
Thanks for sharing your work.
I see the attachment is complete with PDF and code.

If you dont mind i add it to the bascom samples.

_________________
Mark
Back to top
View user's profile Visit poster's website
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 971

poland.gif
PostPosted: Fri Oct 23, 2020 10:36 pm    Post subject: Reply with quote

Okay. ::::::Very Happy
I need it and must use it ...and with bascom it was easy Very Happy
Back to top
View user's profile Visit poster's website
Duval JP

Bascom Member



Joined: 22 Jun 2004
Posts: 1161
Location: France

france.gif
PostPosted: Sat Oct 24, 2020 10:09 am    Post subject: Reply with quote

Hi EDC
I use DS3231 with internal cristal. It is a TCXO (very higt precision ) and I2C connexion (2 wires and it lets SPI for AVRdos or others) Why did you prefer yours ?
I'm only curious
JP
Wink

_________________
pleasure to learn, to teach, to create
Back to top
View user's profile Visit poster's website
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 971

poland.gif
PostPosted: Sun Oct 25, 2020 7:28 am    Post subject: Reply with quote

Cause my AVR device is also I2C slave. In this project Im also using AVR-DOS and W5500 Ethernet chip so..for SPI it is not a problem...
Back to top
View user's profile Visit poster's website
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 971

poland.gif
PostPosted: Wed Nov 24, 2021 8:51 pm    Post subject: Reply with quote

For reasons beyond my control, I had to postpone the project using this RTC.
Now Im working wit it again and one very interesting issue came out.
This RTC dont work on battery hahahahaha Very Happy

Third bit of DayOfWeek byte must be set to join battery with RTC. This bit is disabled by default.
This is handy in some cases I think. You can install battery in your commercial device and ship it no worries about the battery.
Only when end user set the clock then battery will be joined with the clock.

This is made by this line -> "Rtc_buff(6) = Makebcd(day_of_week) Or &B0000_1000" so DayOfWeek must be send atleast once.

Corrected code below:
Code:
Settime:

  Rtc_buff(1) = Write_
  Rtc_buff(2) = &H01                                        'point to seconds
  Rtc_buff(3) = Makebcd(_sec) Or &B1000_0000                'bit 7 starts oscillator
  Rtc_buff(4) = Makebcd(_min)
  Rtc_buff(5) = Makebcd(_hour)
  Rtc_buff(6) = Makebcd(day_of_week) Or &B0000_1000         'bit 3 enables battery backup
  Reset Rtc_ss
   Spiout Rtc_buff(1) , 6
  Set Rtc_ss

Return
Back to top
View user's profile Visit poster's website
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5915
Location: Holland

blank.gif
PostPosted: Thu Nov 25, 2021 10:56 am    Post subject: Reply with quote

thanks for the update. indeed this is valuable info Very Happy
_________________
Mark
Back to top
View user's profile Visit poster's website
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 971

poland.gif
PostPosted: Mon Mar 11, 2024 11:53 pm    Post subject: Reply with quote

Since only this year February had 29 days and we have a leap year another small error came out.
The RTC itself recognizes such a year and sets bit 5 in the month register.
Therefore, it should be masked when reading it.

Code:
  _month = rtc_buff(6) And &B0001_1111                     'bit 5 is the read only leap year
  _month = Makedec(_month)

_________________
Check B-Flash -my MCS bootloader app for Android
Back to top
View user's profile Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> Share your working BASCOM-AVR code here All times are GMT + 1 Hour
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
You cannot attach files in this forum
You cannot download files in this forum