Axel Utech
/
Nucleo_i2c_pcf8574
Demo for PCF8574
Revision 0:daf4d39b8c98, committed 2014-11-05
- Comitter:
- aAXEe
- Date:
- Wed Nov 05 08:01:34 2014 +0000
- Commit message:
- basic handling working
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 daf4d39b8c98 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Wed Nov 05 08:01:34 2014 +0000 @@ -0,0 +1,45 @@ +#include "mbed.h" + +#define PCF8574_ADDR (0x40) + +I2C i2c(I2C_SDA, I2C_SCL); + + +Serial pc(SERIAL_TX, SERIAL_RX); + + +bool pcf8574_write(uint8_t data){ + return i2c.write(PCF8574_ADDR, (char*) &data, 1, 0) == 0; +} + +bool pcf8574_read(uint8_t* data){ + return i2c.read(PCF8574_ADDR, (char*) data, 1, 0) == 0; +} + +int pcf8574_test(uint8_t value){ + int ret; + uint8_t data=0; + + ret = pcf8574_write(value); + if(!ret) return -1; + + ret = pcf8574_read(&data); + if(!ret) return -2; + + return data; +} + +int main() +{ + + printf("Hello PCF8574\n"); + while (1) { + pc.printf("pcf8574_test: low: %i\n", pcf8574_test(0x00)); + wait(0.5); + pc.printf("pcf8574_test: high: %i\n", pcf8574_test(0xff)); + wait(0.5); + } + +} + +
diff -r 000000000000 -r daf4d39b8c98 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Wed Nov 05 08:01:34 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/031413cf7a89 \ No newline at end of file