Simon Ford
/
Test24LC256
Revision 0:ebb4c3fcf4a9, committed 2009-09-08
- Comitter:
- simon
- Date:
- Tue Sep 08 11:50:46 2009 +0000
- Commit message:
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r ebb4c3fcf4a9 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Sep 08 11:50:46 2009 +0000 @@ -0,0 +1,47 @@ +// Test24LC256 hello world example +// Copyright (c) 2009, sford +// Released under the MIT License: http://mbed.org/license/mit +// +// Does some basic stuff with an 24LC256 to show it is working + +#include "mbed.h" + +I2C i2c(p28, p27); // sda, scl +DigitalOut wp(p29); // write protect + +int main() { + + wp = 0; // disable write protect + + printf("Writing bytes 0-16\n"); + + char data[3]; + for(int i=0; i<16; i++) { + data[0] = 0; // MSB address + data[1] = i; // LSB address + data[2] = i * 3; // data + if(i2c.write(0xA0, data, 3)) { + error("Write failed\n"); + } + while(i2c.write(0xA0, NULL, 0)); // wait to complete + } + + printf("Setting read pointer to 0\n"); + + data[0] = 0; // MSB address + data[1] = 0; // LSB address + if(i2c.write(0xA0, data, 2)) { // send address, but no data + error("Write failed\n"); + } + + printf("Reading back data bytes 0-16\n"); + + char response[1]; + for(int i=0; i<16; i++) { + if(i2c.read(0xA0, response, 1)) { + error("Read failed\n"); + } + printf("address %03d = 0x%02X\n", i, response[0]); + } + +}
diff -r 000000000000 -r ebb4c3fcf4a9 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Tue Sep 08 11:50:46 2009 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/f63353af7be8