Hi all!

I have some problems getting my GTPA010 (MediaTek MTK 3329 GPS 10Hz) running on Arduino Mega Rev. 3. I am using I2C connection (have an adapter for it). I tried the following code, which I found on the web:

#include <Wire.h>

#define I2C_GPS_ADDRESS                           0x20       
/*************** I2C GSP register definitions *********************************/

#define I2C_GPS_STATUS                            0x00 //(Read only)
        
#define I2C_GPS_GROUND_SPEED                      0x07   //GPS ground speed in m/s*100 (uint16_t)      (Read Only)
#define I2C_GPS_ALTITUDE                          0x09   //GPS altitude in meters (uint16_t)           (Read Only)
#define I2C_GPS_TIME                              0x0b   //UTC Time from GPS in hhmmss.sss * 100 (uint32_t)(unneccesary precision) (Read Only)
#define I2C_GPS_DISTANCE                          0x0f   //Distance between current pos and internal target location register in meters (uint16_t) (Read Only)
#define I2C_GPS_DIRECTION                         0x11   //direction towards interal target location reg from current position (+/- 180 degree)    (read Only)
#define I2C_GPS_LOCATION                          0x13   //current position (8 bytes, lat and lon, 1 degree = 10 000 000                           (read only)
        

//**************************************************************
// Second byte will be from 'address'+1
unsigned char GPS_1_byte_read(unsigned char address)
{  
  Wire.beginTransmission(I2C_GPS_ADDRESS);
  Wire.send(address);
  Wire.endTransmission();
  Wire.requestFrom(I2C_GPS_ADDRESS, 1);
  while(Wire.available()<1);
  Wire.endTransmission();
 
  return Wire.receive();
}

int GPS_2_byte_read(unsigned char address)
{  
  unsigned char msb, lsb;
  Wire.beginTransmission(I2C_GPS_ADDRESS);
  Wire.send(address);
  Wire.endTransmission();
 
  Wire.requestFrom(I2C_GPS_ADDRESS, 2);
  while(Wire.available()<2)    ;
  msb = Wire.receive();
  lsb = Wire.receive();
 
  Wire.endTransmission();
 
  return (int) lsb<<8 | msb;
}


void setup()
{
  Wire.begin();        // join i2c bus (address optional for master)
  Serial.begin(38400);  // start serial for output
 
  Serial.println("Starting:");
}

void loop()
{
 
  Wire.begin();  
  Serial.println(GPS_1_byte_read(I2C_GPS_STATUS), HEX);
  Serial.println(GPS_2_byte_read(I2C_GPS_ALTITUDE), DEC);
  Wire.endTransmission();
 
  delay(500);
}

Unfortunately the code does not work as expected. I put in some outputs and found out that the code does not continue after the line  while(Wire.available()<1); . Since I am new to the subject, I do not understand what this line is doing and why the code does not continue. Moreover, what value should Serial.begin() have and what about the definition of the hex addresses like I2C_GPS_STATUS 0x00? Are this addresses correct? 

Can someone please help me to get the stuff working? Thank you very much to all of you.

Best regards, Michael

 

 



 

You need to be a member of diydrones to add comments!

Join diydrones

Email me when people reply –

Replies

  • Wire.available() is a call that determines if any bytes are available from I2C. Documentation here: http://arduino.cc/en/Reference/WireAvailable

    So the code is basically waiting until the 2 bytes are sent by the slave. Those two bytes apparently don't arrive. Either because you're using the wrong I2C address, the wrong address for the field being read, some connectivity issue, or various other causes.

    Serial.begin() specifies the baud rate for the Arduino's serial connection.

    What is this adapter you mention? I gather it is a serial to I2C adapter of some sort? In which case I would imagine there's documentation on what I2C address to use and which data addresses correspond to what types of data (altitude, speed, status, etc)

This reply was deleted.

Activity