Go Down

Topic: i2c and a Dallas RTC Anyone?? (Read 4067 times) previous topic - next topic

Gonzillaaa

yep, that's done the trick. One final thing if I'm setting the hour to be 6, how do I know if its am or pm? or how can I set it to be 18:00 instead of 6?

Many thanks,

bluesterror

#16
Jul 02, 2007, 08:16 pm Last Edit: Jul 02, 2007, 08:17 pm by bluesterror Reason: 1
Quote
yep, that's done the trick. One final thing if I'm setting the hour to be 6, how do I know if its am or pm? or how can I set it to be 18:00 instead of 6?


That's what the high bits of the hour are for.  From the datasheet, you have in the top nibble: bit 2 selects 12 or 24 hour time, bit 1 is either the am/pm indicator or the high bit of the 24 hour time.

So use (0x40 | your_time) for 24-hour, or ( ((is_am) ? 0 : 0x02) | your_time) for am/pm mode.

libhart

I also thought about getting this to drive a clock and be very hands off, and for me that means adjusting for DST so once set I shouldn't have to touch it.  I've written code that barely fits into an ATMEGA8 that adjusts automatically for DST in the US...granted that you can't set the time w/the code, the 1307 has to already have your standard time in it, but it's pretty neat I think nonetheless.  Of course you could just use a in input and flip a switch to tell the arduino to adjust or not, but this is all in software and automagic.

bluesterror

Quote

So use (0x40 | your_time) for 24-hour, or ( ((is_am) ? 0 : 0x02) | your_time) for am/pm mode.


This is some really bad advice btw.  I need to go back to bit shifting school.

24 hour mode: just use your_hour with no ORs (bit 6 - 0=24 hr, 1=12 hr)
12 hour mode: use -
   0x40 | ((is_am) ?  0 : 0x20) | your_hour

your_hour should be binary-coded decimal (so 0x13 == 1pm in 24 hour mode).

bluesterror

Quote
I also thought about getting this to drive a clock and be very hands off, and for me that means adjusting for DST so once set I shouldn't have to touch it.


Nice!

lucasvickers

So when using the Wire library you need to manually hook up a pull-up resistor.  I was playing around with the digital lines trying to use the internal pullup resistors and get the I2C communication going myself.  I could never even get the first ACK.

Why is the Wire library on the analog lines?  Is there something I am missing in regards to the complexity of communication over an I2C interface with arduino?

Do any of you know of any successful attempts at a wire type library using the digital lines?

Thanks!
Lucas

gazzy

I think to use I2C you have to use the analogue pins 4 and 5. if you look at the pin descriptions http://www.arduino.cc/en/Hacking/Atmega168Hardware you can see SCL and SDA are there. Maybe i'm wrong though and it is possible to use the digital pins.

lucasvickers

yes - found out those pins you get hardware support.
I'm going to attempt to code it all myself on the digital pins because I wanna learn!

Cheater

Quote
So when using the Wire library you need to manually hook up a pull-up resistor.  I was playing around with the digital lines trying to use the internal pullup resistors and get the I2C communication going myself.  I could never even get the first ACK.

Why is the Wire library on the analog lines?  Is there something I am missing in regards to the complexity of communication over an I2C interface with arduino?

I2C requires the external pull up resistors. Its not a Arduino thing.

I'd advise against trying to do I2C manually. Its not simple especially when compared with SPI.

I2C uses the analog pins because thats just where the required hardware is.
The analog pins are actually normal digital pins with analog functionality. Elsewhere on these forums explains how to use them as digital I/O.

lucasvickers

Arduino has internal pullup resistors!  not on those pins tho.  do they not work for I2C?

Cheater

Not entirely sure how it works. Its not exactly difficult to throw in your own pull ups though so no reason not to.

Go Up