Shop Learn
I2C example, please (simplei2c.h) — Parallax Forums

I2C example, please (simplei2c.h)

I have spent hours trying to get a simple I2C program that will write a string of characters to a GPS module, and then read characters so I can ensure the proper programming has occurred. The string looks like this:

"$PMTK314,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*29"

I find information in the simplei2c.h file (in part, below) but without any comments and no examples on the Parallax site I'm about to give up. For example, the two instructions here look useful:

_int i2c_writeData(i2c *bus, const unsigned char *data, int count);

int i2c_readData(i2c *bus, unsigned char *data, int count);_

But what the heck does i2c *bus mean, where does it come from and what information does it include? What other i2c bits and pieces should go into a program? Most of the simplei2c._h operations use the i2c *bus data. Yes, I know it's a pointer, but to what? I appreciate any help. A simple example would be great. (I haven't programmed in C for a long time.) Thanks. --Jon

(I'm trying to do a demo for middle-school kids.)

23
24
25 typedef struct i2c_st
26 {
27 volatile int scl_mask;
28 volatile int scl_mask_inv;
29 int sda_mask;
30 int sda_mask_inv;
31 int drivescl; /* flag to force scl if non-zero */
32 } i2c;
33
47 HUBTEXT i2c *i2c_open(i2c *bus, int sclPin, int sdaPin, int sclDrive);
48
54 HUBTEXT void i2c_start(i2c *bus);
55
61 HUBTEXT void i2c_stop(i2c *bus);
62
73 HUBTEXT int i2c_writeByte(i2c *bus, int byte);
74
84 HUBTEXT int i2c_readByte(i2c *bus, int ackState);
85
98 HUBTEXT int i2c_writeData(i2c *bus, const unsigned char *data, int count);
99
113 HUBTEXT int i2c_readData(i2c *bus, unsigned char *data, int count);
114
124 HUBTEXT int i2c_poll(i2c *bus, int addr);
125
126 #ifdef __cplusplus
127 }
128 #endif
129
130 #endif
131 /* __i2c_H */
132
133 /*

Comments

  • By the way, I2C device address is 0x10. I see nowhere to put this address information in the I2C commands.

  • Would this happen to be for a MT3339 (or related) chipset? If so, would you be adverse to using a standard serial interface?

    The reason I put this out there is I do a lot of dev work with GPSs, and have never had any luck getting any of the Media Tek units to talk I2C. But good old serial NMEA works like a champ.

    Based on your example string it looks like you just want the unit to send a GPRMC message once each second. If so, you can use the plain vanilla ASCII serial channel both to configure the unit and to send the 1 sec RMC updates.

  • Thanks for your ideas, jRoark. Yes, that string sets the GPS module for GPRMC sentence outputs only. The module is a CD-PA1010D and it has a serial port and an I2C port. I plan to use the GPS module with a Micro:Bit computer board because our middle school uses that board for student experiments--each student has one. The Micro:Bit can handle I2C communications and standard UART communications. But there's a catch. It has only one serial port and it is dedicated to USB communications with a host PC used to display data and for programming the Micro:Bit. So I considered serial communications but went with I2C instead, so the students could see the GPS data on their laptops via USB. After programming with the GPRMC set-up information there's no need to ever again send data to the GPS module. The Micro:Bit can handle the module's I2C output and the students can parse the messages.

    This seems like a lot of effort to go through for a simple demo, but I don't give up easily. Thanks. --Jon

  • GenetixGenetix Posts: 1,542
    edited 2021-09-10 10:26

    Jon,

    simplei2c.h appears to be a BlockyProp functiom (Propeller C).
    https://github.com/parallaxinc/BlocklyPropClient/blob/master/propeller-c-lib/Protocol/libsimplei2c/simplei2c.h

    The Micro:Bit uses Python.
    https://microbit-micropython.readthedocs.io/en/v2-docs/i2c.html

    I found these references but I don't see anything for I2C.
    https://microbit.org/lessons/
    https://www.teachwithict.com/physical-computing.html
    https://github.com/carlosperate/awesome-microbit/blob/master/README.md#-teaching-resources

    I found this Python library for the PA1010D, but it's for the Raspberry Pi.
    https://pypi.org/project/pa1010d/

    Adafruit sells a PA1010D GPS module as has CircuitPython code for it.
    https://www.adafruit.com/product/4415

    Adafruit has Arduino code for the PA1010D but it uses a Serial Port which you don't want.

    ***** This is a different GPS module, but it uses I2C on the Micro:Bit.
    https://www.daveakerman.com/?p=2019

    By the way, this is how you attach code:

  • Hello, Genetix. Many thanks for your help. I appreciate it and the links! Wow. Have a nice weekend. --Jon

Sign In or Register to comment.