Hello
I know this question has been asked other times, but I can't realize (as a
beginner in Tinyos) why I'm having trouble with I2C.
We were using I2C to communicate with a TMP275 temperature sensor by the
expansion connector of a Tmote Sky; the code was adapted from the module
AD524XM.nc. We couldn't get any signal in SCL or SDA, just the START signal,
while calling readPacket or writePacket.
As the bus is the same used by the Sky node, I thought I didn't need pull-up
resistors; am I right?
So I tried to make a loopback test, using the same structure of code, that I
send below. Could someone please help me saying if the way I'm using I2C is
right?
Thanks
// Configuration
configuration Testa_I2C {
}
implementation {
components Main, MSP430I2CC, Testa_I2CM, LedsC, TimerC;
components new I2CResourceC() as I2CResourceC;
Main.StdControl -> Testa_I2CM.StdControl;
Testa_I2CM.LowerControl -> MSP430I2CC;
Testa_I2CM.I2CPacket -> MSP430I2CC;
Testa_I2CM.MSP430I2C -> MSP430I2CC;
Testa_I2CM.I2CResource -> I2CResourceC;
Testa_I2CM.Leds -> LedsC;
Testa_I2CM.Timer -> TimerC.Timer[unique("Timer")];
}
// Module
module Testa_I2CM {
provides {
interface StdControl;
}
uses {
interface StdControl as LowerControl;
interface MSP430I2C;
interface MSP430I2CPacket as I2CPacket;
interface ResourceCmd as I2CResource;
interface Leds;
interface Timer;
}
}
implementation {
bool escreveu;
command result_t StdControl.init() {
call Leds.init();
escreveu = FALSE;
return call LowerControl.init();
}
command result_t StdControl.start() {
call MSP430I2C.enable();
call MSP430I2C.setOwnAddr(0x56);
call Timer.start(TIMER_REPEAT, 5000);
return call LowerControl.start();
}
command result_t StdControl.stop() {
return call LowerControl.stop();
}
event void I2CResource.granted(uint8_t rh) {
uint8_t dado[1];
uint8_t envia = 6;
if(escreveu) {
if(call I2CPacket.readPacket(rh, 0X57, 1, dado)==SUCCESS)
escreveu = FALSE;
}
else {
call I2CPacket.writePacket(rh, 0x56, 1, &envia);
escreveu = TRUE;
}
call I2CResource.release();
}
event void I2CPacket.readPacketDone(uint16_t address, uint8_t length,
uint8_t *data, result_t success) {
// code to verify if data is OK
}
event void I2CPacket.writePacketDone(uint16_t address, uint8_t length,
uint8_t *data, result_t success) {
call I2CResource.deferRequest();
}
event result_t Timer.fired() {
call I2CResource.deferRequest();
return SUCCESS;
}
}
--
Henrique Augusto Menarin
_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help