I2c GPS and sat number

This forum is dedicated to software development related to MultiWii.
It is not the right place to submit a setup problem.
Software download
Post Reply
JohnyGab
Posts: 144
Joined: Sat Oct 29, 2011 4:41 am

I2c GPS and sat number

Post by JohnyGab »

I was implementing a I2c GPS on my quad and, i was having hard time testing if working or not ( the first time ), I new that my GPS had satellite, but only 2-3, and no 3dfix. But, Gui did not show the satellite number ( with I2c gps ) until there is enought GPS.

Seeing if there is satellite, ...even with no fix is something that can be helpfull when building a setup :

in void GPS_NewData()

before :

Code: Select all

static uint8_t _i2c_gps_status;
 
    //Do not use i2c_writereg, since writing a register does not work if an i2c_stop command is issued at the end
    //Still investigating, however with separated i2c_repstart and i2c_write commands works... and did not caused i2c errors on a long term test.
 
    _i2c_gps_status = i2c_readReg(I2C_GPS_ADDRESS,I2C_GPS_STATUS);                    //Get status register
    if (_i2c_gps_status & I2C_GPS_STATUS_3DFIX) {                                     //Check is we have a good 3d fix (numsats>5)
       GPS_fix = 1;                                                                   //Set fix
       GPS_numSat = (_i2c_gps_status & 0xf0) >> 4;                                 //Num of sats is stored the upmost 4 bits of status
       if (!GPS_fix_home) {        //if home is not set set home position to WP#0 and activate it
          i2c_rep_start(I2C_GPS_ADDRESS);i2c_write(I2C_GPS_COMMAND);i2c_write(I2C_GPS_COMMAND_SET_WP);//Store current position to WP#0 (this is used for RTH)
          i2c_rep_start(I2C_GPS_ADDRESS);i2c_write(I2C_GPS_COMMAND);i2c_write(I2C_GPS_COMMAND_ACTIVATE_WP);//Set WP#0 as the active WP
          GPS_fix_home = 1;                                                           //Now we have a home   
       }


After :

Code: Select all

    //Do not use i2c_writereg, since writing a register does not work if an i2c_stop command is issued at the end
    //Still investigating, however with separated i2c_repstart and i2c_write commands works... and did not caused i2c errors on a long term test.
    GPS_numSat = (_i2c_gps_status & 0xf0) >> 4;
    _i2c_gps_status = i2c_readReg(I2C_GPS_ADDRESS,I2C_GPS_STATUS);                    //Get status register
    if (_i2c_gps_status & I2C_GPS_STATUS_3DFIX) {                                     //Check is we have a good 3d fix (numsats>5)
       GPS_fix = 1;                                                                   //Set fix
       GPS_numSat = (_i2c_gps_status & 0xf0) >> 4;                                    //Num of sats is stored the upmost 4 bits of status
       if (!GPS_fix_home) {        //if home is not set set home position to WP#0 and activate it
          i2c_rep_start(I2C_GPS_ADDRESS);i2c_write(I2C_GPS_COMMAND);i2c_write(I2C_GPS_COMMAND_SET_WP);//Store current position to WP#0 (this is used for RTH)
          i2c_rep_start(I2C_GPS_ADDRESS);i2c_write(I2C_GPS_COMMAND);i2c_write(I2C_GPS_COMMAND_ACTIVATE_WP);//Set WP#0 as the active WP
          GPS_fix_home = 1;                                                           //Now we have a home   
       }

User avatar
Loosi
Posts: 63
Joined: Sat Aug 20, 2011 8:31 pm
Location: Germany (HSK)
Contact:

Re: I2c GPS and sat number

Post by Loosi »

+1
Thank you!

Post Reply