B4R Library DS3234 RTC

Here is a library using the SparkFun library for the DS3234 RTC.

B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'Public variables can be accessed from all modules.
    Public Serial1 As Serial
    Public rtc As DS3234
End Sub

Private Sub AppStart
    Serial1.Initialize(115200)
    Log("AppStart")
    
    'pin 5 For SPI CS
    rtc.Initialize(5)
    
    'set time in 24hr format
    rtc.SetTime1(0,22,23,2,14,1,19)
    'set to 12hr format
    rtc.Set12Hour(True)
    
    'Set alarm1
    rtc.Alarm1(0,45,14,18,False)
    'If alarm1 trips set interupt pin active
    rtc.AlarmInterrupt(True,False)
    'Check if alarm1 tripped and reset flag
    Log("Alarm tripped? ",rtc.AlarmStatus1(True))
    
    'Output a 1Hz square wave to interrupt pin
    rtc.EnableSQW(rtc.SQW_1Hz)
    
    'read SRAM location
    Log("sram 0x00: ",rtc.SRAMRead(0x00))
    'write SRAM location
    rtc.SRAMWrite(0x00,0xdd)
    'read SRAM location again
    Log("sram 0x00: ",rtc.SRAMRead(0x00))

    'Get time from RTC
    Log(rtc.Hour,":",rtc.Minute,":",rtc.Second," - ",rtc.Month,"/",rtc.Date,"/",rtc.Year)

End Sub
 

Attachments

  • rDS3234RTC.zip
    11.2 KB · Views: 421
Top