Adrunio as I2c slave

wagp

New Member
Can someone tell me how to use a Picaxe 40x2 as the master on an I2C bus with an Adrunio as the slave.
I can write to the Adrunio, but can't read from the Ardunio.

Any help would be appreciated.

Thanks
 

Buzby

Senior Member
Is an 'Adrunio' something like an 'Arduino' ?

If so, the I2C Slave code for an Arduino should work.

Please post your code for both devices.
There are some clever folks on this forum, but I don't think any of them can read your code without a Crystal Ball.
 

g6ejd

Senior Member
#include <Wire.h>

In your Arduino:
#define SLAVE_ADDRESS 0x29 // e.g. slave address,any number from 0x01 to 0x7F

void setup()
{
Wire.begin(SLAVE_ADDRESS);
}

{
// Then in main body send your data to your PICAXE master
}

OR

#include <Wire.h>

void setup()
{
Wire.begin(2); // join i2c bus with address #2
Wire.onRequest(requestEvent); // register event
}

void loop()
{
delay(100);
}

// function that executes whenever data is requested by master
// this function is registered as an event, see setup()
void requestEvent()
{
Wire.write("hello "); // respond with message of 6 bytes
// as expected by master
}
 

nick12ab

Senior Member
Note that Arduino uses the 7-bit address so you will need to shift all the bits left by one when specifying that address in the hi2csetup command.
 

westaust55

Moderator
In your Arduino:
#define SLAVE_ADDRESS 0x29 // e.g. slave address,any number from 0x01 to 0x7F

It is noted that the OP is using a 40X2, however, for consistency across the PICAXE range and taking into account the i2c address limitations applicable to at least the PICAXE 20X2 parts, it would be preferable to avoid i2c slave addresses $00, $01 and $02. Otherwise if someone clones the code for a 20X2 at a future date there is the likelihood of a post saying &#8220;it doesn't work for my 20X2&#8221;.

See section 4.4 in the PIC18(L)F1XK22 Family
Silicon Errata and Data Sheet Clarification here:
http://ww1.microchip.com/downloads/en/DeviceDoc/80437F.pdf

Specifically:
4.4 SSPADD Invalid Values
In I2C Master mode, SSPADD values of 0x00, 0x01, 0x02 are invalid.
The current I2C Baud Rate Generator (BRG) is not set up to generate a clock signal for these values.
 
Last edited:
Top