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.

Dependencies:   mbed

Committer:
belloula
Date:
Thu Oct 20 22:50:36 2011 +0000
Revision:
0:70612f5e54b1

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
belloula 0:70612f5e54b1 1 //communicate with Global Positioning Module DS-GPM via I2C using mbed.
belloula 0:70612f5e54b1 2 //This example reads time and dat from the GPM and displays them on the debug screen.
belloula 0:70612f5e54b1 3
belloula 0:70612f5e54b1 4 #include "mbed.h"
belloula 0:70612f5e54b1 5 Serial pc(USBTX, USBRX);
belloula 0:70612f5e54b1 6 I2C i2c(p9, p10); // sda, scl
belloula 0:70612f5e54b1 7 unsigned char adress_DSGPM;//= 0xD0;
belloula 0:70612f5e54b1 8 char data[112];
belloula 0:70612f5e54b1 9
belloula 0:70612f5e54b1 10 DigitalOut myled(LED1);
belloula 0:70612f5e54b1 11
belloula 0:70612f5e54b1 12 int main()
belloula 0:70612f5e54b1 13 {
belloula 0:70612f5e54b1 14 int count = 0;
belloula 0:70612f5e54b1 15 //Scan for I2C slave devices (0 => no slave found !0 => address of the slaved device found )
belloula 0:70612f5e54b1 16 pc.printf("I2CU! Searching for I2C devices...\n");
belloula 0:70612f5e54b1 17 for (int address=0xD0; address<0xD7; address+=2)
belloula 0:70612f5e54b1 18 {
belloula 0:70612f5e54b1 19 if (!i2c.write(address, NULL, 0))
belloula 0:70612f5e54b1 20 { // 0 returned is ok
belloula 0:70612f5e54b1 21 pc.printf(" - I2C device found at address 0x%02X\n", address);
belloula 0:70612f5e54b1 22 adress_DSGPM=address;
belloula 0:70612f5e54b1 23 count++;
belloula 0:70612f5e54b1 24 }
belloula 0:70612f5e54b1 25
belloula 0:70612f5e54b1 26 }
belloula 0:70612f5e54b1 27 pc.printf("%d devices found\n", count);
belloula 0:70612f5e54b1 28
belloula 0:70612f5e54b1 29 char BaseReg_Address=0;
belloula 0:70612f5e54b1 30 char cmd[1]={BaseReg_Address};
belloula 0:70612f5e54b1 31 while(1)
belloula 0:70612f5e54b1 32 {
belloula 0:70612f5e54b1 33 myled = 1;
belloula 0:70612f5e54b1 34 wait(0.2);
belloula 0:70612f5e54b1 35 i2c.write(adress_DSGPM,cmd,1);
belloula 0:70612f5e54b1 36 i2c.read(adress_DSGPM,data,6);
belloula 0:70612f5e54b1 37 pc.printf("%d%d:%d%d:%d%d\n", data[0], data[1], data[2], data[3], data[4], data[5]);
belloula 0:70612f5e54b1 38 myled = 0;
belloula 0:70612f5e54b1 39 wait(0.5);
belloula 0:70612f5e54b1 40 }
belloula 0:70612f5e54b1 41 }
belloula 0:70612f5e54b1 42
belloula 0:70612f5e54b1 43
belloula 0:70612f5e54b1 44
belloula 0:70612f5e54b1 45