Hi all,
I'm kind of new to tinyos(v2.1.1) and currently I'm trying to add a sht11
chip onto my crumb128 board that uses the atm128 microcontroller. I'm not
100% sure of what exacly I'm doing, but basically I am trying to port the
sht11 chip files from the telosa platform to my own.
I made changes mainly to HplSensirionSht11P.nc
which is shown below...
-------------------------------------------------------------
configuration HplSensirionSht11C {
provides interface Resource[ uint8_t id ];
provides interface GeneralIO as DATA;
provides interface GeneralIO as SCK;
provides interface GpioInterrupt as InterruptDATA;
}
implementation {
components HplAtm128GeneralIOC;
//Set PINS
DATA = HplAtm128GeneralIOC.PortB4;
SCK = HplAtm128GeneralIOC.PortB1;
components HplSensirionSht11P;
HplSensirionSht11P.DATA -> HplAtm128GeneralIOC.PortB4;
HplSensirionSht11P.SCK -> HplAtm128GeneralIOC.PortB1;
components new TimerMilliC();
HplSensirionSht11P.Timer -> TimerMilliC;
//SET interrupt pins to be same as DATA
//8 Interrupt pins available in atm128, described as Int0->Int7
//those corresponds to... PD0->PD3 ... PE4->PE7
components HplAtm128InterruptC;
components new Atm128GpioInterruptC() as InterruptDATAC;
InterruptDATAC.Atm128Interrupt -> HplAtm128InterruptC.Int1;
InterruptDATA = InterruptDATAC.Interrupt;
components new FcfsArbiterC( "Sht11.Resource" ) as Arbiter;
Resource = Arbiter;
components new SplitControlPowerManagerC();
SplitControlPowerManagerC.SplitControl -> HplSensirionSht11P;
SplitControlPowerManagerC.ArbiterInfo -> Arbiter.ArbiterInfo;
SplitControlPowerManagerC.ResourceDefaultOwner ->
Arbiter.ResourceDefaultOwner;
}
------------------------------------------------------------------------
the DATA and SCK are in ports B4 and B1 (set to those ports when we got the
sensorboard)
and since B4 is not included as one of the interrupt port, would it cause
the sht11 to not work?
I also removed the PWRM GeneralIO, hence I also made changes to
HplSensirionSht11P which I think makes it do nothing.
------------------------------------------------------------------------
module HplSensirionSht11P {
provides interface SplitControl;
uses interface Timer<TMilli>;
uses interface GeneralIO as DATA;
uses interface GeneralIO as SCK;
}
implementation {
task void stopTask();
command error_t SplitControl.start() {
call Timer.startOneShot( 11 );
return SUCCESS;
}
event void Timer.fired() {
signal SplitControl.startDone( SUCCESS );
}
command error_t SplitControl.stop() {
call SCK.makeInput();
call SCK.clr();
call DATA.makeInput();
call DATA.clr();
post stopTask();
return SUCCESS;
}
task void stopTask() {
signal SplitControl.stopDone( SUCCESS );
}
}
-------------------------------------------------------------------
The following is the application that tells the microcontroller to sample
the sht11 every now and then
-------------------------------------------------------------------
configuration SampleShtAppC
{
}
implementation
{
components MainC;
components SampleShtC;
components new SensirionSht11C() as Sht11;
components new TimerMilliC() as Timer1;
components new TimerMilliC() as Timer2;
components PlatformSerialC;
components ProbomegaLedsC;
SampleShtC -> MainC.Boot;
//SampleShtC -> MainC.SoftwareInit;
//MainC.SoftwareInit -> SampleShtC;
SampleShtC.Timer1 -> Timer1;
SampleShtC.Timer2 -> Timer2;
SampleShtC.ProbomegaLeds -> ProbomegaLedsC;
SampleShtC.Temperature -> Sht11.Temperature;
SampleShtC.TemperatureMetadata -> Sht11.TemperatureMetadata;
SampleShtC.Humidity -> Sht11.Humidity;
SampleShtC.HumidityMetadata -> Sht11.HumidityMetadata;
SampleShtC.StdControl -> PlatformSerialC;
SampleShtC.UartStream -> PlatformSerialC;
}
----------------------------------------------------------------
#include "Timer.h"
#include <string.h>
#include <stdio.h>
module SampleShtC @safe()
{
uses interface Read<uint16_t> as Temperature;
uses interface DeviceMetadata as TemperatureMetadata;
uses interface Read<uint16_t> as Humidity;
uses interface DeviceMetadata as HumidityMetadata;
uses interface Timer<TMilli> as Timer1;
uses interface Timer<TMilli> as Timer2;
uses interface ProbomegaLeds;
uses interface Boot;
uses interface Init as SoftwareInit;
uses interface UartStream;
uses interface StdControl;
}
implementation
{
error_t tempResult = FAIL;
error_t humResult = FAIL;
uint16_t tempVal;
uint16_t humVal;
char buff[256];
event void Boot.booted()
{
call StdControl.start();
call Timer1.startPeriodic( 1024 );
//call Timer2.startPeriodic( 1024 );
}
//Read temperature periodically
event void Timer1.fired()
{
call ProbomegaLeds.led0Toggle();
call Temperature.read();
sprintf(buff,"READ REQUEST\n");
call UartStream.send((uint8_t*)buff,strlen(buff));
}
event void Temperature.readDone( error_t result, uint16_t val )
{
tempResult = result;
tempVal = val;
call UartStream.send((uint8_t*)buff,strlen(buff));
if (tempResult == SUCCESS)
{
sprintf(buff,"SUCCESS\n");
call UartStream.send((uint8_t*)buff,strlen(buff));
sprintf(buff,"Temperature = %d\n",val);
call UartStream.send((uint8_t*)buff,strlen(buff));
}else if (tempResult == EBUSY){
sprintf(buff,"EBUSY\n");
call UartStream.send((uint8_t*)buff,strlen(buff));
}else{
sprintf(buff,"FAIL\n");
call UartStream.send((uint8_t*)buff,strlen(buff));
}
tempResult = FAIL;
}
event void Timer2.fired()
{
call ProbomegaLeds.led1Toggle();
call Humidity.read();
}
event void Humidity.readDone( error_t result, uint16_t val )
{
humResult = result;
humVal = val;
if (humResult == SUCCESS)
{
sprintf(buff,"Humidity = %d\n",val);
call UartStream.send((uint8_t*)buff,strlen(buff));
}
humResult = FAIL;
}
async event void UartStream.receivedByte(uint8_t byte)
{
}
async event void
UartStream.receiveDone(uint8_t *buf, uint16_t len, error_t error)
{
}
async event void
UartStream.sendDone(uint8_t *buf, uint16_t len, error_t error)
{
}
/*default error_t command Temperature.read()
{
return FAIL;
}
default error_t command Humidity.read()
{
return FAIL;
}*/
}
----------------------------------------------------------------
the problem I am having here is that the result from the
Temperature.readDone seems to always give 'FAIL' which I think means that it
failed to read from the sht11. Is this because we need to do something to
the sht11 before data can be read?
I read in TEP109 that "When a HIL component is being used, the sensor MUST
initialize itself, either by including the MainC component and wiring to
the SoftwareInit interface, or by allowing a lower-level component (like an
ADC) to initialize itself." I thought this might be the problem but then
I'm not too sure either. If it is the problem, how exactly do we wire the
SoftwareInit interface?
Thanks in advance
Gavin
_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help