Problems getting MTK3329 GPS working with Arduino Mega and I2C

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.requestFrom(I2C_GPS_ADDRESS, 1);
  return Wire.receive();

int GPS_2_byte_read(unsigned char address)
  unsigned char msb, lsb;
  Wire.requestFrom(I2C_GPS_ADDRESS, 2);
  while(Wire.available()<2)    ;
  msb = Wire.receive();
  lsb = Wire.receive();
  return (int) lsb8 | msb;

void setup()
  Wire.begin();        // join i2c bus (address optional for master)
  Serial.begin(38400);  // start serial for output

void loop()
  Serial.println(GPS_1_byte_read(I2C_GPS_STATUS), HEX);
  Serial.println(GPS_2_byte_read(I2C_GPS_ALTITUDE), DEC);

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




Views: 1289

Reply to This

Replies to This Discussion

Wire.available() is a call that determines if any bytes are available from I2C. Documentation here:

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)

Hi Bot Thoughts!

Thank you very much for your answer. Indeed, I was already thinking that it might be an addressing issue. The adapter I mentioned was sold by DIY Drones in 2010/2011. Unfortunately I can not find an image of it in the internet. I am currently abroad, but will return within this week. As soon as I am back I will post a picture and/or naming of the device and I will try getting the GPS running with other addresses. I found in the meanwhile several other posts were people used 0x40instead of 0x20. I will give this a try......

Best regards, Michael

Hi all,

Finally, I got it fixed. It was a stupid wiring error of mine. Since I bought the GPS two years ago I did not spend much time on thinking about the correct wiring, because I felt confident in what I was doing. Bad thinking..... I am now using serial connection and the GPS_NMEA_test.pde from the ArduPlane repository. It work fine.

Cheers, Michael

Reply to Discussion



Season Two of the Trust Time Trial (T3) Contest 
A list of all T3 contests is here. The current round, the Vertical Horizontal one, is here

© 2018   Created by Chris Anderson.   Powered by

Badges  |  Report an Issue  |  Terms of Service