communicate with Global Positioning Module DS-GPM via I2C using mbed. This example reads time and dat from the GPM and displays them on the debug screen.
Revision 0:70612f5e54b1, committed 2011-10-20
- Comitter:
- belloula
- Date:
- Thu Oct 20 22:50:36 2011 +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 70612f5e54b1 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Oct 20 22:50:36 2011 +0000 @@ -0,0 +1,45 @@ +//communicate with Global Positioning Module DS-GPM via I2C using mbed. +//This example reads time and dat from the GPM and displays them on the debug screen. + +#include "mbed.h" +Serial pc(USBTX, USBRX); +I2C i2c(p9, p10); // sda, scl +unsigned char adress_DSGPM;//= 0xD0; +char data[112]; + +DigitalOut myled(LED1); + +int main() +{ + int count = 0; + //Scan for I2C slave devices (0 => no slave found !0 => address of the slaved device found ) + pc.printf("I2CU! Searching for I2C devices...\n"); + for (int address=0xD0; address<0xD7; address+=2) + { + if (!i2c.write(address, NULL, 0)) + { // 0 returned is ok + pc.printf(" - I2C device found at address 0x%02X\n", address); + adress_DSGPM=address; + count++; + } + + } + pc.printf("%d devices found\n", count); + + char BaseReg_Address=0; + char cmd[1]={BaseReg_Address}; + while(1) + { + myled = 1; + wait(0.2); + i2c.write(adress_DSGPM,cmd,1); + i2c.read(adress_DSGPM,data,6); + pc.printf("%d%d:%d%d:%d%d\n", data[0], data[1], data[2], data[3], data[4], data[5]); + myled = 0; + wait(0.5); + } +} + + + +
diff -r 000000000000 -r 70612f5e54b1 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Thu Oct 20 22:50:36 2011 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/63bcd7ba4912