This is about robots & automation. It's a companion blog to JaneMareesTech, which is about the Arduino microcontroller system & related electronics
Showing posts with label TWI. Show all posts
Showing posts with label TWI. Show all posts
Saturday, October 22, 2011
Task 39 - using the I2C bus with EEPROM 24LC64: avoiding buffer overrun
..
Thursday, October 20, 2011
Task 38a - using the I2C bus with an EEPROM 24LC64 addressed differently
I've added a line to the earlier code coz i want to make it easier to change the device address.
In this particular case:
A0 is LOW;
A1 is HIGH;
A2 is LOW.
This device needs to be addressed as 0x52
(see code changes below)
etcetera..
& i've changed the input data just to make sure the program's doing what it should be doing..
char somedata[] = "Jane-Maree's EEPROM data"; // - 24 characters..
And this is what it does..
byte LCaddress = 0x51; // 24LC64 device address
A0 is HIGH;
A1 is LOW;
A2 is LOW.
..& this device needs to be addressed as 0x51..
..producing this ==}
i've got pikkies of the breadboard arrangement clearly (i hope) showing the connections to A0, A1, & A2.
Everything else is unchanged..
In this particular case:
A0 is LOW;
A1 is HIGH;
A2 is LOW.
This device needs to be addressed as 0x52
(see code changes below)
#include {Wire.h} // I2C library - usual brackets warning
byte LCaddress = 0x52; // 24LC64 device address
byte LCaddress = 0x52; // 24LC64 device address
:
:
// now write the char-string to the EEPROM - NOTE 0x52:address pin A1 is HIGH
i2c_eeprom_write_page(LCaddress, 0, (byte *)somedata, sizeof(somedata));
:i2c_eeprom_write_page(LCaddress, 0, (byte *)somedata, sizeof(somedata));
:
// now access the first address (0) from the memory
byte b = i2c_eeprom_read_byte(LCaddress, 0); //NOTE 0x52:address pin A1 is HIGH
:
:
addr++; //..next address &..
//..access next address from the memory.
b = i2c_eeprom_read_byte(LCaddress, addr); //NOTE 0x52:address pin A1 is HIGH
//..access next address from the memory.
b = i2c_eeprom_read_byte(LCaddress, addr); //NOTE 0x52:address pin A1 is HIGH
:
:etcetera..
& i've changed the input data just to make sure the program's doing what it should be doing..
char somedata[] = "Jane-Maree's EEPROM data"; // - 24 characters..
And this is what it does..
..& when i've written..
byte LCaddress = 0x51; // 24LC64 device address
..it's because..
A1 is LOW;
A2 is LOW.
..& this device needs to be addressed as 0x51..
..producing this ==}
i've got pikkies of the breadboard arrangement clearly (i hope) showing the connections to A0, A1, & A2.
Everything else is unchanged..
Wednesday, October 19, 2011
Task 38.1 - using the I2C bus with an EEPROM 24LC64: software edit
/*
* Project: eeprom_fromWeb
* Author: hkhijhe - tidied even more by Jane-Maree Howard
* Date: 01/10/2010
* Platform: Arduino 22
* Purpose: To demonstrate use of the I2C bus with an EEPROM 24LC64
- "You were issued with an eeprom 24LC64 IC.
- This is a TWI memory that you connect to SCL and SDA on the Arduino.
- Run the program from the blog.
- Show your code changes and the serial monitor output in your blog".
* Operation: Because this chip is I2C,
- it only uses Arduino analog pins 4 & 5 (SDA and SCL),
- and of course the power (5V) and GND.
- Connect as follows:
- Arduino pin 4 to EEPROM pin 5
- Arduino pin 5 to EEPROM pin 6
- Arduino 5V to EEPROM pin 8
- Arduino GND to EEPROM pin 1,2,3,4
- Be sure to leave pin 7 of the EEPROM open or tie it to GND,
- otherwise the EEPROM will be write protected.
- Include: Wire.h - the I2C library
- Declare: various i2c_eeprom_read.. i2c_eeprom_write.. procedures
- Setup(): Opens the Wire connection, the Serial connection,
- writes a char-string to the EEPROM, & prints heading
- NOTE: the char-string has length = 28
- Loop(): Reads from the EEPROM, & prints, one byte at a time, & repeats
*/
#include {Wire.h} //I2C library-usual brackets warning
void setup()
{
// a char-string of data to write to the EEPROM - 28 characters long!!
char someData[] = "this is data from the eeprom";
/*
char somedata[] = "this is Jane-Maree's eeprom data"; - 32 characters..
.. & it bombs. Gibberish - I've tried it! See WARNING below..
*/
Wire.begin(); // Wire connection initialised
Serial.begin(9600); // Serial connection @ 9600 baud
// now write the char-string to the EEPROM
i2c_eeprom_write_page(0x50, 0, (byte *)someData, sizeof(someData));
delay(10); //add a small delay..
// ..& print a heading
Serial.println("\nMemory written");
Serial.println("\nNow read memory & print to Serial port");
} //setup()
void loop()
{
int addr=0; // address parameter, starts @ 0
// now access the first address (0) from the memory
byte b = i2c_eeprom_read_byte(0x50, 0);
// while there are non-zero bytes..
while (b!=0)
{
Serial.print((char)b); //..print content as char to serial port..
addr++; //..next address &..
//..access next address from the memory.
b = i2c_eeprom_read_byte(0x50, addr);
}//while ()
Serial.println(" "); // new line..
delay(2000); // ..2 second delay, & start again!
} //loop()
/*
WARNING: address is a page address, 6-bit end will wrap around
also, data can be maximum of about 30 bytes,
because the Wire library has a buffer of 32 bytes
*/
void i2c_eeprom_write_page( int deviceAddress, unsigned int eeAddressPage, byte* data, byte length )
{
Wire.beginTransmission(deviceAddress);
Wire.send((int)(eeAddressPage >> 8)); // MSB
Wire.send((int)(eeAddressPage & 0xFF)); // LSB
byte c;
for ( c = 0; c < length; c++)
Wire.send(data[c]);
Wire.endTransmission();
} //i2c_eeprom_write_page()
byte i2c_eeprom_read_byte( int deviceAddress, unsigned int eeAddress )
{
byte rdata = 0xFF;
//ask device by address for data
Wire.beginTransmission(deviceAddress);
Wire.send((int)(eeAddress >> 8)); // MSB
Wire.send((int)(eeAddress & 0xFF)); // LSB
Wire.endTransmission();
Wire.requestFrom(deviceAddress,1);
if (Wire.available())
rdata = Wire.receive();
return rdata;
} //i2c_eeprom_read_byte()
// END
* Project: eeprom_fromWeb
* Author: hkhijhe - tidied even more by Jane-Maree Howard
* Date: 01/10/2010
* Platform: Arduino 22
* Purpose: To demonstrate use of the I2C bus with an EEPROM 24LC64
- "You were issued with an eeprom 24LC64 IC.
- This is a TWI memory that you connect to SCL and SDA on the Arduino.
- Run the program from the blog.
- Show your code changes and the serial monitor output in your blog".
* Operation: Because this chip is I2C,
- it only uses Arduino analog pins 4 & 5 (SDA and SCL),
- and of course the power (5V) and GND.
- Connect as follows:
- Arduino pin 4 to EEPROM pin 5
- Arduino pin 5 to EEPROM pin 6
- Arduino 5V to EEPROM pin 8
- Arduino GND to EEPROM pin 1,2,3,4
- Be sure to leave pin 7 of the EEPROM open or tie it to GND,
- otherwise the EEPROM will be write protected.
- Include: Wire.h - the I2C library
- Declare: various i2c_eeprom_read.. i2c_eeprom_write.. procedures
- Setup(): Opens the Wire connection, the Serial connection,
- writes a char-string to the EEPROM, & prints heading
- NOTE: the char-string has length = 28
- Loop(): Reads from the EEPROM, & prints, one byte at a time, & repeats
*/
#include {Wire.h} //I2C library-usual brackets warning
void setup()
{
// a char-string of data to write to the EEPROM - 28 characters long!!
char someData[] = "this is data from the eeprom";
/*
char somedata[] = "this is Jane-Maree's eeprom data"; - 32 characters..
.. & it bombs. Gibberish - I've tried it! See WARNING below..
*/
Wire.begin(); // Wire connection initialised
Serial.begin(9600); // Serial connection @ 9600 baud
// now write the char-string to the EEPROM
i2c_eeprom_write_page(0x50, 0, (byte *)someData, sizeof(someData));
delay(10); //add a small delay..
// ..& print a heading
Serial.println("\nMemory written");
Serial.println("\nNow read memory & print to Serial port");
} //setup()
void loop()
{
int addr=0; // address parameter, starts @ 0
// now access the first address (0) from the memory
byte b = i2c_eeprom_read_byte(0x50, 0);
// while there are non-zero bytes..
while (b!=0)
{
Serial.print((char)b); //..print content as char to serial port..
addr++; //..next address &..
//..access next address from the memory.
b = i2c_eeprom_read_byte(0x50, addr);
}//while ()
Serial.println(" "); // new line..
delay(2000); // ..2 second delay, & start again!
} //loop()
/*
WARNING: address is a page address, 6-bit end will wrap around
also, data can be maximum of about 30 bytes,
because the Wire library has a buffer of 32 bytes
*/
void i2c_eeprom_write_page( int deviceAddress, unsigned int eeAddressPage, byte* data, byte length )
{
Wire.beginTransmission(deviceAddress);
Wire.send((int)(eeAddressPage >> 8)); // MSB
Wire.send((int)(eeAddressPage & 0xFF)); // LSB
byte c;
for ( c = 0; c < length; c++)
Wire.send(data[c]);
Wire.endTransmission();
} //i2c_eeprom_write_page()
byte i2c_eeprom_read_byte( int deviceAddress, unsigned int eeAddress )
{
byte rdata = 0xFF;
//ask device by address for data
Wire.beginTransmission(deviceAddress);
Wire.send((int)(eeAddress >> 8)); // MSB
Wire.send((int)(eeAddress & 0xFF)); // LSB
Wire.endTransmission();
Wire.requestFrom(deviceAddress,1);
if (Wire.available())
rdata = Wire.receive();
return rdata;
} //i2c_eeprom_read_byte()
// END
Tuesday, October 18, 2011
Task 38 - using the I2C bus with an EEPROM 24LC64
(The post following this one goes into different device addresses)
The address given in the original code - below, more or less - has the 24LC64 connected as follows:
Pin A0 is LOW;
Pin A1 is LOW;
Pin A2 is LOW.
This requires the device address to be 0x50.
Later, we will see devices connected so that they are to be addressed as 0x51 & 0x52, merely by varying the LOW/HIGH status of A0, A1, & A2.
This is how several devices can be connected to the same I2C bus - they are addressed differently..
/*
* Project: eeprom_fromWeb
* Author: hkhijhe - tidied by Jane-Maree Howard
* Date: 01/10/2010
* Platform: Arduino 22
* Purpose: To demonstrate use of the I2C bus with an EEPROM 24LC64
- "You were issued with an eeprom 24LC64 IC.
- This is a TWI memory that you connect to SCL and SDA on the Arduino.
- Run the program from the blog.
- Show your code changes and the serial monitor output in your blog".
* Operation: Because this chip is I2C,
- it only uses Arduino analog pins 4 & 5 (SDA and SCL),
- and of course the power (5V) and GND.
- Connect as follows:
- Arduino pin 4 to EEPROM pin 5
- Arduino pin 5 to EEPROM pin 6
- Arduino 5V to EEPROM pin 8
- Arduino GND to EEPROM pin 1,2,3,4
- Be sure to leave pin 7 of the EEPROM open or tie it to GND,
- otherwise the EEPROM will be write protected.
- Include: Wire.h - the I2C library
- Declare: various i2c_eeprom_read.. i2c_eeprom_write.. procedures
- Setup(): Opens the Wire connection, the Serial connection,
- writes a char-string to the EEPROM, & prints heading
- NOTE: the char-string has length = 28
- Loop(): Reads from the EEPROM, & prints, one byte at a time, & repeats
*/
#include {Wire.h} //I2C library-usual brackets warning
void setup()
{
// a char-string of data to write to the EEPROM - 28 characters long!!
char somedata[] = "this is data from the eeprom";
/*
char somedata[] = "this is Jane-Maree's eeprom data"; - 32 characters..
.. & it bombs. Gibberish - I've tried it! See WARNING below..
*/
Wire.begin(); // Wire connection initialised
Serial.begin(9600); // Serial connection @ 9600 baud
// now write the char-string to the EEPROM
i2c_eeprom_write_page(0x50, 0, (byte *)somedata, sizeof(somedata));
delay(10); //add a small delay..
// ..& print a heading
Serial.println("\nMemory written");
Serial.println("\nNow read memory & print to Serial port");
} //setup()
void loop()
{
int addr=0; // address parameter, starts @ 0
// now access the first address (0) from the memory
byte b = i2c_eeprom_read_byte(0x50, 0);
// while there are non-zero bytes..
while (b!=0)
{
Serial.print((char)b); //..print content to serial port..
addr++; //..next address &..
//..access next address from the memory.
b = i2c_eeprom_read_byte(0x50, addr);
}//while ()
Serial.println(" "); // new line..
delay(2000); // ..2 second delay, & start again!
} //loop()
void i2c_eeprom_write_byte( int deviceaddress, unsigned int eeaddress, byte data )
{
int rdata = data;
Wire.beginTransmission(deviceaddress);
Wire.send((int)(eeaddress >> 8)); // MSB
Wire.send((int)(eeaddress & 0xFF)); // LSB
Wire.send(rdata);
Wire.endTransmission();
} //i2c_eeprom_write_byte()
/*
WARNING: address is a page address, 6-bit end will wrap around
also, data can be maximum of about 30 bytes,
because the Wire library has a buffer of 32 bytes
*/
void i2c_eeprom_write_page( int deviceaddress, unsigned int eeaddresspage, byte* data, byte length )
{
Wire.beginTransmission(deviceaddress);
Wire.send((int)(eeaddresspage >> 8)); // MSB
Wire.send((int)(eeaddresspage & 0xFF)); // LSB
byte c;
for ( c = 0; c < length; c++)
Wire.send(data[c]);
Wire.endTransmission();
} //i2c_eeprom_write_page()
byte i2c_eeprom_read_byte( int deviceaddress, unsigned int eeaddress )
{
byte rdata = 0xFF;
Wire.beginTransmission(deviceaddress);
Wire.send((int)(eeaddress >> 8)); // MSB
Wire.send((int)(eeaddress & 0xFF)); // LSB
Wire.endTransmission();
Wire.requestFrom(deviceaddress,1);
if (Wire.available())
rdata = Wire.receive();
return rdata;
} //i2c_eeprom_read_byte()
// maybe let's not read more than 30 or 32 bytes at a time! See NOTE!
void i2c_eeprom_read_buffer( int deviceaddress, unsigned int eeaddress, byte *buffer, int length )
{
Wire.beginTransmission(deviceaddress);
Wire.send((int)(eeaddress >> 8)); // MSB
Wire.send((int)(eeaddress & 0xFF)); // LSB
Wire.endTransmission();
Wire.requestFrom(deviceaddress,length);
int c = 0;
for ( c = 0; c < length; c++ )
if (Wire.available())
buffer[c] = Wire.receive();
} //i2c_eeprom_read_buffer()
You can see the gibberish along the top, caused by a buffer over-run.
i think this was what happened earlier, when i was 'experimenting'.
When all else fails,
Read The Instructions.
Now i need to figure out how to get around that buffer problem - i've not yet understood how to add a C-header file (.h) & C-file (.cpp)..
The address given in the original code - below, more or less - has the 24LC64 connected as follows:
Pin A0 is LOW;Pin A1 is LOW;
Pin A2 is LOW.
This requires the device address to be 0x50.
Later, we will see devices connected so that they are to be addressed as 0x51 & 0x52, merely by varying the LOW/HIGH status of A0, A1, & A2.
This is how several devices can be connected to the same I2C bus - they are addressed differently..
/*
* Project: eeprom_fromWeb
* Author: hkhijhe - tidied by Jane-Maree Howard
* Date: 01/10/2010
* Platform: Arduino 22
* Purpose: To demonstrate use of the I2C bus with an EEPROM 24LC64
- "You were issued with an eeprom 24LC64 IC.
- This is a TWI memory that you connect to SCL and SDA on the Arduino.
- Run the program from the blog.
- Show your code changes and the serial monitor output in your blog".
* Operation: Because this chip is I2C,
- it only uses Arduino analog pins 4 & 5 (SDA and SCL),
- and of course the power (5V) and GND.
- Connect as follows:
- Arduino pin 4 to EEPROM pin 5
- Arduino pin 5 to EEPROM pin 6
- Arduino 5V to EEPROM pin 8
- Arduino GND to EEPROM pin 1,2,3,4
- Be sure to leave pin 7 of the EEPROM open or tie it to GND,
- otherwise the EEPROM will be write protected.
- Include: Wire.h - the I2C library
- Declare: various i2c_eeprom_read.. i2c_eeprom_write.. procedures
- Setup(): Opens the Wire connection, the Serial connection,
- writes a char-string to the EEPROM, & prints heading
- NOTE: the char-string has length = 28
- Loop(): Reads from the EEPROM, & prints, one byte at a time, & repeats
*/
#include {Wire.h} //I2C library-usual brackets warning
void setup()
{
// a char-string of data to write to the EEPROM - 28 characters long!!
char somedata[] = "this is data from the eeprom";
/*
char somedata[] = "this is Jane-Maree's eeprom data"; - 32 characters..
.. & it bombs. Gibberish - I've tried it! See WARNING below..
*/
Wire.begin(); // Wire connection initialised
Serial.begin(9600); // Serial connection @ 9600 baud
// now write the char-string to the EEPROM
i2c_eeprom_write_page(0x50, 0, (byte *)somedata, sizeof(somedata));
delay(10); //add a small delay..
// ..& print a heading
Serial.println("\nMemory written");
Serial.println("\nNow read memory & print to Serial port");
} //setup()
void loop()
{
int addr=0; // address parameter, starts @ 0
// now access the first address (0) from the memory
byte b = i2c_eeprom_read_byte(0x50, 0);
// while there are non-zero bytes..
while (b!=0)
{
Serial.print((char)b); //..print content to serial port..
addr++; //..next address &..
//..access next address from the memory.
b = i2c_eeprom_read_byte(0x50, addr);
}//while ()
Serial.println(" "); // new line..
delay(2000); // ..2 second delay, & start again!
} //loop()
void i2c_eeprom_write_byte( int deviceaddress, unsigned int eeaddress, byte data )
{
int rdata = data;
Wire.beginTransmission(deviceaddress);
Wire.send((int)(eeaddress >> 8)); // MSB
Wire.send((int)(eeaddress & 0xFF)); // LSB
Wire.send(rdata);
Wire.endTransmission();
} //i2c_eeprom_write_byte()
/*
WARNING: address is a page address, 6-bit end will wrap around
also, data can be maximum of about 30 bytes,
because the Wire library has a buffer of 32 bytes
*/
void i2c_eeprom_write_page( int deviceaddress, unsigned int eeaddresspage, byte* data, byte length )
{
Wire.beginTransmission(deviceaddress);
Wire.send((int)(eeaddresspage >> 8)); // MSB
Wire.send((int)(eeaddresspage & 0xFF)); // LSB
byte c;
for ( c = 0; c < length; c++)
Wire.send(data[c]);
Wire.endTransmission();
} //i2c_eeprom_write_page()
byte i2c_eeprom_read_byte( int deviceaddress, unsigned int eeaddress )
{
byte rdata = 0xFF;
Wire.beginTransmission(deviceaddress);
Wire.send((int)(eeaddress >> 8)); // MSB
Wire.send((int)(eeaddress & 0xFF)); // LSB
Wire.endTransmission();
Wire.requestFrom(deviceaddress,1);
if (Wire.available())
rdata = Wire.receive();
return rdata;
} //i2c_eeprom_read_byte()
// maybe let's not read more than 30 or 32 bytes at a time! See NOTE!
void i2c_eeprom_read_buffer( int deviceaddress, unsigned int eeaddress, byte *buffer, int length )
{
Wire.beginTransmission(deviceaddress);
Wire.send((int)(eeaddress >> 8)); // MSB
Wire.send((int)(eeaddress & 0xFF)); // LSB
Wire.endTransmission();
Wire.requestFrom(deviceaddress,length);
int c = 0;
for ( c = 0; c < length; c++ )
if (Wire.available())
buffer[c] = Wire.receive();
} //i2c_eeprom_read_buffer()
You can see the gibberish along the top, caused by a buffer over-run.
i think this was what happened earlier, when i was 'experimenting'.
When all else fails,
Read The Instructions.
Now i need to figure out how to get around that buffer problem - i've not yet understood how to add a C-header file (.h) & C-file (.cpp)..
Task 38 - a diversion "..long time the manxome foe (s)he sought.."
..well it wasn't THAT long - I'm back in D208 &..
"Listen.. Listen.. It's a goal!!"
(with apologies to the legendary Winston McCarthy).
well, yes! Now it's working perfectly. And so, for a diversion,
from Lewis Carroll..
- The Jabberwock
- as illustrated by John Tenniel
Jabberwocky
'Twas brillig, and the slithy toves
Did gyre and gimble in the wabe;
All mimsy were the borogoves,
And the mome raths outgrabe.
"Beware the Jabberwock, my son!
The jaws that bite, the claws that catch!
Beware the Jubjub bird, and shun
The frumious Bandersnatch!"
He took his vorpal sword in hand:
Long time the manxome foe he sought--
So rested he by the Tumtum tree,
And stood awhile in thought.
And as in uffish thought he stood,
The Jabberwock, with eyes of flame,
Came whiffling through the tulgey wood,
And burbled as it came!
One, two! One, two! and through and through
The vorpal blade went snicker-snack!
He left it dead, and with its head
He went galumphing back.
"And hast thou slain the Jabberwock?
Come to my arms, my beamish boy!
O frabjous day! Callooh! Callay!"
He chortled in his joy.
'Twas brillig, and the slithy toves
Did gyre and gimble in the wabe;
All mimsy were the borogoves,
And the mome raths outgrabe.
"from Through the Looking-Glass, and What Alice Found There (1872)
I've always liked this, so I'm pleased to have an excuse to include it.
And isn't Shakespeare marvellous:
"Listen.. Listen.. It's a goal!!"
(with apologies to the legendary Winston McCarthy).
well, yes! Now it's working perfectly. And so, for a diversion,
from Lewis Carroll..
- The Jabberwock
- as illustrated by John Tenniel
Jabberwocky
'Twas brillig, and the slithy toves
Did gyre and gimble in the wabe;
All mimsy were the borogoves,
And the mome raths outgrabe.
"Beware the Jabberwock, my son!
The jaws that bite, the claws that catch!
Beware the Jubjub bird, and shun
The frumious Bandersnatch!"
He took his vorpal sword in hand:
Long time the manxome foe he sought--
So rested he by the Tumtum tree,
And stood awhile in thought.
And as in uffish thought he stood,
The Jabberwock, with eyes of flame,
Came whiffling through the tulgey wood,
And burbled as it came!
One, two! One, two! and through and through
The vorpal blade went snicker-snack!
He left it dead, and with its head
He went galumphing back.
"And hast thou slain the Jabberwock?
Come to my arms, my beamish boy!
O frabjous day! Callooh! Callay!"
He chortled in his joy.
'Twas brillig, and the slithy toves
Did gyre and gimble in the wabe;
All mimsy were the borogoves,
And the mome raths outgrabe.
"
“
”
I've always liked this, so I'm pleased to have an excuse to include it.
And isn't Shakespeare marvellous:
"The graves stood tenantless, and the sheeted dead
Did squeak and gibber in the Roman streets"
Hamlet: Act I, Scene i.
Task 37 - Integrate the new eeprom library from the link
Integrating the new eeprom library from the link here.
"To use the library, make a folder in your SKETCHBOOKPATH\libaries
with the name I2C_EEPROM and put the .h and .cpp there.
Optionally make a examples subdirectory to place the sample app."
Reference: http://arduino.cc/playground/Main/LibraryForI2CEEPROM
Having tried Task 38 in room D208, I'm now wondering if my current change of room (D209) is causing a problem. The website refers to a 'boundary problem', & I have a feeling that I don't really know what I'm doing (yet)..


