DolphinV4 API  1.6.1.0
Autarkic Sensor Example



Application file - main.c

/************************************************************************-
EVA Board:
EVA320-2
Input PIN:
ADIO_0
Output PIN:
SCSEDIO_0
is set at wakeup and reset before entering deep sleep
SCLKDIO_1
indicates sending of the telegram
Description:
This example demonstrates an autarkic sensor which performs deep sleep and
wakes up every 10 seconds. After wake-up 3 subtelegrams are transmitted to
the air. An analogue measurement of the ADIO_0 is performed. An 8-bit variable
increments every time the program starts. The program stores the value in RAM0.
After the subtelegrams were transmitted the application goes to deep sleep.
Notes:
The GPIO is switched off during deep sleep and the pauses between radio subtelegrams.
Timer0 interrupt, which manages the API internal scheduler, is not activated in this example to save energy.
-************************************************************************/
#include "EO3100I_API.h"
#include "EO3100I_CFG.h"
#define led_pwrOn(); io_setDigital(SCSEDIO_0,1);
#define led_pwrOff(); io_setDigital(SCSEDIO_0,0);
#define led_txOn(); io_setDigital(SCLKDIO_1,1);
#define led_txOff(); io_setDigital(SCLKDIO_1,0);
code uint8 VERSION_APP[] = {0xE0,'V','E','R','S','I','O','N',1,0,1,0,'A','A','U','T','A','R','K','I','C','S','E','N','S','O','R',0x00,0xE0};
typedef union
{
uint8 u8byte[32];
struct
{
uint8 u8Counter;
} value;
} RAM0_SHADOW;
RAM0_SHADOW ungRam0;
void measurement(uint8 *pu8ADIO0);
void main()
{
uint32 data u32WatchdogPeriode;
RESET_TYPE data u8ResetSrc;
uint8 u8Meas;
//Configuration in EO3100I_cfg.h
mainInit();
led_pwrOn();
//Get the info where are we comming from
pwr_getSystemReset(&u8ResetSrc);
// Header
rTel2.raw.bytes[0] = RADIO2_HDR_SRCID32_BCAST | RADIO2_HDR_RORG_4BS; // Header: Only 32 bit Originator-ID, no extended Header, 4BS telegram
// SourceId
rTel2.raw.bytes[1] = 0x00; // Id
rTel2.raw.bytes[2] = 0x00; // Id
rTel2.raw.bytes[3] = 0x00; // Id
rTel2.raw.bytes[4] = 0x00; // Id
// Data 4 bytes
rTel2.raw.bytes[5] = 0x00; // Data MSB
rTel2.raw.bytes[6] = 0x00; // Data byte
rTel2.raw.bytes[7] = 0x00; // Data byte
rTel2.raw.bytes[8] = 0x00; // Data LSB
// Length
rTel2.raw.u8Length = 10; // The API needs an extra byte to insert the CRC of the radio telegram.
// Measurement of analogue values
measurement(&u8Meas);
switch (u8ResetSrc)
{
case PIN_RESET:
case VDD_RESET:
// this is the actual calibration to avoid a floating multiplication
u32WatchdogPeriode = (uint32)((uint32)CONV_TIME_TO_COUNTER(10, SEC,WATCHDOG_CLK)*gModArea.val.u16CalibWatchdog)/WATCHDOG_CALIB_CONST;
pwr_setSleepTimer(WATCHDOG_TIMER, u32WatchdogPeriode,0);
// Initialize the RAM0...
ungRam0.value.u8Counter = 0;
// ...by writing the RAM0 byte 0 (only 1 byte. Max value for the 3rd parameter is 32) with the information in the ungRam0 structure.
mem_writeRAM0((uint8*)&ungRam0, 0x00, 1);
break;
default:
break;
}
// Copy RAM0 first byte in ungRam0
mem_readRAM0((uint8*)&ungRam0, 0x00, 1);
rTel2.raw.bytes[5] = ungRam0.value.u8Counter;
rTel2.raw.bytes[7] = u8Meas;
// Initialize random number generator for the subtelegram timing
misc_rndInit(ungRam0.value.u8Counter + u8Meas);
// Send telegram
led_txOn();
radio_sendTelegram2(&rTel2, NULL);
led_txOff();
// Increment counter and store in RAM0
ungRam0.value.u8Counter++;
mem_writeRAM0((uint8*)&ungRam0, 0x00, 1);
led_pwrOff();
// Jump to deep sleep mode
// We should not get here
while(1);
}
void measurement(uint8 *pu8ADIO0)
{
sint16 s16adio0value;
sint16 s16posref;
uint16 u16MeasScaled;
io_enableAnalog(1); // disable analogue module
io_ulpMeasAnalog(GPIO1_ADIO_0 , RVSS, &s16adio0value); // measure ADIO_0 against internal reference voltage
io_ulpMeasAnalog(RVDD , RVSS, &s16posref); // measure positive reference against internal reference voltage
io_ulpScaleAnalog(s16posref , s16adio0value, 8, &u16MeasScaled); // scale the ADIO_0 against the positive reference, using 8-bit resolution.
*pu8ADIO0 = (uint8)u16MeasScaled;
io_enableAnalog(0); // disable analogue module
}



