-48-
v6.3
Architecture and System
4. Architecture and System
4.1. Concepts
The Waspmote’s architecture is based on the Atmel
ATMEGA 1281
microcontroller. This processing unit starts executing the
bootloader
binary, which is responsible for loading into the memory the compiled programs and libraries previously stored in
the FLASH memory, so that the main program that has been created can finally begin running.
When Waspmote is connected and starts the
bootloader
, there is a waiting time (62.5ms) before beginning the first instruction,
this time is used to start loading new compiled programs updates. If a new program is received from the USB during this time,
it will be loaded into the FLASH memory (128KB) substituting already existing programs. Otherwise, if a new program is not
received, the last program stored in the memory will start running.
The structure of the codes is divided into 2 basic parts:
setup
and
loop
. Both parts of the code have sequential behaviour,
executing instructions in the set order.
The
setup
is the first part of the code, which is only run once when the code is initialized. In this part it is recommended to
include the initialization of the modules which are going to be used, as well as the part of the code which is only important
when Waspmote is started.
The part named
loop
runs continuously, forming an infinite loop. Because of the behavior of this part of the code, the use of
interruptions is recommended to perform actions with Waspmote.
A common programming technique to save energy would be based on blocking the program (either keeping the micro awake
or asleep in particular cases) until some of interruptions available in Waspmote show that an event has occurred. This way, when
an interruption is detected the associated function, which was previously stored in an interruption vector, is executed.
To be able to detect the capture of interruptions during the execution of the code, a series of flags have been created and will
be activated to indicate the event which has generated the interruption (see chapters “Interruptions” and “Energy System”).
Figure: Blocking loop, interruption appears and is dealt with
When Waspmote is reset or switched on, the code starts again from the setup function and then the loop function.
By default, variable values declared in the code and modified in execution will be lost when a reset occurs or there is no battery.
To store values permanently, it is necessary to use the microcontroller’s
EEPROM (4KB)
non-volatile memory. EEPROM addresses
from 0 to 1023 are used by Waspmote to save important data, so they must not be over-written. Thus, the available storage
addresses go from 1024 to 4095. Another option is to use of the high capacity
2GB SD card
.