craigcurtin
Senior Member
Guys,
I have a picaxe 40x2 and an Arduino Mega operating together over i2c. I am migrating this particular project from my 40x2 to the Arduino platform.
Doing this in a staged approach - i made the Arduino the master of the i2c bus and the picaxe slave.
I have "passed" control of the DS1307 RTC from the picaxe to the Arduino, which now extracts and formats the time and passes it back through two variables in the scratchpad to the picaxe - all works as expected.
I am also passing some other scratchpad values back to the Arduino - these are being updated by the Picaxe based on sensor values it is reading.
Now my question(s)
I have a subroutine i call to get the time and this is where i define the i2cslave statements (as per below)
Does the hi2csetup survive the subroutine ending ? Or does the Picaxe slave "disappear" once this subroutine finishes ?
The reason that i ask is that when on the Arduino and reading the scratchpad that the Picaxe has updated - it appears every now and then i get a negative result i.e. the values returned are -1 (they are temperatures in C in Sydney so this an incorrect result)
Not sure if this is because in fact the Arduino can not get to the scratchpad sometimes or some other problem.
Also do i have to CLEAR the hi2cflag each time or is that just a convenience so i can poll the flag for any updates to the scratchpad (as these are times i just do this is a subroutine that is called each time through my main routine so accuracy to within 1 minute or so is fine.)
thanks
Craig
I have a picaxe 40x2 and an Arduino Mega operating together over i2c. I am migrating this particular project from my 40x2 to the Arduino platform.
Doing this in a staged approach - i made the Arduino the master of the i2c bus and the picaxe slave.
I have "passed" control of the DS1307 RTC from the picaxe to the Arduino, which now extracts and formats the time and passes it back through two variables in the scratchpad to the picaxe - all works as expected.
I am also passing some other scratchpad values back to the Arduino - these are being updated by the Picaxe based on sensor values it is reading.
Now my question(s)
I have a subroutine i call to get the time and this is where i define the i2cslave statements (as per below)
Code:
ReadTimeFromRTC:
{
hi2csetup i2cslave, 160 '80 on arduino because of the 7bit -v- 8bit
hi2cflag = 0 ' reset flag
get 0,Hours,Mins ' get last 2 bytes written - Hours and Minutes
Debug
'i2cslave %11010000, i2cslow, i2cbyte
'readi2c 0,(workvariable1,mins,hours)
'Convert to Decimal from BCD
'let workvariable1 = mins & %11110000 / 16 * 10
'let mins = mins & %00001111 + workvariable1
'let workvariable1 = hours & %11110000 / 16 * 10
'let hours = hours & %00001111 + workvariable1
Return
}
The reason that i ask is that when on the Arduino and reading the scratchpad that the Picaxe has updated - it appears every now and then i get a negative result i.e. the values returned are -1 (they are temperatures in C in Sydney so this an incorrect result)
Not sure if this is because in fact the Arduino can not get to the scratchpad sometimes or some other problem.
Also do i have to CLEAR the hi2cflag each time or is that just a convenience so i can poll the flag for any updates to the scratchpad (as these are times i just do this is a subroutine that is called each time through my main routine so accuracy to within 1 minute or so is fine.)
thanks
Craig