Arduino I2C and Ublox GPS

I am getting some unpredictable results connecting an Arduino Uno and a Ublox GPS over I2C. I am looking for some help in how to understand the problem better.

I have read Nick Gammon’s excellent material on I2C, and I was seeing data coming through, but some of the results are flaky. There might be different aspects to this problem, so I am listing them. The I2C communication is going through an Adafruit level shifter for 5v - 3.3v conversion.

  1. The GPS has its own power supply (3v). Communication over I2C only worked at startup if the 3v power of the GPS is also connected to the 3v pin of the Arduino (as well as the 3v side of the level shifter). Once communication was established, I could supply power to the SDA / SCL lines from either the Arduino, or the GPS, or both (but not neither, obviously). So if you have two separately powered devices, should the power to SDA / SCL be supplied by one or by both?

The problem is complicated because the Ublox has ambiguous documentation about the I2C port. It says that the port will shut down if not polled within 2 seconds, or if the 4k buffer is full. This would explain why I2C does not work if they don’t share a common Vcc. But it also says that the port will re-activate if polled.

I would expect the two devices to have separate power supplies; and then for I2C to share a common ground, and have one or other supply the power to each side of the level shifter, but not both. Yet it does not work to do that.

I can see that the I2C is being read, but the ublox shows that the buffer is empty.

  1. The I2C on the GPS (as slave) has a protocol for sending data:
  • read the low bytes at 0xFD (the pointer will increment automatically)
  • read the high bytes at 0xFE (the pointer will increment again)
  • read the data buffer at 0xFF
    Reading the low bytes and high bytes gives you the number of bytes to retrieve, but it is largely irrelevant. I have done a serial print of the number of bytes, and the buffer is quickly filled up to the maximum of 4k. My understanding is that the Arduino wire library only reads 32 bytes at a time. So I have coded it to keep reading chunks of 32 bytes until the buffer is read, and then start again.

This seemed to work. I saw all the messages, then a blank, then more messages. The trouble is that something caused the GPS I2C to go haywire (technical term) and stop working. I don’t want to try again until I sort out Question 1, in case it damages the GPS module.

With the wire library, I don’t seem to find a way to debug the communication. Was the slave found? Did it respond to the poll? Did it respond with “no data”, or has the port shut down? Ideally I would want to see the Start, Stop, Write, Read, ACK, NACK communication, but I don’t think I can do that with Wire.

  1. The ublox I2C communication protocol requires:
  • no STOP between reading the high and low bytes (so that the pointer can auto-increment)
  • no STOP when reading the chunks of 32k of data (so the pointer keeps reading the buffer)

I am achieving this by using the parameter (false) for Wire.requestFrom().

So, any ideas appreciated. Is the GPS I2C not responding because of the power problem? Or because the I2C port is damaged? Or because the Wire library can’t handle the communication?

Attached is the protocol for communicating with the GPS over I2C.[/list]

DDC_Application_Note(GPS.G5-X-08023).pdf (1.01 MB)

Hi, anthony!
I upgraded the standard I2C (TWI) library so that it could read into the buffer of a given size.
Try this code.

recoonI2C.rar (6.64 KB)

UNO_I2C_EVK_7N.ino (1.46 KB)

Hi, and thanks for this. I will give it a try and let you know what happens, anthony

I forgot to say
I connected the unit to both UART and I2C ports:

  • UART connected to the PC
  • I2C connected to the Arduino Uno

I downloaded the u-center utility http://www.u-blox.com/images/Support/Support_Products/EvaluationSoftware/u-centersetup-7.0.2.1.zip
and uses it to make sure the I2C port is working well (menu View/Messages/UBX/MON/HW)