I2C PIC16F690 and RTC DS3231 help

ErnieM

Joined Apr 24, 2011
8,377
I2C has no minimum speed. You can debug it with a DVM. Or LED even.

Most important is to catch the ACK bit. No ACK, no joy.
 

Thread Starter

portreathbeach

Joined Mar 7, 2010
143
Thanks very much. Looking forward to experimenting with this. I suppose as soon as I get a working bit of code it will come in handy when talking to other i2c devices.

May even have a look at programming in C in MPLab X too! I've always programmed in assembly on my PIC projects, and know all the setup procedures to get things working, I suppose I just don't want to learn it all again, but I may take a look.
 

Thread Starter

portreathbeach

Joined Mar 7, 2010
143
OK. My Real Time Clock modules turned up today so I was eager to try out communicating with it.......

Success after a couple of attempts!

First I tried sending some data to the Control register of the DS3231 to turn on the 'square wave output pin' and set it to 1Hz. Nothing....Attached the scope and found I hadn't entered the correct address for the DS3231 into my program. Tried again.....Success.

I then tried doing a read from a register, which is a little more tricky. I set the program to loop around reading the 'Seconds' register from the DS3231 and output them on a PORT on my PIC. When running the program, PORT B counts from 0 to 9 in binary at 1 second intervals.


Thanks again for all the help people have given me here.


Craig
 

Thread Starter

portreathbeach

Joined Mar 7, 2010
143
I found the easiest way to check that it was working was to send the start condition, then the address of the DS3231, check the ack bit, send stop condition. I looped this over and over and scooped the two lines.

With the DS3231 not connected, the ack bit was obviously high. When connecting the DS4231, the ack bit changed to a 0........well it did after I had the correct address in the program ;)
 

sirch2

Joined Jan 21, 2013
1,037
Totally off-topic but I just noticed your username, I rented a house in Portreath close to the beach many, many years ago.

Sorry, just brought back memories and had to get that out there...
 

ErnieM

Joined Apr 24, 2011
8,377
I found the easiest way to check that it was working was to send the start condition, then the address of the DS3231, check the ack bit, send stop condition. I looped this over and over and scooped the two lines.
Well... since ACK is short for ACKNOWLEDGE, and is used to let the master know the slave is there and responding, all I can say is LDO. :D

I've noticed several "tutorials" for I2C that completely ignore the ACK bit as if it is completely unimportant. Well, that's only true as long as everything goes right.
 
Top