Alberto Petrucci
/
Nucleo_I2C
NUCLEO I2C MASTER
Fork of I2C_HelloWorld_Mbed by
Revision 1:677b47408246, committed 2017-03-01
- Comitter:
- capriele
- Date:
- Wed Mar 01 08:06:44 2017 +0000
- Parent:
- 0:f76c26307f9a
- Commit message:
- NUCLEO I2C MASTER
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 f76c26307f9a -r 677b47408246 main.cpp --- a/main.cpp Thu Feb 14 17:24:48 2013 +0000 +++ b/main.cpp Wed Mar 01 08:06:44 2017 +0000 @@ -1,25 +1,40 @@ #include "mbed.h" - -// Read temperature from LM75BD + #include <stdio.h> +#include <inttypes.h> + +Serial pc(USBTX, USBRX); // tx, rx -I2C i2c(p28, p27); +const int addr = (0x07); +I2C i2c(D14, D15); //sda, scl -const int addr = 0x90; +//LEDS +DigitalOut led0(D2); +DigitalOut led1(D3); +DigitalOut led2(D4); +DigitalOut led3(D5); int main() { - char cmd[2]; + i2c.frequency(100000);//100khz + + char num0[1]; + num0[0] = 0x00; + + char cmd[1]; + cmd[0] = 0x00; while (1) { - cmd[0] = 0x01; - cmd[1] = 0x00; - i2c.write(addr, cmd, 2); - + //i2c.write(addr, cmd, 1, false); + //i2c.read(addr, num0, 2, false); + + //cmd[0] = 0x01; + i2c.write(addr, cmd, 1, false); + i2c.read(addr, num0, 1, false); + + //Accendo i led + led0 = num0[0] & 0x01; + led1 = num0[0] & 0x02; + led2 = num0[0] & 0x03; + led3 = num0[0] & 0x04; + printf("RECEIVED = %02X \n", num0[0]); wait(0.5); - - cmd[0] = 0x00; - i2c.write(addr, cmd, 1); - i2c.read(addr, cmd, 2); - - float tmp = (float((cmd[0]<<8)|cmd[1]) / 256.0); - printf("Temp = %.2f\n", tmp); } } \ No newline at end of file
diff -r f76c26307f9a -r 677b47408246 mbed.bld --- a/mbed.bld Thu Feb 14 17:24:48 2013 +0000 +++ b/mbed.bld Wed Mar 01 08:06:44 2017 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/0954ebd79f59 \ No newline at end of file +http://mbed.org/users/mbed_official/code/mbed/builds/faff56e089b2 \ No newline at end of file