LonelyWolf / stm32

STM32 stuff
The Unlicense
949 stars 496 forks source link

wrong time DS3231 #7

Closed dukykaetzchen closed 7 years ago

dukykaetzchen commented 8 years ago

Hello,

wonderful code, well done. There should be a small correction at The function "to Human readable Format"

hrf_date->Hours = raw_date->hours; and hrf_date->Year = raw_date->year + 2000;

otherwise both are in hexadecimal :) So my 2016 was 2010 with your code.

Maybe I messed up...but check yourself again because we are in the hex overflow year 16 :D

LonelyWolf commented 8 years ago

Wonderful code? This must be joke :) That was one of my first attempts on C and STM32. I'm wanted to try to work with I2C and DS3231 was the only I2C device I had that time. So I've ported my DS3231 library from AVR asm to C and it worked. Then I've connected LCD to devboard, drew a simple clock, said "WHOA, IT WORKS!" and forget about that stuff for a long time )))

As for year: I've looked at code and didn't see nothing wrong. Where did you see overflow? Take a look at datasheet, the year stored in BCD format. So for "2016" year the 06h register of DS3231 must contain 0x16 (22 in decimal). The high nibble stores year number ten's and the low nibble stores year number (digit from 0 to 9). 0x16 = 0b00010110. High nibble = 0b0001 (decimal 1) Low nibble = 0b0110 (decimal 6) So decimal year will be (0b0001 * 10) + (0b0110) = 10 + 6 = 16. In short: BCD value "0b00010110" represents decimal value "16".

PS: unfortunately at the current moment I do not have a STM32F1 processor to check the code and I'm to lazy to rewrite it for the L1/L4 :) But I'm pretty sure what year conversions are correct.

dukykaetzchen commented 8 years ago

I just wanted to butter you up. :D This code is usual like the code example in the old stm32 periph lib. There is an optimized version of the i2c code without wait states, check it out. Just checked the datasheet again and you're right, it's bcd coded. Haven't understood it until now. ;) Thanks for the help. I wanted to move to Low Energy STM Devices ,too. But not yet sure what to take.

LonelyWolf commented 8 years ago

The L1 is pretty simple. The L4 - awesome, but it's new and has not much code samples, if you don't afraid this, look at it. The L4 clocking system - just kicks ass. I2C is improved version from the F0 series, much human-friendly. And so on...