Pages: 1 [2]   Go Down
Author Topic: i2c and a Dallas RTC Anyone??  (Read 3419 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 12
I Love YaBB 2!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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,
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: July 02, 2007, 01:17:12 pm by bluesterror » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 38
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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).
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
Logged

new york
Offline Offline
Newbie
*
Karma: 0
Posts: 45
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 5
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

new york
Offline Offline
Newbie
*
Karma: 0
Posts: 45
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
Logged

Brisbane, Australia
Offline Offline
God Member
*****
Karma: 1
Posts: 593
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

new york
Offline Offline
Newbie
*
Karma: 0
Posts: 45
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Brisbane, Australia
Offline Offline
God Member
*****
Karma: 1
Posts: 593
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: 1 [2]   Go Up
Jump to: