Hey guys Thanks for all your time. My name is Jaosn. Currently im working on a project using Tmote Sky and MMA8452 which is a accelerometer sensor. I try to use tinyos I2C API to write/read from the MMA8452, but the readdone is always fail. i was so confused about it. could someone help me out please. I don't know whether do i need to use some other interface besides the Resource and I2CPacket? How can i initialize the transmission? appreciate for your help. sincerely Jason
below is my code: 2 #include "printf.h" 3 #include <Timer.h> 4 #include <I2C.h> 5 6 7 module ReceiverC { 8 uses { 9 interface Boot; 10 interface Leds; 11 interface Resource; 12 interface Timer<TMilli> as Timer0; 13 interface I2CPacket<TI2CBasicAddr> I2CPacket; 14 } 15 } 16 17 implementation { 18 19 uint8_t reg_addr; 20 uint8_t reg_value; 21 22 event void Boot.booted(){ 23 call Timer0.startPeriodic(3000); 24 } 25 26 event void Timer0.fired() 27 { 28 printf("Timer0 short\n"); 29 printfflush(); 30 call Resource.request(); 31 } 32 event void Resource.granted() { 33 reg_addr = 0x0D; 34 call I2CPacket.write(I2C_START, 0x3A, 1, ®_addr); 35 } 36 37 async event void I2CPacket.writeDone(error_t error, uint16_t addr, uint8_t length, uint8_t* data) { 38 if (error == SUCCESS){ 39 call Leds.led0Toggle(); 40 printf("w d success\n %u", *data); 41 } else if ( error == FAIL){ 42 printf("w d fail\n"); 43 } 44 printfflush(); 45 call I2CPacket.read(I2C_STOP, 0x3B, 1, ®_value); 46 } 47 async event void I2CPacket.readDone(error_t error, uint16_t addr, uint8_t length, uint8_t* data) { 48 if (error == SUCCESS){ 49 call Leds.led1Toggle(); 50 printf("r d success\n"); 51 } else if ( error == FAIL){ 52 printf("r d fail\n%u", *data); 53 } 54 printfflush(); 55 call Resource.release(); 56 } 57 } -- View this message in context: http://tinyos-help.10906.n7.nabble.com/Question-For-TinyOS-I2C-Please-Help-tp23026.html Sent from the TinyOS - Help mailing list archive at Nabble.com. _______________________________________________ Tinyos-help mailing list Tinyos-help@millennium.berkeley.edu https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help