Hello, all
   I   feel very strange about I2C communication in micaz with Tinyos 2.0.
   The same example in the mail-list follows
 
TestC.nc file.
#include <I2C.h>

 module TestC {
  uses {
    interface Boot;
    interface Leds;
    interface GeneralIO as SoundPower;
   interface GeneralIO as SoundOutpt;
      interface Resource;
    interface I2CPacket<TI2CBasicAddr>;
  }
 }
 implementation {

  uint8_t Buffer[2];
  uint8_t RBuffer[2];

 void wait()
  {
 uint8_t i;
 for(i=0;i<100;i++){  
 asm volatile ("nop" :: );
 asm volatile ("nop" :: );
 asm volatile ("nop" :: );
  
  }
 }

  event void Boot.booted() {
      //call SoundPower.makeOutput();
      //call SoundOutpt.makeOutput();
      //call SoundPower.set();
      //call SoundOutpt.clr();            
     call Resource.request();
 }
  event void Resource.granted() {
    Buffer[0] = 0x01;
    Buffer[1] = 0x40;
     
   
      if (call I2CPacket.write(I2C_START | I2C_STOP, 0xC0, 1, &Buffer 
 [0]) == SUCCESS) {
     call Leds.led2On();
  //  wait();
      if (call I2CPacket.read(I2C_START | I2C_STOP, 0xC0, 1, &RBuffer 
   [0]) == SUCCESS) call Leds.led1On();
    }
  }
  async event void I2CPacket.readDone(error_t error, uint16_t addr,  
  uint8_t length, uint8_t* data) {
     //  call Leds.led2On();

  }
  async event void I2CPacket.writeDone(error_t error, uint16_t addr,  
  uint8_t length, uint8_t* data) {
   call Leds.led0On();

  }
 }

TestAppC.nc file:
configuration TestAppC {}
 implementation {
  components TestC, MainC, MicaBusC,  LedsC;
  components new Atm128I2CMasterC();
  TestC.Boot -> MainC;
  TestC.Leds -> LedsC;
  TestC.SoundPower -> MicaBusC.PW3;
  TestC.SoundOutpt -> MicaBusC.PW6;
  TestC.Resource -> Atm128I2CMasterC;
  TestC.I2CPacket -> Atm128I2CMasterC;
 }

As somebody suggested I have changed the  I2C.init(FALSE) into
 I2C.init(TRUE) in the Atm128I2CMasterPacketP.nc; Now when I used the 
Oscilloscope to observe the signal, we can find the write operation is finished.
But the read operation can not continue even I add delay using the wait() 
function.
I track the I2CPacket.read in the Atm128I2CMasterPacketP.nc;
Find when implement  I2CPacket.read()  the state is I2C_STARTING. Logically in 
I2C.commandComplete() before signal I2CPacket.writeDone(SUCCESS, packetAddr, 
packetLen, packetPtr), the state has been changed into I2C_IDLE.
I  can not find which operation changes the state variable. So I am very 
confused about it.
Does anybody can help me?
Thanks a lot.

Jianxin



_________________________________________________________________
MSN 中文网,最新时尚生活资讯,白领聚集门户。
http://cn.msn.com
_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to