![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
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.
main.cpp
- Committer:
- belloula
- Date:
- 2011-10-20
- Revision:
- 0:70612f5e54b1
File content as of revision 0:70612f5e54b1:
//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); } }