Bs2P interfaced with a Chronodot
Does anyone have example code to interface/communicate between the BS2p and the chronodot?
I am attepting to set up a clock with a Bs2p, but am having trouble with any...even simple...communication using the I2c command.
My setup is as follows....
Basic Stamp Chronodot
VSS
Ground
VDD
VCC
P0
SDA
P1
SCL
All other Chronodot connections (on the left of the dot) are not connected...
I have 2 resistors (4.7k ohm) soldered into the R1 and R2 positions.
My simple attempt at communication has been along the lines of...
value Var Word
I2cout 000000, 0, [30]
I2cin 000001,0, [value]
debug ? value
Value=255
What am I missing or doing wrong?
I am attepting to set up a clock with a Bs2p, but am having trouble with any...even simple...communication using the I2c command.
My setup is as follows....
Basic Stamp Chronodot
VSS
Ground
VDD
VCC
P0
SDA
P1
SCL
All other Chronodot connections (on the left of the dot) are not connected...
I have 2 resistors (4.7k ohm) soldered into the R1 and R2 positions.
My simple attempt at communication has been along the lines of...
value Var Word
I2cout 000000, 0, [30]
I2cin 000001,0, [value]
debug ? value
Value=255
What am I missing or doing wrong?
Comments
It would help any that respond to see the complete program listing. Can you upload it please?
Below is the actual code I'm using. I found that I had neglected to set the pin value in the I2cin and I2Cout commands. I set it to "0" and got it to count up from the initial set value of 30...
I then placed a ' to REM the I2Cout, and it appears to be counting up for me.
I find this to be promising...
Any pitfalls I should watch out for as I progress?
' {$STAMP BS2p}
' {$PBASIC 2.5}
Seconds VAR Word
Minutes VAR Word
Hours VAR Word
' 'I2COUT 0, %11010000, 0, [30]
start:
DEBUG CLS
I2CIN 0, %11010001, 0, [seconds]
I2CIN 0, %11010001, 1, [Minutes]
I2CIN 0, %11010001, 2, [Hours]
DEBUG HEX2 Hours, ":",HEX2 minutes, ":", HEX2 Seconds
PAUSE 1000
GOTO start
[COLOR=#808080][I]#include <Wire.h>[/I][/COLOR] [COLOR=#993333]void[/COLOR] setup[COLOR=#66CC66]([/COLOR][COLOR=#66CC66])[/COLOR][COLOR=#66CC66]{[/COLOR] Wire.[COLOR=#006600]begin[/COLOR][COLOR=#66CC66]([/COLOR][COLOR=#66CC66])[/COLOR]; Serial.[COLOR=#006600]begin[/COLOR][COLOR=#66CC66]([/COLOR][COLOR=#CC66CC]9600[/COLOR][COLOR=#66CC66])[/COLOR]; [COLOR=#808080][I]// clear /EOSC bit[/I][/COLOR] [COLOR=#808080][I]// Sometimes necessary to ensure that the clock[/I][/COLOR] [COLOR=#808080][I]// keeps running on just battery power. Once set,[/I][/COLOR] [COLOR=#808080][I]// it shouldn't need to be reset but it's a good[/I][/COLOR] [COLOR=#808080][I]// idea to make sure.[/I][/COLOR] Wire.[COLOR=#006600]beginTransmission[/COLOR][COLOR=#66CC66]([/COLOR]0x68[COLOR=#66CC66])[/COLOR]; [COLOR=#808080][I]// address DS3231[/I][/COLOR] Wire.[COLOR=#006600]write[/COLOR][COLOR=#66CC66]([/COLOR]0x0E[COLOR=#66CC66])[/COLOR]; [COLOR=#808080][I]// select register[/I][/COLOR] Wire.[COLOR=#006600]write[/COLOR][COLOR=#66CC66]([/COLOR]0b00011100[COLOR=#66CC66])[/COLOR]; [COLOR=#808080][I]// write register bitmap, bit 7 is /EOSC[/I][/COLOR] Wire.[COLOR=#006600]endTransmission[/COLOR][COLOR=#66CC66]([/COLOR][COLOR=#66CC66])[/COLOR];[COLOR=#66CC66]}[/COLOR] [COLOR=#993333]void[/COLOR] loop[COLOR=#66CC66]([/COLOR][COLOR=#66CC66])[/COLOR][COLOR=#66CC66]{[/COLOR] [COLOR=#808080][I]// send request to receive data starting at register 0[/I][/COLOR] Wire.[COLOR=#006600]beginTransmission[/COLOR][COLOR=#66CC66]([/COLOR]0x68[COLOR=#66CC66])[/COLOR]; [COLOR=#808080][I]// 0x68 is DS3231 device address[/I][/COLOR] Wire.[COLOR=#006600]write[/COLOR][COLOR=#66CC66]([/COLOR][COLOR=#66CC66]([/COLOR]byte[COLOR=#66CC66])[/COLOR]0[COLOR=#66CC66])[/COLOR]; [COLOR=#808080][I]// start at register 0[/I][/COLOR] Wire.[COLOR=#006600]endTransmission[/COLOR][COLOR=#66CC66]([/COLOR][COLOR=#66CC66])[/COLOR]; Wire.[COLOR=#006600]requestFrom[/COLOR][COLOR=#66CC66]([/COLOR]0x68[COLOR=#66CC66],[/COLOR] [COLOR=#CC66CC]3[/COLOR][COLOR=#66CC66])[/COLOR]; [COLOR=#808080][I]// request three bytes (seconds, minutes, hours)[/I][/COLOR] [COLOR=#B1B100]while[/COLOR][COLOR=#66CC66]([/COLOR]Wire.[COLOR=#006600]available[/COLOR][COLOR=#66CC66]([/COLOR][COLOR=#66CC66])[/COLOR][COLOR=#66CC66])[/COLOR] [COLOR=#66CC66]{[/COLOR] [COLOR=#993333]int[/COLOR] seconds [COLOR=#66CC66]=[/COLOR] Wire.[COLOR=#006600]read[/COLOR][COLOR=#66CC66]([/COLOR][COLOR=#66CC66])[/COLOR]; [COLOR=#808080][I]// get seconds[/I][/COLOR] [COLOR=#993333]int[/COLOR] minutes [COLOR=#66CC66]=[/COLOR] Wire.[COLOR=#006600]read[/COLOR][COLOR=#66CC66]([/COLOR][COLOR=#66CC66])[/COLOR]; [COLOR=#808080][I]// get minutes[/I][/COLOR] [COLOR=#993333]int[/COLOR] hours [COLOR=#66CC66]=[/COLOR] Wire.[COLOR=#006600]read[/COLOR][COLOR=#66CC66]([/COLOR][COLOR=#66CC66])[/COLOR]; [COLOR=#808080][I]// get hours[/I][/COLOR] seconds [COLOR=#66CC66]=[/COLOR] [COLOR=#66CC66]([/COLOR][COLOR=#66CC66]([/COLOR][COLOR=#66CC66]([/COLOR]seconds [COLOR=#66CC66]&[/COLOR] 0b11110000[COLOR=#66CC66])[/COLOR][COLOR=#66CC66]>>[/COLOR][COLOR=#CC66CC]4[/COLOR][COLOR=#66CC66])[/COLOR][COLOR=#66CC66]*[/COLOR][COLOR=#CC66CC]10[/COLOR] [COLOR=#66CC66]+[/COLOR] [COLOR=#66CC66]([/COLOR]seconds [COLOR=#66CC66]&[/COLOR] 0b00001111[COLOR=#66CC66])[/COLOR][COLOR=#66CC66])[/COLOR]; [COLOR=#808080][I]// convert BCD to decimal[/I][/COLOR] minutes [COLOR=#66CC66]=[/COLOR] [COLOR=#66CC66]([/COLOR][COLOR=#66CC66]([/COLOR][COLOR=#66CC66]([/COLOR]minutes [COLOR=#66CC66]&[/COLOR] 0b11110000[COLOR=#66CC66])[/COLOR][COLOR=#66CC66]>>[/COLOR][COLOR=#CC66CC]4[/COLOR][COLOR=#66CC66])[/COLOR][COLOR=#66CC66]*[/COLOR][COLOR=#CC66CC]10[/COLOR] [COLOR=#66CC66]+[/COLOR] [COLOR=#66CC66]([/COLOR]minutes [COLOR=#66CC66]&[/COLOR] 0b00001111[COLOR=#66CC66])[/COLOR][COLOR=#66CC66])[/COLOR]; [COLOR=#808080][I]// convert BCD to decimal[/I][/COLOR] hours [COLOR=#66CC66]=[/COLOR] [COLOR=#66CC66]([/COLOR][COLOR=#66CC66]([/COLOR][COLOR=#66CC66]([/COLOR]hours [COLOR=#66CC66]&[/COLOR] 0b00100000[COLOR=#66CC66])[/COLOR][COLOR=#66CC66]>>[/COLOR][COLOR=#CC66CC]5[/COLOR][COLOR=#66CC66])[/COLOR][COLOR=#66CC66]*[/COLOR][COLOR=#CC66CC]20[/COLOR] [COLOR=#66CC66]+[/COLOR] [COLOR=#66CC66]([/COLOR][COLOR=#66CC66]([/COLOR]hours [COLOR=#66CC66]&[/COLOR] 0b00010000[COLOR=#66CC66])[/COLOR][COLOR=#66CC66]>>[/COLOR][COLOR=#CC66CC]4[/COLOR][COLOR=#66CC66])[/COLOR][COLOR=#66CC66]*[/COLOR][COLOR=#CC66CC]10[/COLOR] [COLOR=#66CC66]+[/COLOR] [COLOR=#66CC66]([/COLOR]hours [COLOR=#66CC66]&[/COLOR] 0b00001111[COLOR=#66CC66])[/COLOR][COLOR=#66CC66])[/COLOR]; [COLOR=#808080][I]// convert BCD to decimal (assume 24 hour mode)[/I][/COLOR] Serial.[COLOR=#006600]print[/COLOR][COLOR=#66CC66]([/COLOR]hours[COLOR=#66CC66])[/COLOR]; Serial.[COLOR=#006600]print[/COLOR][COLOR=#66CC66]([/COLOR][COLOR=#FF0000]":"[/COLOR][COLOR=#66CC66])[/COLOR]; Serial.[COLOR=#006600]print[/COLOR][COLOR=#66CC66]([/COLOR]minutes[COLOR=#66CC66])[/COLOR]; Serial.[COLOR=#006600]print[/COLOR][COLOR=#66CC66]([/COLOR][COLOR=#FF0000]":"[/COLOR][COLOR=#66CC66])[/COLOR]; Serial.[COLOR=#006600]println[/COLOR][COLOR=#66CC66]([/COLOR]seconds[COLOR=#66CC66])[/COLOR]; [COLOR=#66CC66]}[/COLOR] delay[COLOR=#66CC66]([/COLOR][COLOR=#CC66CC]1000[/COLOR][COLOR=#66CC66])[/COLOR]; [COLOR=#66CC66]}[/COLOR]
it looks like it is returning bytes not words. This might be your problem.