Config file - EO3100I_CFG.h

// Generated on 2013-06-07 16:58:05 by DolphinAPIConfigurator 1.1.0.20
#ifndef _EO3100I_CFG_H_INCLUDED
#define _EO3100I_CFG_H_INCLUDED
void startupInit();
void mainInit();
//*********************RADIO PARAM***************************
#define RADIO_BUFF_NUM 10
#define RADIO_MATURITY_TIME 100
extern volatile RADIO_BUFFER_TYPE xdata gRadioBuff[RADIO_BUFF_NUM];
//*********************FILTER PARAM***************************
#define FILTER_NUM 1
extern volatile uint32 xdata u32gFilterValue[FILTER_NUM];
extern volatile uint8 xdata u8gFilterCfg[FILTER_NUM];
//*********************IO PARAM******************************
extern uint8 code io_param[];
#endif //_EO3100I_CFG_H_INCLUDED



Config file - EO3100I_CFG.c

// Generated on 2013-06-07 16:59:28 by DolphinAPIConfigurator 1.1.0.20
#include "EO3100I_API.h"
#include "EO3100I_CFG.h"
//*********************API INIT***************************
//Note: Function is called from startup.a51. Global variables are not yet initialized!
void startupInit()
{
io_init(io_param);
}
void mainInit()
{
radio_init(RADIO_BUFF_NUM, RADIO_MATURITY_TIME);
}
//*********************RADIO PARAM***************************
volatile RADIO_BUFFER_TYPE xdata gRadioBuff[RADIO_BUFF_NUM];
//*********************FILTER PARAM***************************
volatile uint32 xdata u32gFilterValue[FILTER_NUM];
volatile uint8 xdata u8gFilterCfg[FILTER_NUM];
//*********************IO PARAM******************************
uint8 code io_param[] = {
0x07, //IDX_GPIO_CONF
0x00, //IDX_GPIO0_CONF
0x0C, //IDX_GPIO0_PULL_CONF
0x03, //IDX_GPIO0_DIR
0x01, //IDX_GPIO1_AN
0x00, //IDX_GPIO1_CONF0
0x00, //IDX_GPIO1_CONF1
0x03, //IDX_GPIO1_DIG_CONF
0x00, //IDX_GPIO1_DIR
0xFF, //IDX_GPIO1_PULL
0x0C, //IDX_GPIO2_CONF
0x00, //IDX_GPIO2_DIR
0x00, //IDX_GPIO0
0x00, //IDX_GPIO1
0x00, //IDX_GPIO2
};
// I/O Configuration overview
//
// Pin : Interface Direction Pull InitValue Interrupt
// SCSEDIO0 : Digital I/O Out None 0 No
// SCLKDIO1 : Digital I/O Out None 0 No
// WSDADIO2 : Digital I/O In Up 0 No
// RSDADIO3 : Digital I/O In Up 0 No
// ADIO0 : Analogue I/O In Up 0 No
// ADIO1 : Digital I/O In Up 0 No
// ADIO2 : Digital I/O In Up 0 No
// ADIO3 : Digital I/O In Up 0 No
// ADIO4 : Digital I/O In Up 0 No
// ADIO5 : Digital I/O In Up 0 No
// ADIO6 : Digital I/O In Up 0 No
// ADIO7 : Digital I/O In Up 0 No
// WXIDIO : Digital I/O In Up 0 No
// WXODIO : Digital I/O In Up 0 No
// WAKE0 : Digital I/O In None 0 No
// WAKE1 : Digital I/O In None 0 No