Uma Maheswary
- Dec 14, 2016
- 2
- Joined
- Dec 14, 2016
- Messages
- 2
Hi
I could run the LWmesh peer to peer application for my atmega256rfr2 devices.http://www.atmel.com/tools/lightweight_mesh.aspx.Now I modified the code for reducing power consumption in rf devices.The modified code for sending device is as follows
The device communication works well when the Hibernate() function is not called.But when this function is called it enters into a deep sleep and communicate seldom .dis sleep mode affect rf communication?What is the mistake in my code please help.
I could run the LWmesh peer to peer application for my atmega256rfr2 devices.http://www.atmel.com/tools/lightweight_mesh.aspx.Now I modified the code for reducing power consumption in rf devices.The modified code for sending device is as follows
Code:
volatile int lastPIRsensorState=1;
volatile int PIRsensorState=0;
void Hibernate(){
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
ADCSRA&=~(1<<7);
sleep_enable();
EICRA|=(1<<ISC00);
EIMSK|=(1<<INT0);
sei();
sleep_disable();
EIMSK&=~(1<<INT0);
cli();
}
ISR(INT0_vect){
PIRsensorState=!lastPIRsensorState;
}
static void appDataConf(NWK_DataReq_t *req){
appDataReqBusy=false;
(void)req;
}
static void appSendData(void){
if (appDataReqBusy)
return;
appDataReqBuffer[0]=PIRsensorState;
appDataReq.dstAddr = 1-APP_ADDR;
appDataReq.dstEndpoint = APP_ENDPOINT;
appDataReq.srcEndpoint = APP_ENDPOINT;
appDataReq.options = NWK_OPT_ENABLE_SECURITY;
appDataReq.data = appDataReqBuffer;
appDataReq.size = 1;
appDataReq.confirm = appDataConf;
NWK_DataReq(&appDataReq);
appDataReqBusy = true;
}
static void appTimerHandler(SYS_Timer_t *timer)
{
appSendData();
(void)timer;
}
static void appInit(void)
{
NWK_SetAddr(APP_ADDR);
NWK_SetPanId(APP_PANID);
PHY_SetChannel(APP_CHANNEL);
#ifdef PHY_AT86RF212
PHY_SetBand(APP_BAND);
PHY_SetModulation(APP_MODULATION);
#endif
PHY_SetRxState(true);
HAL_BoardInit();
appTimer.interval = APP_FLUSH_TIMER_INTERVAL;
appTimer.mode = SYS_TIMER_INTERVAL_MODE;
appTimer.handler = appTimerHandler;
}
/*************************************************************************//**
*****************************************************************************/
static void APP_TaskHandler(void)
{
switch (appState)
{
case APP_STATE_INITIAL:
{
appInit();
appSendData();
appState = APP_STATE_IDLE;
} break;
case APP_STATE_IDLE:
break;
default:
break;
}
}
/*************************************************************************//**
*****************************************************************************/
int main(void)
{
SYS_Init();
PORTD=1<<PD0
HAL_UartInit(9600);
while (1)
{
SYS_TaskHandler();
HAL_UartTaskHandler();
APP_TaskHandler();
lastPIRsensorState=PIRsensorState;
Hibernate();
}
}
The device communication works well when the Hibernate() function is not called.But when this function is called it enters into a deep sleep and communicate seldom .dis sleep mode affect rf communication?What is the mistake in my code please help.