This article, written by Maurice Ribble, provided all I needed to know about programming the chip and reading it's registers. This article, and its large number of following questions/answers, can be found at. The best source of understanding that I have found is an archived article from Hobby Robotics titled "An I2C Bus Example Using the DS1307 Real-Time Clock". The chip itself is easy to use but requires some understanding of its internal programming and its I2C register assignments. Both projects required knowledge of real time (Month, Day, and Time). I have used this chip twice with an Arduino Uno: (1) To adjust the elevation angle of a pole mounted Solar array, and (2) To inject a specified amount of EM1 algae control solution into a grey water tank. It might be slowly breaking on the inside or something.Įdit: aha, found the downside - when you cut power at 3.3V, the RTC forgets what time it was despite the backup battery being present and charged. The datasheet says that the min for Vcc should be 4.5V, but it actually seems to work faster at 3.3V. I figure hey, the RTC has its own battery, maybe it's ignoring the 3.3V line and just using its internal reserves to talk? Nope, if you don't provide it with anything it'll refuse to chat. At 5V it took ~1060 microseconds, but with the RTC running off the 3.3V pin it took ~290 microseconds - more than 3x faster. #Real time clock with seconds codeThe particularly strange part, though, is that the thing I'm working on is time-critical, so I had code timing my communication with the RTC. Apparently, it works ok - the time seemed correct - so I guess that's nice. Then I decided, "What the heck, I'll put it on 3.3V and see what happens". I set it up so that this was running off of the Uno's 5V pin, and everything worked fine. I didn't realize that these were 5 volt devices, but I figured since I was prototyping on an Uno I could get the systems working together and then worry about getting 3.3V components. This modified function should work: Wire.write((B01000000 | decToBcd(hour) )) Using the binary value B01000000 and the bitwise OR operator, this should set the clock to output in 12-hour mode while also setting the original defined hour at the beginning of that example code. Since the hour is already converted to a binary from the function decToBcd(), I would just use a logical bitwise operator. This is the section that says "RUNNING THE FOLLOWING CODE WILL RESET THE TIME" : Wire.write(decToBcd(hour)) I would probably add it to line 35 of the second block of code where it is sending the hour value to the DS1307. To set the breakout board to 12-hour mode, you would just send a logic HIGH for bit 6 for the hour timekeeping register. They are just using the DC1307 in 24-hour mode. #Real time clock with seconds how toLooking at the example code from the bildr tutorial provided, it does not show how to set it. This is explained on page 8 of the datasheet. Looking at the datasheet for the breakout board, there is an option to set the mode as either 12 hour or 24 hours. Through this method, it is a little bit more complicated to set DS1307 to 12-hour mode. Setting Bit 6 for the Hour Timekeeper Register 0x02 if greater than 12 hours, subtract before displaying the hour variable if less than or equal to 12 hours, display 12 hour #Real time clock with seconds serialYou can write this statement around the line 48 in the first block of code from the bildr tutorial where the data is outputting to the serial monitor similar to this. I would write an additional variable to show that the time is either AM or PM. Just write the code to subtract 12 hours using an if/else statement if the value is greater than 11:59am in order to display the time as 12 hours. Using condition statements, you can display the data in "12-hour" mode. Through this method, you would just need to process the received values from the DS1307 to display as a 12 hour value without needing to change the hour register. There are two options to display the clock as a 12-hour mode using an Arduino: Tech Support Tips/Troubleshooting/Common Issues For the SQW pin, we recommend doing using a logic level converter since the GPIO for the Raspberry Pi is 3.3V. For the SQW pin, we recommend doing using a logic level converter or voltage divider since the I/O of the Arduino is 3.3V.įor a Raspberry Pi, you can remove the solder jumpers for the pull-up resistors so that you can just use the Raspberry Pi’s internal pull-up resistors. Otherwise, you might want to use a dedicated I2C logic level converter for the I2C pins =>. #Real time clock with seconds driversYou might be able to get away with just connecting the RTC to your 3.3V Arduino because of the open drain drivers =>. You would need to do some modifications before being able to use it with a 3.3V system. The supply voltage for the RTC DS1307 needs to have a 5V input so it is not directly compatible with a 3.3V device (like a 3.3V Arduino or a Raspberry Pi).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |