Greetings, Earthlings. I'm hoping that you exemplary programmers and
TinyOS developers can help out a wee old mechanical engineering
student with his troubles centering on I2C.
The device that is being used is a MICAz unit and we were hoping to
interface a series of I/O expanders (4 x PCF8574A units, 7-bit device
addressing, and these devices will be interfacing with some LM629
units). We know that the circuitry works because we've been able to
read/write to the device using a PIC16F877A piece of junk. However,
once we move over to TinyOS, the device appears not to work. It works
on the PIC because the built-in libraries handle all of the tedious
work. I'd have thought TOS would have similar functionality but I was
disappointed.
At first, the Masters student who had no previous experience (no one
did, really) with TinyOS tried to first use I2CPacket and that
wouldn't work. That part of the group split away for a bit and are
implementing PID in software, which I really, really wanted to avoid
(because it's a really bad idea in this case but we have a deadline).
While they were doing that I took a little time to see if I could get
I2C working. I dropped back to I2CM and now planning to drop to
straight TOSH sequences and handling every single bit in and out,
making me a very unhappy person. I have already started but before I
do this, I thought I'd ask for any ideas on a better approach.
I have no real clue on how I2CPacket works (I always like working my
way "up" from hardware because I find it easier to understand that way).
1) I'm assuming that I2C.write(char) puts the eight bit char on the bus,
2) That it doesn't set the bit (I have tried with and without R/W bit
set), and
3) Now that I've written this, I forgot to check and see if read/write
handles any ACK conditions.
The one hardware change that seemed to be required was the removal of
our external pull-ups as we used TOSH commands to set and clear the
two lines and verified that it worked using a multimeter. Right now,
the green LED comes on *saying* that the write has occurred but the IO
expander outputs do not change as it should.
// $Id: MyAppM.nc $
/*
* Date: 10/30/08
*/
#define DEVICE_ADDR 0x40
module MyAppM {
provides interface StdControl;
uses interface StdControl as TimerControl;
uses interface Timer as UpdateTimer;
uses interface Leds;
uses interface I2C as PID;
}
implementation {
int i = 1;
command result_t StdControl.init() {
call TimerControl.init();
call Leds.init();
return SUCCESS;
}
command result_t StdControl.start() {
call UpdateTimer.start(TIMER_REPEAT, 2000);
return SUCCESS;
}
command result_t StdControl.stop() {
call UpdateTimer.stop();
return SUCCESS;
}
void i2c_start() {
// Since noting else on the bus controls it, I
// may *not* have to check the current line status.
TOSH_MAKE_I2C_BUS1_SDA_OUTPUT();;
TOSH_SET_I2C_BUS1_SDA_PIN();
TOSH_SET_I2C_BUS1_SCL_PIN();
TOSH_uwait(10);
TOSH_CLR_I2C_BUS1_SDA_PIN();
TOSH_uwait(10);
TOSH_CLR_I2C_BUS1_SCL_PIN();
TOSH_uwait(10);
}
void payload() {
// Not sure if I2C.write() actually sets the R/W bit.
uint8_t address = DEVICE_ADDR & 0x01;
i2c_start();
TOSH_uwait(15);
if (call PID.write(address) == SUCCESS) {
call Leds.greenOn();
// Should wait for an ACK here before next
write,
// or put the check in writeDone().
call PID.write(0x55);
}
else
call Leds.redOn();
call PID.sendEnd();
}
event result_t UpdateTimer.fired() {
call Leds.yellowToggle();
call Leds.redOff();
payload();
return SUCCESS;
}
event result_t PID.sendStartDone() {
return SUCCESS; }
event result_t PID.sendEndDone() {
return SUCCESS; }
event result_t PID.readDone(char d) {
return SUCCESS; }
event result_t PID.writeDone(bool s) {
return SUCCESS; }
}
_______
// $Id:MyApp.nc $
/*
* Author: Patrick Walker
* Date: 10/30/08
*
*/
configuration MyApp { }
implementation {
components Main, TimerC, LedsC, MyAppM, I2CM;
Main.StdControl -> MyAppM;
MyAppM.Leds -> LedsC;
MyAppM.TimerControl -> TimerC.StdControl;
MyAppM.UpdateTimer -> TimerC.Timer[unique("Timer")];
MyAppM.PID -> I2CM;
}
________________________
Patrick William Walker
[EMAIL PROTECTED]
[EMAIL PROTECTED]
_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help