Using I2C for Serial Comms

rbright

Member
Playing with a new controller in Australia known as a MaxiMite based upon a PIC32 ( http://geoffg.net/maximite.html) Currently this system does not have a serial port but has I2C operating OK to a PicAxe for passing bytes.
Has anyone ever used I2C on a PicAxe to PicAxe or any orther I2C device for the equivalent of serial communications?
Regards
 

MartinM57

Moderator
Are you talking about using I2C to emulate RS232-protocol serial? I2C is, by definition, a serial protocol (the bytes go serially down a data wire, as opposed to having many data wires).

Presumably the Maximite to PICAXE link is passing bytes by having the PICAXE act as an I2C slave, recieving bytes from the Maximite I2C master? Which can be done in PICAXE land with a PICAXE I2C master and a PICAXE I2C slave (see Manual 2 for examples)

So I'm not quite sure what you're asking...
 

hippy

Ex-Staff (retired)
If it's just writing to a PICAXE X2 or reading from one using I2C then as MartinM57 says that should be straight forward enough.

The MaxiMite is Open Source and the source code is available. It would seem fairly easy to add handling for serial transfer, PIN(x)=y as a simple byte send and y=PIN(x) as byte receive at a fixed baud rate, which could make things easier. The code to change is mainly in External.c
 

rbright

Member
YES want I2C to emulate RS232-protocol serial

Requirement is to use I2C to emulate RS232-protocol serial with the PICAXE X2.

Correct the MaxiMite is Open Source with the source code available but changing that is a bit beyond me & I'd like to see how practical it would be to program it at the PicAxe Basic level.

Basically what I would like to do is communicate from the MaxiMite (which at this stage of development does not have a serial port) to a slave PicAxe or even a network of PicAxes using the only medium available from the MaxiMite which is I2C which has been tested out passing simple bytes to a slave PicAxe.

What is invisaged would require bothways communication, for example the MaxiMite polls the PicAxe asking for a value from a temperature sensor which the PicAxe returns then the Maximite can do something with the data like display on its connected VGA screen. Speadwise even 1200 bps or lower would be usable.

I was hoping someone has an example of PicAxe to PicAxe serial communications through I2C to get me started.

Another possibility would be to use a I2C UART but don't want to resort to that for something that could be achievable in Basic code.

Regards all
 

inglewoodpete

Senior Member
Serial or "RS232" protocol is a layer 1 protocol in the 7-layer OSI (Open Systems Interconnection) model. Layer 1 deals with the basic media, electrical and bit timing of communication. There is no provision for handshaking in layer 1: the sending end trusts that the other end is smart enough to know what to do with any received data.

i2c is a layer 2 protocol - it communicates at a higher technological level. Each node or end of the link has an address and there is a protocol of how the ends share the link and handshake/acknowledge data sent and received.

And there is the problem: the i2c protocol is too sophisticated to simply convert to asynch serial like RS232.

My suggestion would be to use an X1 or X2 series PICAXE (my choice would be the 20X2) configured as an i2c slave to the Maximite and, with some form of scratchpad monitoring, transmit and receive serial data via its hSerial port.

I have done similar things with 40X2 and 28X1 chips in the past. However, my code was purpose built and would not port easily to your application.
 
Last edited:

rbright

Member
Thanks for the words of wisdom especially inglewoodpete to the reference to the OSI Model which explained the issue so clearly and will save a lot of heartache. Sounds like going back to the source code will be the only effective solution.
Regards all
 
Top