Welcome Guest,Register Now
Log In

ANT Forum

Welcome guest, please Login or Register

   

Frustrations with sparkfun USB ANT stick and nRF24AP1 module

Rank

Total Posts: 1

Joined 0

PM

Hi,

I've been struggling with getting an ANT connection setup with the Sparkfun nRF24AP1 board and USB ANT stick. They provide some C code for an ATMega 168 (I modified to work with ATMega328p), but it appears to have some errors in it. I have worked a lot on this code, and think I have come up with a working solution, but I can't seem to get the connection established.

http://www.sparkfun.com/products/8840

http://www.sparkfun.com/products/8565

I send 6 packets to the nRF24AP1 board, and confirm that RTS goes high after each packet (confirming proper baud rate, message format, etc.). I have installed the FTDI drivers, and the ANT stick shows up as a COM port. I have a COM sniffer set for 4800bps, but it shows nothing when I send data. Nor does the LED on the ANT stick light up.

I've put a ton of time into this, and am totally lost at this point since I don't know of any way to diagnose what the problem is. Does anybody have experience with setting up a simple ANT connection, and could take a look at my code? I believe I have commented it adequately.

Is there anything else I would need to do with the ANT stick? I'm assuming all that needs to be done is install FTDI drivers, make sure jumpers are set for 4800bps, and start monitoring the COM port.


As a quick reference, I have set the following parameters on my nRF24AP1 module:

network # = 0
channel # = 0
Device # = x0031
Device type ID = x01
channel type = x10
transmission type = x01


Thanks for the help!! (I crossposted in the sparkfun forums but have had no luck there)

DC

/* 
* AP1_master.c 

* Created: 5/15/2011 4:09:22 PM 
*  Author: DC 
*/ 
/* 
    07-07-08 
    Copyright Spark Fun Electronics© 2008 
    Aaron Weiss 
   aaron at sparkfun.com 
    
    Master AP1 Intitialization @ 4800bps 
*/ 

#include <stdlib.h> 

#include <stdio.h> 
#include <avr/io.h> 
#include <avr/pgmspace.h> 

//#define FOSC 8000000 // 8MHz         //ORIGINAL 
#define F_CPU 8000000 // 8MHz         //I added 
#define BAUD 4800 
#define MYUBRR 103 // Calculated from http://www.wormfood.net/avrbaudcalc.php 

#define sbi(var, mask)   ((var) |= (uint8_t)(1 << mask)) 
#define cbi(var, mask)   ((var) &= (uint8_t)~(1 << mask)) 

#define STATUS_LED 5 // Pin 28 (PC5) 

// Define functions 
//======================= 
void ioinit(void);      // initializes IO 
static int uart_putchar(char cFILE *stream); // sends char out of UART 
uint8_t uart_getchar(void); // receives char from UART 

static FILE mystdout FDEV_SETUP_STREAM(uart_putcharNULL_FDEV_SETUP_WRITE); 

void delay_ms(uint16_t x); // general purpose delay 

void config(void); // runs config functions 
//======================= 

// Configuration functions 
//======================= 
void reset(void); 
void assignch(void); 
void setchid(void); 
void opench(void); 
void setchperiod(void); 
void send(void); 
//======================= 

