Go Down

Topic: An interface for ANT radios... librarification advice? (Read 4093 times) previous topic - next topic


Hi all,
Attached is a preliminary sketch that provides an interface to low-power ANT radios (used by most Garmin and Suunto sports products). ANT is a TDMA protocol in which the radio Tx/Rx are only powered during very short pre-arranged timeslots and spend the other 99.9% of their time sleeping. All the timing is handled by the radio IC - when data is transmitted or received (which occurs at a regular interval), it generates an interrupt and transfers an event message to the host (e.g. "Tx OK" event or received payload, etc.). Message rate can range from once per two seconds (minimum) to up to some low hundreds per second(?) maximum, although a dozen or less per second would be typical.

The code attached shows a very simple use case where the Arduino creates a single broadcast channel and then sends one payload (in this case, the same payload) each time it is waked by the radio interrupt (e.g. in response to the last payload being transmitted, which generates an "EVENT_TX" event). As ANT is intended for very low-power systems, the interrupt-driven "sleep until something interesting happens" use-case shown will be very common.

While the code attached "works", I'd like to make it into a full-fledged Arduino library that can ideally be called from higher-level libraries (e.g. future mesh-networking stack), and operate by having the user or higher-level library register their own event handlers (e.g. callback functions) for the different types of event messages generated by the radio.

Some specific advice I could use on the 'best' way to make this into a library are:

Code efficiency - C vs c++ libraries? (I've heard it's possible to make a straight C library for Arduino, but never actually seen one. Is it worth it?)

Function calls (e.g. digitalWrite) inside an ISR - does this generate problems, performance or otherwise? (I know that the compiler for PIC18 micros adds an absolutely dreadful amount of context save/restore the moment the ISR includes a function call, is this the case for avr-gcc as well?)

Best practices on making the library functions usable by other libraries?

Using and passing callbacks to a function inside a class? (related to previous question - a function in library B passing its address to a function in library A to register as an event handler. I seem to recall reading this is a giant nono.)



Very cool!  I want one!  Will read your library.  How hard is it to wire the ANT side to a sensor?  How much does the UNO side cost?  This might work great together with Xbee to communicate to a PC.


You don't wire the ANT chip to a sensor, but you can wire them both to the same Arduino. You shouldn't need both an ANT and XBee radio, unless you are building an ANt-to-XBee network bridge :-) To interface to a PC, some dedicated USB receiver sticks are available (Garmin makes the 'official' one, but Sparkfun also has a version), or a second Arduino plugged into the PC can act as the receiver.

Sparkfun has modules using the older 'AP1' variants for about $25, about comparable with XBees. (They are hardwired in async. serial mode; the final library should support this mode too.) If you are making your own PCB it can be much cheaper (the IC itself is ~$3.50). If you go that route, I'd recommend using the newer 'AP2' series chip (nRF24AP2).

Anyone with advice / best-practices on a library design as described above? :-)

Go Up