20 May 2010

Minor Project - external EEPROM management: software from Nicholas Zambetti; his WIRE library


This is the wire library!


Some very nice & simple stuff from Nicholas Zambetti.
Just needs adapting for what i want - which isn't complicated..


/*
Wire Master Writer by Nicholas Zambetti

Demonstrates use of the Wire library
Writes data to an I2C/TWI slave device
Refer to the "Wire Slave Receiver" example for use with this
*/

#include Wire.h

void setup()
{
Wire.begin(); // join i2c bus (address optional for master)
}//setup()

byte x = 0;

void loop()
{
Wire.beginTransmission(4); // transmit to device #4
Wire.send("x is "); // sends five bytes
Wire.send(x); // sends one byte
Wire.endTransmission(); // stop transmitting

x++;
delay(500);
}//loop()

//==============================================

/*
Wire Slave Receiver by Nicholas Zambetti

Demonstrates use of the Wire library
Receives data as an I2C/TWI slave device
Refer to the "Wire Master Writer" example for use with this
*/
#include Wire.h

void setup()
{
Wire.begin(4); // join i2c bus with address #4
Wire.onReceive(receiveEvent); // register event
Serial.begin(9600); // start serial for output
}//setup()

void loop()
{
delay(100);
}//loop()

// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent(int howMany)
{
while(1 < c =" Wire.receive();" x =" Wire.receive();">

//========================================

/*
Wire Master Reader by Nicholas Zambetti

Demonstrates use of the Wire library
Reads data from an I2C/TWI slave device
Refer to the "Wire Slave Sender" example for use with this

*/
#include Wire.h

void setup()
{
Wire.begin(); // join i2c bus (address optional for master)
Serial.begin(9600); // start serial for output
}// setup()

void loop()
{
Wire.requestFrom(2, 6); // request 6 bytes from slave device #2

while(Wire.available()) // slave may send less than requested
{
char c = Wire.receive(); // receive a byte as character
Serial.print(c); // print the character
}//while()

delay(500);
}//loop()

//===========================================

/*
Wire Slave Sender by Nicholas Zambetti

Demonstrates use of the Wire library
Sends data as an I2C/TWI slave device
Refer to the "Wire Master Reader" example for use with this
*/
#include Wire.h

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

void loop()
{
delay(100);
}//loop()

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


//*****************************************************SEE VERY IMPORTANT COMMENT BELOW

1 comment:

  1. VERY IMPORTANT!!
    In the above codings there are
    #include Wire.h
    statements.
    Around the Wire.h there should be 'less-than' &
    'greater-than' symbols.
    these don't show up in these blog postings..
    ..don't forget them!

    ReplyDelete