On page 11 of the data sheet it shows the register set up. I'm having trouble with register 02h which sets up the hours. The minutes, seconds, day, and date portions are working
I wrote this code to trouble shoot the hours portion:
And, the demos in your installation? See C:\GCB@Syn\GreatCowBasic\Demos\real_time_clock_solutions. There are many demos for the DS3231 and the documentation is in the directory C:\GCB@Syn\GreatCowBasic\Demos\real_time_clock_solutions\clocks
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Starting with the string.... the binary string of 01100011 is a numeric value of 1100011. So, know this we need to figure out what is going on.
This is caused by lots of little errors.
Use Option Explicit. This will start to reveal the issues. As you are NOT using Option explicit everything is assummed to by a Byte.
When Time_Hour as Long. As the string 1100011 is a lomg number, using the VAL32 method you get the correct result.
Str:01100011Val32:1100011
So, I would not be using a string to handle binary byte values.....
My proof code.
#chip18F47K42#optionExplicit'USART settings #define USART_BAUD_RATE 9600 #define USART_TX_BLOCKING 'GeneratedbyPICPPSToolforGreatCowBasic'PPS Tool version: 0.0.5.26 'PinManagerdata:v1.76'Generated for 18F47K42 ''Template comment at the start of the config file '#startupInitPPS,85#definePPSToolPart18F47K42SubInitPPS'Module: UART pin directions Dir PORTC.6 Out 'MakeTX1pinanoutput'Module: UART1 RC6PPS = 0x0013 'TX1>RC6EndSub'Template comment at the end of the config file Dim HourSTR, Time_HourSTR, Hour_12_24_PM_AM_STR as String Dim Hour as word Dim Time_Hour as long do 'Thebelow2commandsshouldproduceb01100011which=99indecimalOR3PMin12hourmodeHour_12_24_PM_AM_STR="011";Bit7=0,Bit6is12Hour=1&24Hour=0,Bit5isPM=1&Am=0Hour=3;1-9Hour=DecToBcd_GCB(Hour);PerDatasheetthetimeportionmustbeinBCDformatTime_HourSTR=Hour_12_24_PM_AM_STR+Right(ByteToBin(Hour),5)HSerPrint"Str :"hserprintTime_HourSTR;Shouldprintout01100011anditdoesHSerPrintCRLFHSerPrint"Val32: "Time_Hour=Val32(Time_HourSTR)hserprintTime_HourHSerPrintCRLFwait1sloop
Last edit: Anobium 2019-09-02
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm using this RTC https://www.adafruit.com/product/3028 module.
This is the data sheet https://datasheets.maximintegrated.com/en/ds/DS3231.pdf for the IC.
On page 11 of the data sheet it shows the register set up. I'm having trouble with register 02h which sets up the hours. The minutes, seconds, day, and date portions are working
I wrote this code to trouble shoot the hours portion:
I thought the line Time_Hour = Val(Time_HourSTR)
would convert 01100011 to 99. It doesn't. I get 235..
Any ideas?
Last edit: Anobium 2019-09-01
Why not start with the DS3231 library? See http://gcbasic.sourceforge.net/help/_libraries_overview.html
And, the demos in your installation? See C:\GCB@Syn\GreatCowBasic\Demos\real_time_clock_solutions. There are many demos for the DS3231 and the documentation is in the directory C:\GCB@Syn\GreatCowBasic\Demos\real_time_clock_solutions\clocks
Thanks! I'll try these.
I'm still curious why the code I wrote did not work. Any idea?
Starting with the string.... the binary string of
01100011
is a numeric value of1100011
. So, know this we need to figure out what is going on.This is caused by lots of little errors.
Use Option Explicit. This will start to reveal the issues. As you are NOT using Option explicit everything is assummed to by a Byte.
When Time_Hour as Long. As the string
1100011
is a lomg number, using the VAL32 method you get the correct result.So, I would not be using a string to handle binary byte values.....
My proof code.
Last edit: Anobium 2019-09-02