[[ANT]]

* Library for PIC24F [#vdabf719]

>
This page introduces  ANT library for PIC24F series and its sample code. PIC24F is a 16bit microcontroller (IC) and produced by Microchip Technology Inc. The source code is compiled and executed at PIC24FJ64GA002. This library is still alpha version, and there is possibly a lot of bug in the code.~
This page introduces  ANT library for PIC24F series and its sample code. PIC24F is a 16bit microcontroller (IC) and produced by [[Microchip Technology Inc.>http://www.microchip.com/]] The source code is compiled and executed at [[PIC24FJ64GA002>http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en026374]]. This library is still alpha version, and there is possibly a lot of bug in the code.~

>
- ant.h
-- This is a header file, which lists the API functions for an ANT chip.
- ant.h &ref(ant.h);~
-- This is a header file, which lists the API functions for an ANT chip.~

>
- ant.c
-- This is C source code for API functions, which enable to communicate with the ANT chip. To execute this code, a function, which works with UART1 that listed at uart.c, is required. 
- ant.c &ref(ant.c);~
-- This is C source code for API functions, which enable to communicate with the ANT chip. To execute this code, a function, which works with UART1 that listed at uart.c, is required.~

>
- uart.h
-- The is a header file listing the API that works with UART.
- uart.h &ref(uart.h);~
-- The is a header file listing the API that works with UART.~

>
- uart.c
-- C source code for API functions, which work with UART.
- uart.c &ref(uart.c);~
-- C source code for API functions, which work with UART.~

>
To exchange the commands and results with ANT chip, ant.c calls the functions which works with uart1 listed on uart.c. In this example, both uart.c and uart.h are required.~
At transmitting information, uart.c acceses via polling. uart.c also uses interrupt to receive the information since the reception of data is managed by interrupt-driven.~
The pins, which are re-mappable, are assigned to RX and TX of UART. In uart.c, there are comments about pin assignments, but the assignments of re-map pins can be changed according to your PCB.~ 
At the example shown below, RTS of ANT module is assigned to RA3 and performs polling by software. There is no hardware flow. The example can be modified based upon your circuit.~

** Example [#f839f2b7]
>
 #include <ant.h>
 #include <uart.h>
 
 #define   DEVICE_NUMBER   31
 #define   MAX_BUFSIZE     32
 
 #define   ANT_CH          0
 
 unsigned  char buffer[MAX_BUFSIZE];
 
 void OpenANT() {
 //  This function sets the communication parameter at 0ch and opens the channel
 
	ANT_ResetSystem();                                         // resetting the ANT device
 
	ANT_AssignChannel( ANT_CH, ANT_Bidirectional_Slave, 0) ;   // Assigning a channel to a receiving channel
	ANT_SetChannelId( ANT_CH,  DEVICE_NUMBER, 1, 1 );          // Setting Device Number and other Device ID
 
	ANT_SetChannelPeriod_Hz( ANT_CH, 4 );                      // Setting Channel Period at 4Hz  (this is the same as the default, so you may skip it )
	ANT_SetChannelRFFreq( ANT_CH, 4 );                         // Setting frequency at 2404MHz 
 
	ANT_OpenChannel( ANT_CH );                                 // Opening the channel and starting communicating
 
       return;
 }
  
 void main () {
  
   int s;
   
 //  Input initializing code for hardware 
 //    write down the I/O mode of each port and whether each port has open-drain or not.    
 //
  
    uart_init( 38400, 0 );            // Initializing UART resistor 
                                      // Caution) To communicate to an ANT module at 38400bps, chip resistors are required. 
    OpenANT();
 
    while(1) {
        if ( s = BC_ANT_RecvPacket( buffer, MAX_BUFSIZE )) {
            // Processing data as it receives data from the ANT chip...
            // Writing down how to process as it receives pakets and/or events from the ANT chip
        }
    }
 
 }
* Revision History [#bbddba0e]
>
- 2013/02/01 This article is initially uploaded



Front page   New List of pages Search Recent changes   RSS of recent changes