SNAPpy Built-Ins

getInfo()

Expected getInfo() return values:

getInfo(0) # returns 4 meaning "Atmel"
getInfo(3) # returns 6 meaning AT128RFA1

i2cInit()

Beginning with SNAP 2.5, the i2cInit() command allows you to specify which pins to use for SCL and SDA for any platforms based on the AT128RFA1.

peekRadio() and pokeRadio()

These functions are not necessary on the ATmega128RFA1. The internal radio registers are in the main memory space of the chip and can be read or written using the regular peek() and poke() functions.

pulsePin()

Using negative msWidth with the pulsePin() function allows for tighter pulse control. The values have been tuned to produce durations close to 1µs per tick. In SNAP 2.7, the following timings were measured for negative msWidth values:

Value Measured Duration
-1 0.99 µS
-10 9.99 µS
-100 99.999 µS
-1000 1.00000 mS
-10000 9.999996 mS
-20000 19.99999 mS
-30000 29.99998 mS
-32768 32.76797 mS

random()

The pseudo random number generation for random() is done in hardware, not software, as long as the radio is enabled. If you disable the radio receiver, random number generation will be performed by the SNAP software instead.

readAdc()

When using readAdc(), channels 0-7 correspond to direct reads of one of the eight external analog input pins, while channels 8-29 return various “differential” readings as shown in the following table:

Channel Number Returns
0 ADC0
1 ADC1
2 ADC2
3 ADC3
4 ADC4
5 ADC5
6 ADC6
7 ADC7
8 10 * (ADC0 – ADC0)
9 10 * (ADC1 – ADC0)
10 200 * (ADC0 – ADC0)
11 200 * (ADC1 – ADC0)
12 10 * (ADC2 – ADC2)
13 10 * (ADC3 – ADC2)
14 200 * (ADC2 – ADC2)
15 200 * (ADC3 – ADC2)
16 ADC0 – ADC1
17 ADC1 – ADC1
18 ADC2 – ADC1
19 ADC3 – ADC1
20 ADC4 – ADC1
21 ADC5 – ADC1
22 ADC6 – ADC1
23 ADC7 – ADC1
24 ADC0 – ADC2
25 ADC1 – ADC2
26 ADC2 – ADC2
27 ADC3 – ADC2
28 ADC4 – ADC2
29 ADC5 – ADC2

Note

This function returns an integer value 0-1023, since these are 10-bit analog to digital converters. The reference voltage is 1.6 volts. Refer to the ATmega128RFA1 datasheets for more information.

setRadioRate()

On the ATmega128RFA1, setRadioRate() supports the following values for dataRateEnum:

Value Radio Data Rate
0 250 Kbps
1 500 Kbps
2 1 Mbps
3 2 Mbps

Radio rate 0 is compatible with any 2.4 GHz 802.15.4 SNAP radio using rate 0. Any other rate may not work with any non-ATMEL ATmega128RFA1 radio and will only work with a compatible radio working at the same rate.

Because changing from the default radio rate makes the node incompatible with nodes based on other hardware platforms and implies that greater speed is desired, it may be appropriate to set the Turbo Bit in NV64 - Vendor Specific.

sleep()

The ATmega128RFA1 supports timed and untimed sleep modes. Mode 0 should only be used for untimed sleep and mode 2 for timed sleep. In sleep mode 2, the maximum value is 0xA8C0, which is 43200 seconds, or 12 hours. Timed sleep in modes 0 and 1 are now deprecated and should no longer be used.

Sleep mode 2 uses the symbol counter to control its sleep timing, and thus allowing it to have high precision timing.

In the original RF100 SNAP module, the ticks parameter could accept either a zero, a positive, or a negative number. Zero indicates “untimed sleep” (i.e. wake up on pin-interrupt only). Positive numbers indicated how long to sleep in mode-dependent “ticks,” and negative numbers indicated fractions of a second.

On the ATmega128RFA1, zero still indicates “untimed sleep.” Positive numbers indicate how long to sleep in 1.0s “ticks” (regardless of mode).

Negative values for sleep mode 2, from -22,335 (0xA8C1) to -1 (0xFFFF) provide sleep timed to the millisecond for the absolute value of the ticks value entered. For example, sleep(2, -300) would send the node to sleep for 300 milliseconds. Note that the “rollover” from positive to negative values is not at the normal position for 16- bit signed integers. While 0x8000 would normally render as -32767 and thus would suggest a little over 32⅔ seconds of sleep, for sleep mode 2 it would provide 32,768 seconds, or 9:06:08 of sleep. So for values between 32,768 and 43,200, it will be necessary to pass the value using hexadecimal notations of 0x8000 through 0xA8C0. (You can use hexadecimal notation in any situation where you are passing an integer in SNAPpy. This is just one of the times where the hexadecimal notation makes the passed value more clear.)

When the node wakes from sleep mode 2, it restores the symbol counter to the state it was in when the sleep started.

Note

Do not configure the ATmega128RFA1 to wake up from an edge-triggered interrupt on INT4-INT7. This will work, but the processor will not go into a very “deep” sleep, and it will continue to draw a substantial amount of current (~900µA).

getLq()

The ATmega128RFA1 supports two getLq() modes:
  • Invoking getLq() or getLq(0) returns a signal strength in negative dBm. So a return value of 20 indicates that the last transmission received had a signal strength of -20dBm. This matches the behavior of the other SNAP platforms.
  • Invoking getLq(1) returns a link quality measurement from 0 – 255, where 255 indicates the best possible link quality and 0 indicates the worst.

No Effect

The following built-in commands have no effect: