Making a Javelin behave as an I2C peripheral
I have a microcontroller circuit that I am doing development work on and the circuit has no display, which can make debugging challenging. But it does have an I2C bus so I am thinking I might be able to send debugging messages to a Javelin I have laying around that has a LCD display, using the I2C bus to communicate between the two. Are there any examples that I can look at that will help me with this?
Comments
You have I2C files inside stamp.peripheral.io. I think using this file and 2 pins, you must be able to retreive the informations from you circuit and display them on a screen with the Javelin.
So take a look at the stamp.peripheral.io.I2C class, and also stamp.peripheral.lcd.SerialLCD for the display.
Regards,
JM
I think you will find all what you need regarding I2C and the way to handle the address.
Also, stamp.peripheral.memory.eeprom.MC24LC256 is a good example on the way to use it. I'm using it to connect 8 MC24LC256 to my Javelin (a little home-made memory extention [noparse];)[/noparse] )
JM
Although the I2C protocol has provisions for networks with more than
one microcontroller, the Javelin Stamp’s I2C library is designed to work
in a single-master network. This means that the Javelin Stamp is the
only microcontroller connected to a given bus. The rest of the devices
are called I2C slaves because they take orders from the I2C master (the
Javelin Stamp).
And I have been asking about a circuit that has two microcontrollers and the master is not the Javelin.
The only way to let the javelin act as a slave device is via a receive Uart.
So if you have 1 I/O pin on the other mcu that you can use to send serial
commands then you can use the javelin to control a display.
But in that case, why not use a serial LCD directly?
regards peter
The other mcu is on a production board and for various reasons attaching anything other than to an existing I2C port is not an option.
I2Cstart is SDA going low while SCL is high.
So, on your mcu, when I2C is idle (SDA high, SCL high)
make SCL low while SDA is high. This is not recognized by I2C devices.
Then serial transmit data using SDA [url=mailto:pin@9600]pin[/url], while keeping SCL low.
After sending all the bytes that make up a command, SDA will be high
(serial idle state) so just make SCL high again, signaling end of command.
On the javelin:
Uart myRx = new Uart(Uart.dirReceive,CPU.pinSDA.Uart.dontInvert,Uart.speed9600,Uart.stop1);
while (true) {
· if (myRx.byteAvailable()) {
····c = Uart.receiveByte();
··· if (CPU.readPin(pinSCL) == false) {
····· //handle valid incoming byte (store in array for postprocessing)
··· }
··· else { //pinSCL input high
······ //discard byte
······ //also·postprocess·command (special value last byte)
··· }
· }
}
While using I2C on the other mcu, pinSCL is not constantly low and
so the javelin will discard received bytes which have meaningless values.
You can add a checksum·to the command stream so any command received
that has a matching checksum is known to be valid.
JavPinSCL (input)
[noparse][[/noparse]1k]
SCL other mcu
JavPinSDA (input)
[noparse][[/noparse]1k]
SDA other mcu
JavGND
GND other mcu
regards peter
Post Edited (Peter Verkaik) : 4/21/2009 5:49:28 PM GMT
Actually I know how to use the IC2 bus with the other mcu as I am already using it to read and write to an EEPROM and a RTC on that unit. It looks like I need to filter for only those messages intended for the Javelin by comparing the device address for the message where you say to "postprocess command (special value last byte)", right? I think that I can figure the rest of this out by studying the I2C protocol.
not filter any I2C command. You must send a serial stream of bytes
that make up a command for the javelin, between I2Cstop and I2Cstart
(when I2C bus is idle) while keeping SCL low. That way the javelin
knows when received bytes are valid. So you must implement a uart
on the other mcu that uses its SDA pin to transmit the serial data.
Because the serial data is transmitted between I2Cstop and I2Cstart
the other I2C devices ignore these bytes.
regards peter
which are needed to clock in data.
regards peter
there are I2C LCD displays. Just google for I2C LCD.
regards peter
http://www.i2cchip.com/
Scroll down to BL233 chip.
regards peter