int main (void

    ioinit
(); 
    
   
sbi(PORTCSTATUS_LED);  //Just to inform that everything is powered up 
    
   
config(); 
    
   while(
1
    

    
   sbi
(PORTCSTATUS_LED); 
   
delay_ms(500); //was 500 
   
cbi(PORTCSTATUS_LED); 
   
delay_ms(500);  //was 500 
   

    
return(0); 



void config 
(void

   reset
(); 
   
delay_ms(1000);  
   
assignch(); 
   
delay_ms(1000);  
   
setchid(); 
   
delay_ms(1000); 
   
setchperiod();    
   
delay_ms(1000); 
   
opench(); 
   
delay_ms(1000);  
   
send(); 


// Resets module 
void reset (void

   uint8_t i

   
uint8_t setup[7]
    
   
//start test code 
   //uint8_t test; 
   //test = 0xA; 
   //putchar('U'); 
   //putchar('A'); 
   //end test code 
    
    
   
setup[0] 0xa4// SYNC Byte 
   
setup[1] 0x01// LENGTH Byte 
   
setup[2] 0x4a// ID Byte 
   
setup[3] 0x00// Data Byte N (N=LENGTH) 
   
setup[4] 0xef// Checksum 
   
setup[5] 0x00// zero pad 
   
setup[6] 0x00// zero pad 
    
   
for(i++) 
    

   putchar
(setup[i]); 
    



// Assigns CH=0, CH Type=10(TX), Net#=0 
void assignch (void

   uint8_t i

   
uint8_t setup[9]
    
   
setup[0] 0xa4;   //Sync 
   
setup[1] 0x03;   //Length = 3 bytes 
   
setup[2] 0x42;   //Message ID = assign channel 
   
setup[3] 0x00;   //ch # 0 
   
setup[4] 0x10;   //ch type=10 
   
setup[5] 0x00;   //Network # = 0 
   
setup[6] 0xf5;   //Checksum 
   
setup[7] 0x00;   // zero pad 
   
setup[8] 0x00;   // zero pad 

   
for(i++) 
    

   putchar
(setup[i]); 
    



// Assigns Device#=3100 (actually 31 - little endian), Device Type ID=01, Trans Type=01 
void setchid (void

   uint8_t i

   
uint8_t setup[11]
    
   
setup[0] 0xa4;   //Sync byte 
   
setup[1] 0x05;   //Length = 5 bytes 
   
setup[2] 0x51;   //message ID = set channel ID 
   
setup[3] 0x00;   //ch # 0 
   
setup[4] 0x31;   //Device number = 0031 (little endian), so 31 here 
   
setup[5] 0x00;   //Device number = 0031 (little endian), so 00 here 
   
setup[6] 0x01;   //Device type ID = 01 
   
setup[7] 0x01;    //WAS 0x05.  This is transmission type, and I changed to 0x01 (no shared address) as in example on p16 of ANT guide 
   
setup[8] 0xc1;   //checksum 
   
setup[9] 0x00// zero pad 
   
setup[10] 0x00// zero pad 
    
   
for(11 i++) 
    

   putchar
(setup[i]); 
    



// Opens CH 0 
void opench (void

   uint8_t i

   
uint8_t setup[7]
    
   
setup[0] 0xa4;   //sync 
   
setup[1] 0x01;   //length = 1 
   
setup[2] 0x4b;   //message ID = open channel 
   
setup[3] 0x00;   //ch # 0 
   
setup[4] 0xee;   //checksum 
   
setup[5] 0x00// zero pad 
   
setup[6] 0x00// zero pad 
    
   
for(i++) 
    

   putchar
(setup[i]); 
    



// Sets channel period to 4 Hz (8192) 
void setchperiod (void

   uint8_t i

   
uint8_t setup[9]
    
   
setup[0] 0xa4;   //sync 
   
setup[1] 0x03;   //Length = 3 (short needed, little endian) 
   
setup[2] 0x43;   //message ID = set channel period 
   
setup[3] 0x00;   //ch # 0 
   
setup[4] 0x92;   //Least significant byte of 8192 
   
setup[5] 0x81;   //Most significant byte of 8192 
   
setup[6] 0xf7;   //checksum 
   
setup[7] 0x00// zero pad 
   
setup[8] 0x00// zero pad 
    
   
for(i++) 
    

   putchar
(setup[i]); 
    



// Sends Data=AAAAAAAAAAAAAAAA 
void send (void

   uint8_t i

   
uint8_t setup[13]
    
   
setup[0] 0xa4;   //sync 
   
setup[1] 0x09;   //length = 9 bytes 
   
setup[2] 0x4e;   //message id = broadcast data 
   
setup[3] 0x00;   //ch # 0 
   
setup[4] 0xaa
   
setup[5] 0xaa
   
setup[6] 0xaa
   
setup[7] 0xaa
   
setup[8] 0xaa
   
setup[9] 0xaa
   
setup[10] 0xaa
   
setup[11] 0xaa
   
setup[12] 0xe3
    
   for(
13 i++) 
    

   putchar
(setup[i]); 
    



void ioinit 
(void

    
//1 = output, 0 = input 
    
DDRB 0b11101111//PB4 = MISO 
    
DDRC 0b11111111//all outputs 
    
DDRD 0b11111110//PORTD (RX on PD0) 

    //USART Baud rate: 4800 
    
UBRR0H = (MYUBRR >> 8); 
    
UBRR0L MYUBRR
    
UCSR0B = (1<<RXEN0)|(1<<TXEN0); 
    
    
stdout = &mystdout//Required for printf init 


static int uart_putchar(char cFILE *stream

    
if (== '\\n'uart_putchar('\\r'stream); 
  
    
loop_until_bit_is_set(UCSR0AUDRE0); 
    
UDR0 c
    
    return 
0


uint8_t uart_getchar
(void

    
while( !(UCSR0A & (1<<RXC0)) ); 
    return(
UDR0); 


//General short delays 
void delay_ms(uint16_t x

  uint8_t y
zw
  for ( ; 
x--)
    
for ( 90y++){               //was 90, 11 gives delayms(500) actually 500ms at 8MHz 
      
for ( 8w++){            //New - put in to compensate for clock divide by 8 error in original 
         
for ( z++)
            asm volatile 
("nop"); 
      
}          
      } 
    } 
  } 
     
Rank

Total Posts: 4

Joined 0

PM

Hey man, i'm using the same devices, and i'm with problem too.

But one thing i can tell you: you have to configure the USB Stick to.

You will use the code example at sparkfun's website called "slave".

It's very similar to the "master", but you setup as a receiver, and the function setchid, you'll fill with zero's as a wildcard. That's why the USB Stick has the tx/rx pins.

I'm doing it with the software Termite. I can receive messages back looking like the USB Stick is correctly configures, but, a while after that a receive a "search timeout" and it starts to send me a lots of messages saying the connection fail. (and the led blinks, heheheh)

So i think i'm with problems with the nRF24AP1. I'm using the same code as you are, but i've put the send() function inside the looping while(1), to send 0xAA intermittently.

But i don't know how to debug the nRF24AP1 and see if it is really sending the packets, you know, because it doesn't have a led or something that we can see what's happening.

I hope that i could help a little. (sorry for the bad english, i'm brazilian)

Good luck,
Cauê