my mica2 node connects ADXL345 by I2C interface, my hardware is ok ,It is
tested in language C ,and the result is right. While I write the programme
in nesc ,and  the results turn out to be A7,no matter what register it is .I
am sure the slave address is right. anybody know what is the problem is it?
Parts of the programme as follows:
///////////////////////////////////////////////////////////////////////////////////////////////
 event void Boot.booted()         //系统启动
          {
                call BusyWait.wait(1.1);
                if (call Uart1Control.start()==SUCCESS)
                {
                        call Timer.startPeriodic(SAMPLING_FREQUENCY);
                }
          }

           event void Timer.fired() {    
                        cmd=ADXL345_READ_X_LOW;
                        call I2CResource.request();
         
          }

          event void I2CResource.granted()
     {
                call BusyWait.wait(1000);
                call I2CPacket.write(I2C_START |I2C_STOP, ADXL345_ADDRESS,1, 
&cmd);
                //call Leds.led0On();   
     }

        //      task void readDoneTask();

  async event void I2CPacket.writeDone(error_t error, uint16_t addr, uint8_t
length, uint8_t *data)
  { 
        if (call I2CResource.isOwner()==FALSE) return;

        atomic if (error==SUCCESS) 
        { 
                if (call I2CPacket.read(I2C_START | I2C_STOP, ADXL345_ADDRESS,
sizeof(adc_value), &adc_value)!=SUCCESS) 
                 {
                        call I2CResource.release();
                         return; 
                 }
    }   
  }

//*************************************************************************

        task void readDoneTask()
        {
                if (call UartStream.send(&ch0,1*sizeof(uint8_t))==SUCCESS)      
                {};//call Leds.led1Toggle();    
        }
                
         async event void I2CPacket.readDone(error_t error, uint16_t addr, 
uint8_t
length, uint8_t *data)    {
                        
                        if (error == SUCCESS)
                                {
                                        //call Leds.led2On();
                                        ch0=*data;
                                call I2CResource.release();
                                post readDoneTask();
                        }
                                
                        
                }



--
View this message in context: 
http://tinyos-help.10906.n7.nabble.com/problem-ADXL345-with-I2C-interface-on-mica2-tp23372.html
Sent from the TinyOS - Help mailing list archive at Nabble.com.

_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to