Re-posting this due to complications with my mail server.
Hi all,
I am facing some difficulties interfacing an SRF02 ultrasound sensor to
MICAz using I2C bus in TinyOS-2.x. My program allows the MICAz mote to write to
the bus but it is unable to read the measurements from the sensor. It seems the
readDone() event is never triggered.
I have attached the main code for reference. The delay function is to allow
the mote application some time to write to the bus, and 0xE0 is the sensor's
I2C address. Pls help.
/*********************************************************************************************/
event void I2CResource.granted() {
if (state == 0){//send measure command
bufferPtr->cmd=0x00; //real ranging mode in centimeters
bufferPtr->data=0x51;
call I2CPacket.write(I2C_START, 0xE0, 2, (uint8_t*)bufferPtr);
delay(150); //equivalent to 1ms
call I2CPacket.write(I2C_STOP, 0xE0, 0, (uint8_t*)bufferPtr);
delay(500);
state = 1;
}
else if (state == 1){//send get_measurement command
readPtr->cmd=0x00;
readPtr->data=0x00;
delay (100000);//delay for more than 66ms to wait for ranging
bufferPtr->cmd=0x02; //real ranging mode in centimeters
call I2CPacket.write(I2C_START, 0xE0, 1, (uint8_t*)bufferPtr);
delay(50);
call I2CPacket.read(I2C_START, 0xE0, 2, (uint8_t*)readPtr);
delay(250);
call I2CPacket.read(I2C_ACK_END, 0xE0, 0, (uint8_t*)readPtr);
delay(500);
state = 0;
}//end state
call I2CResource.release();
call I2CResource.request();
}
/*********************************************************************************************/
_________________________________________________________________
Help Splitzo Sally Before It’s Too Late!
http://www.thegirlwhosplitinto5.com/_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help