Hmmm.. When in a quandary, have a laugh - "thanks" to Mike Keefe of the 'Denver Post'
And this guy, Andrew Toos, at CartoonStock
I like the 'robot' on the right.. these are just too good (hehe) :-D
"To use the library, make a folder in your SKETCHBOOKPATH\libaries
with the name I2C_EEPROM and put the .h and .cpp there.
Optionally make a examples subdirectory to place the sample app."
Reference: http://arduino.cc/playground/Main/LibraryForI2CEEPROM
Having tried Task 38 in room D208, I'm now wondering if my current change of room (D209) is causing a problem. The website refers to a 'boundary problem', & I have a feeling that I don't really know what I'm doing (yet)..


Hmmm.. When in a quandary, have a laugh - "thanks" to Mike Keefe of the 'Denver Post'
And this guy, Andrew Toos, at CartoonStock
I like the 'robot' on the right.. these are just too good (hehe) :-D
Sunday, September 18, 2011
Task 27 -- The Wire Librrary
27. List the main functions of the Wire library.
Say what they do with examples. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Wire Library Functions
======================
1. begin()
begin(address)
Initiates the Wire library and joins I2C bus as master or slave.
Normally called only once.
Parameters: address: the 7-bit slave address (optional);
if not specified, join the bus as a master.
No returns.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2. requestFrom(address, count)
Used by master to request bytes from slave device.
The bytes may then be retrieved with the available() and receive() functions.
Parameters: address: the 7-bit address of device to request bytes from
quantity: the number of bytes to request
No returns.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3. beginTransmission(address)
Begin transmission to I2C slave device with address given.
Queue bytes for transmission with send() function.
Transmit bytes by calling endTransmission().
Parameters: address: 7-bit address of device to transmit to
No returns.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4. endTransmission()
Ends transmission to slave device begun by beginTransmission()
Actually transmits the bytes queued by send().
No parameters.
Returns: byte, indicating transmission status:
0 success
1 data too long to fit in transmit buffer
2 received NACK on transmit of address
3 received NACK on transmit of data
4 other error.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5. send()
Sends data from slave device in response to request from master, or
queues bytes for transmission from master to slave device
(in-between calls to beginTransmission() and endTransmission()).
Parameters: value: a byte to send (byte)
string: a string to send (char *)
data: an array of data to send (byte *)
quantity: the number of bytes of data to transmit (byte)
No returns.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6. byte available()
Returns number of bytes available for retrieval with receive().
Should be called on master device after call to requestFrom(),
or on slave inside the onReceive() handler.
No parameters;
Returns: number of bytes available for reading.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7. byte receive()
Retrieves byte transmitted from slave device to master
after call to requestFrom()
or transmitted from master to slave.
No parameters;
Returns: next byte received.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8. onReceive(handler)
9. onRequest(handler)
These are not much used in our projects.
Note: On most Arduino boards,
SDA (data line) is on analog input pin 4, and
SCL (clock line) is on analog input pin 5.
Reference: http://arduino.cc/en/Reference/Wire
.
Saturday, September 17, 2011
Task 25 - DIY TWI protocol using 4-bit data-path
Labels:
Arduino,
bit logic,
communication,
I2C,
serial monitor,
software,
TASKS,
TWI
Friday, September 16, 2011
Task 24 - DIY TWI protocol using 8-bit data-path
..
Labels:
Arduino,
bit logic,
communication,
I2C,
serial monitor,
software,
TASKS,
TWI
Subscribe to:
Posts (Atom)




