Don't ad-block us - support your favorite websites. We have safe, unobstrusive, robotics related ads that you actually want to see - see here for more.
0 Members and 1 Guest are viewing this topic.
#include "sys/axon2.h"#include "rprintf.h"void appInitHardware(void) { uartInit(UART1, (BAUD_RATE)115200); uartInit(UART0, (BAUD_RATE)38400); rprintfInit(&uart1SendByte); rprintf("\nAxon II Initiated.\n");}TICK_COUNT appInitSoftware(TICK_COUNT loopStart){ return 0;}// This is the main loopTICK_COUNT appControl(LOOP_COUNT loopCount, TICK_COUNT loopStart) { while(!uartReceiveBufferIsEmpty(UART0)) { int byte = uartGetByte(UART0); rprintf("%d", byte); uartSendByte(UART0, byte); } return 10;}
//==============================================================================// [GetXBeeHVal] - Set the XBee DL or MY or??? Simply pass the two characters// that were passed in to the XBEE//==============================================================================WORD GetXBeeHVal (char c1, char c2){ WORD wDL; BYTE bTemp[10]; // temporary buffer BYTE cbRead; BYTE i; pin_toggle(L3); ClearXBeeInputBuffer(); // Clear our input buffer rprintfInit(WIRELESS_ACTIVATE); wDL = -1; // an error condition clockWaitms(20); // wait 20ms for quard time to enter into command mode rprintf("+++"); // Now output the string to enter command mode WaitForXBeeTransmitComplete(); clockWaitms(20); // wait 20ms for quard time to enter into command mode rprintf("AT%c%c\rATCN\r", c1, c2); // Ok I output the new DL as well as the ATCN to exit command mode // Now lets try to read some stuff in cbRead = ReadFromXBee(bTemp, sizeof(bTemp), 10000, 13); // This should be OK<cr> cbRead = ReadFromXBee(bTemp, sizeof(bTemp), 10000, 13); // This shoould be our DL<cr> if ((cbRead > 1) && (bTemp[cbRead-1] == 13)) { // We need to convrt the number from a hex string to a number... wDL = 0; // start off with 0 cbRead--; // subtract off the cr... for (i = 0; i < cbRead; i++) { if ((bTemp[i] >= '0') && (bTemp[i] <= '9')) wDL = (wDL<<4) + (bTemp[i]-'0'); else if ((bTemp[i] >= 'A') && (bTemp[i] <= 'F')) wDL = (wDL<<4) + (bTemp[i]-'A' + 10); else if ((bTemp[i] >= 'a') && (bTemp[i] <= 'f')) wDL = (wDL<<4) + (bTemp[i]-'a' + 10); } } cbRead = ReadFromXBee(bTemp, sizeof(bTemp), 10000, 13); // This should be OK<cr> pin_toggle(L3); #ifdef DEBUG rprintfInit(USB_ACTIVATE); rprintf("GetXBEEHVAL: %c%c=%x\n", c1, c2, wDL);#endif //DEBUG return wDL;}// Simple wrappers to get My and DL...WORD GetXBeeMY(void){ return GetXBeeHVal ('M', 'Y');}WORD GetXBeeDL(void){ return GetXBeeHVal ('D', 'L');}//==============================================================================// [ClearXBeeInputBuffer] - This simple helper function will clear out the input// buffer from the XBEE//==============================================================================void ClearXBeeInputBuffer(void){// pin_toggle(L4); TICK_COUNT start = clockGetus(); // Get the start time TICK_COUNT wait = 1000; // 1ms = 1000us while(clockHasElapsed(start, wait)==FALSE) { if (!uartReceiveBufferIsEmpty(XBEE_UART)) { uartFlushReceiveBuffer(XBEE_UART); start = clockGetus(); // Update the start time } }// pin_toggle(L4); }//==============================================================================// [WaitForXBeeTransmitComplete] - This simple helper function will loop waiting// for the uart to say it is done.//==============================================================================void WaitForXBeeTransmitComplete(void){ while(uartIsBusy(XBEE_UART)) ;}
I never liked the range test in the x-ctu program, i could never get it to work reliably.
You didn't mention that you checked to make sure the baud rates an each radio matched the computer and Axon. Did you check?
I don't know how you initialized your xbee. For example mine normally come from Sparkfun with the default baud rate of 9600.
while(!uartReceiveBufferIsEmpty(UART0)) { int byte = uartGetByte(UART0); rprintf("%c", byte); }
int byte = uartGetByte(UART0);if(byte != -1) { rprintf("%c", byte);}
void ReceiveXBeePacket(PDIYPACKET pdiyp){ BYTE cbRead; BYTE bcsIn; BYTE *pb; int i; XPACKETHEADER XBeePacketHeader; // A packet header to use WORD wNewDL; TICK_COUNT tcCurrentTime; TICK_COUNT tcTimeDiffMS; boolean _fPacketValidPrev = g_diystate.fPacketValid; // Save away the previous state as this is the state if no new data... boolean _fNewPacketAvail = FALSE; g_diystate.fPacketValid = FALSE; g_diystate.fPacketTimeOut = FALSE; g_diystate.fPacketForced = FALSE; pin_toggle(L1); // We will first see if we have a packet header waiting for us. if (!uartReceiveBufferIsEmpty(XBEE_UART)) { // The XBEE has sent us some data so try to get a packet header cbRead = ReadFromXBee((void*)&XBeePacketHeader, sizeof(XPACKETHEADER), 10000, -1);
#include "sys/axon2.h"#include "iopin.h"#include "rprintf.h"#define UART0_TX_BUFFER_SIZE 80#define UART0_RX_BUFFER_SIZE 20void appInitHardware(void) { uartInit(UART1, (BAUD_RATE)115200); uartInit(UART0, (BAUD_RATE)38400); rprintfInit(&uart1SendByte); rprintf("\nAxon II Initiated.\n");}TICK_COUNT appInitSoftware(TICK_COUNT loopStart){ return 0;}// This is the main loopTICK_COUNT appControl(LOOP_COUNT loopCount, TICK_COUNT loopStart) { //while(!uartReceiveBufferIsEmpty(UART0)) { int byte = uartGetByte(UART0); if(byte != -1) { rprintf("%c", byte); } //} return 10;}
//allows for printing with features, but uses more memory#include <stdlib.h>//WebbotLib Includes#define UART2_TX_BUFFER_SIZE 80#define UART2_RX_BUFFER_SIZE 20#include "buffer.h"#include "sys/axon2.h"//declare microcontroller#include "servos.h" //use for servos#include "a2d.h" //use for ADC#include "rprintf.h" //use for UART#include "i2c_master.h" //use for I2C#include "errors.h" //helpful for debugging mistakes#include "string.h"
while(!uartReceiveBufferIsEmpty(UART0)) { int byte = uartGetByte(UART0); if(byte != -1) { rprintf("%c", byte); }
if(!uartReceiveBufferIsEmpty(UART0)) { int byte = uartGetByte(UART0); rprintf("%c", byte); }
Alternatively you can supply transmit and receive buffers by specifying UART_RX_BUFFER_SIZE and/or UART_TX_BUFFER_SIZE at the top of your program file (before you include the system file).