I2C communication with DS3231
My first post and probably very basic but I cannot get an ACK from a I2COUT to the BS2Px.
My Picoscope 7 displays the SDA and SCL outputs with the proper Data but no SDA ACKs. Any suggestions would be greatly appreciated.
' HARDWARE ASSIGNMENTS FOR THE DS3231 MODULE
'-----------------------
SDA PIN 0 ' use PIN in place of CON The Pin argument for SDA automatically specifies the SCL pin
SCL PIN SDA + 1 ' use PIN in place of CON
LED PIN 2 ' Define OUTPUT PIN 2
' SOFTWARE ASSIGNMENTS:
'-----------------------
Address VAR Byte
temp VAR Byte
Seconds VAR Byte ' 0101 0110 is 56 seconds BCD
Minutes VAR Byte ' 0001 0101 is 15 minutes BCD
Hours VAR Byte ' 0001 0101 is 15 hours since bit 7 = 0 (24hr clock) BCD
Day VAR Byte ' 01 - 31 in BCD 0001 1000 = 18th of month BCD
Month VAR Byte ' 0001 0001 is 11th month BCD
Year VAR Byte ' 0001 0110 25
Seconds = $20
Minutes = $45
Hours = $16
Day = $05
Month = $04
Year = $25
Write_to_DS3231:
START:
I2COUT 0, $D0, $00, [$20, $45, $16, $05, $04, $25]
DEBUG "THE PROGRAM IS CYCLING", CR
PAUSE 1000
DEBUG CLS
GOTO START ' do it again
Comments
Can you provide screen cap so we can see what you see? I've never used the BS2p with the DS3231, but I have P1 and P2 libraries for it -- that chip is pretty easy to use.
Hope I have uploaded the screenshot correctly Jon - first for that too: A real novice here!
It appears that the Address 0x68 is sent as well as the seconds command and then all the data in Hex, but no ACKs.
Sean
Well that was impressive and very easy. I didn't know that the comments go here. I think that I have a lot to learn
Sean
It's a little tricky to see given the resolution of the image, but it looks to me like you're getting ACKS (SDA is low at rising edge of 9th clock). Maybe try a smaller packet (see below) and zoom in a bit on your screen. There seem to be markers (yellow rectangle) where the ACK bit should be. If you hover over them do you get any additional information?
I don't have a BS2p handy, so I ran this simple code on a Propeller 1 with my bit-banged I2C which runs about the same speed as BS2p I2C. This is the Propeller code.
...which is the equivalent to:
This is what it looks like on my logic analyzer. We're both getting $68 at the start because the LA is showing the slave address as a 7-bit value ($D0 >> 1 == $68).

So I was correct: you are getting ACKs (ACK is 0 in I2C). Now try a simple loop to see if the chip is running. Again, I don't have a BS2p to try this with, so you may have to make some adjustments.
Here's how I did it with the Propeller 1.
Note that the I2COUT and I2CIN commands of the BS2p hide a lot of details about I2C transactions.
This what the transaction looks like on my LA.
Your Logic analyser is very precise Jon. Even with magnification on mine I can't discern a gap between the SDA and the SCL during the Start, but since it is in the nanosecond range that may not be possible. I wondered if the DS3231 was receiving the Start Condition.
If I hover over the yellow blip the text reads no ACK for either address; command or data bytes. The text box is reading SDA high - no ACK over the 9th clock pulse.
I have never worked with the propellers and have no knowledge of their code requirements.
I did try a Bit Banging I2C workaround using "SHIFTOUT" but it would not trigger any ACKs either.
It occured to me that I may have a dud DS3231 Module (from Ali Express - should have ordered at least 2), but the onboard LED lights up and I have 1K pullup resistors on SDA and SCL.
I also thought that the DS3231 may require a Reset but if that were the case I would have thought that the data or clock line would be stuck low.
Interestingly, I can't get any ACKS from AVEML7700 light sensor module either.
Thanks for replying Jon.
Sean
It's a fair point: my normal logic analyzer is a Saleae which is a bit pricey. Since it is expensive, I don't take it on the road with me; I use one of these:
-- https://www.amazon.com/dp/B077LSG5P2
It's cheap and small, so I can keep a spare in my computer bag, and it works pretty well with a nifty piece of freeware called PulseView. Here's the capture from read transaction.
Don't be fooled by the Saleae Logic note in the device box; that what the $13 LA identifies as for PulseView. I promise, that trace was with the low-cost device.
During the COVID lockdowns I escaped to the free state of AZ for Thanksgiving with friends. I had one of these cheap logic analyzers with me and it allowed me to write a pixel driver for a forum friend -- even though I didn't have the particular pixels he was using. That made him happy, and me smile. Sometimes inexpensive tools will do the job.
Back to your DS3231... Why are you saying that you're not getting ACKs? It says in your last graphic Address ACK: 0 -- that's a valid ACK. Remember, I2C uses open-collector/drain connections so an ACK requires the device to pull SDA low. That seems to be what you're getting.
Regardless of what you see, did you try to run the little read loop to see if the seconds are changing? If you run that code and the seconds register doesn't change, you may have to clear the OSF bit in the status register. In my Propeller code, I do this whenever I connect to a DS3231. Here's that code from my DS3231 library for the Px:
Here's how I would attempt to do that in the BS2p
This code compiles, but I can't test it.