I cant comunicate the wixels

Please I need help. I’m already trying to several days and I’m not getting success with wixels. I do not understand what is wrong. I’m trying to do the basics. The Wixel connected to the computer apparently is doing the right thing, but the other Wixel does not respond, and apparently did not receive the packets. Below the code I’m using. Its just a test. I need process the packet, not send back, but until now, I cant transmit any packet.

/*
 * aaClient.c
 */
#include <wixel.h>
#include <string.h>
#include <usb.h>
#include <usb_com.h>
#include <radio_queue.h>

#define false 0
#define true !false

uint8 XDATA radioBuf[22];
BIT sendBuf = false;

uint32 redOn = 0;
uint32 yellowOn = 0;

void updateLeds()
{
    usbShowStatusWithGreenLed();
	LED_RED(redOn);
    if(redOn) redOn--;
	LED_YELLOW(yellowOn);
    if(yellowOn) yellowOn--;
}

void radioRxService()
{
	uint8 XDATA * pack;

	pack = radioQueueRxCurrentPacket();
	if (pack)
	{
        memcpy(radioBuf, pack, pack[0]+1);
	    radioQueueRxDoneWithPacket();
	    sendBuf = true;
	    yellowOn = 0x1000;
	}
}

void radioTxService()
{
    uint8 XDATA * pack;

    if(!sendBuf)return;

	pack = radioQueueTxCurrentPacket();
    if (pack)
    {
        memcpy(radioBuf, pack, radioBuf[0]+1);
        radioQueueTxSendPacket();
        sendBuf = false;
	    redOn = 0x1000;
    	radioMacStrobe();
    }
}

void main()
{
    systemInit();
    usbInit();
    radioQueueInit();

    while(1)
    {
        updateLeds();
        boardService();
        usbComService();

        radioRxService();
        radioTxService();

        //imHere();
    }
}

#define TIME_TO_SEND 5000

void imHere()
{   static uint32 lastSend = getMs();
    uint8 XDATA * pack;

	if(((getMs()-lastSend)>TIME_TO_SEND)&&radioQueueTxAvailable())
	{
		pack = radioQueueTxCurrentPacket();
	    if (pack)
	    {
	        pack[0] = 0x04;
	        pack[1] = serialNumber[3];
	        pack[2] = serialNumber[2];
	        pack[3] = serialNumber[1];
	        pack[4] = serialNumber[0];
	        radioQueueTxSendPacket();
	        lastSend = getMs();
	    	radioMacStrobe();
	    }
	}
}

After post this code I see a bug in radioTxService function.

the line:
memcpy(radioBuf, pack, radioBuf[0]+1);

must be:
memcpy(pack, radioBuf, radioBuf[0]+1);

but its not the problem, this line is never executed. The leds dont blink.

Hello.

Have you been able to get wireless communication working with any of the precompiled example apps that we provide in the Wixel User’s Guide? Have you been able to compile one of those apps from source using the Wixel SDK and get it to work?

One thing I see: You should not be calling any radioMac functions in your program: the radioQueue library will handle that for you.

Why do you expect sendBuf to ever be 1? I see you commented out the call to imHere().

–David

Hi David,

I run test_radio_signal (tx and rx) and works, although the values ​​are not so good:

95, -70, 95
92, -70, 91
94, -71, 94
91, -69, 90
90, -69, 97
76, -34, 89
82, -32, 89
81, -31, 87
78, -27, 87
79, -27, 92
82, -27, 89
76, -27, 89
82, -27, 95
80, -27, 94
84, -27, 95
92, -41, 94

With radio_queue I cant transmit nothing, but I rewrite the test program to use
radio_com. It worked in part, but the program showed a behavior I did not expect. The remote Wixel creates and sends packets like “Im here” but transmission only really happens in the fourth package, and then the 4 packets are sent at once, but with the last incomplete, missing two bytes. These two bytes are sent at the next transmission with another set of 4 packages.

Apparently, the radio_com mechanism wait fill the buffer before transmission. Is there a way to force the immediate transmission without the wait?

Bellow the new code:

/*
 * aaClient.c
 *
 *  Created on: 14/10/2012
 *      Author: Usuario
 */
#include <wixel.h>
#include <string.h>
#include <usb.h>
#include <usb_com.h>
#include <radio_com.h>

#define false 0
#define true !false

#define computerID 0xFF
#define msgImHere  0xFF
uint8 myID = serialNumber[3];
uint8 packID = 1;

uint8 XDATA radioBuf[22];
BIT sendBuf = false;

uint16 redOn = 0;
uint16 yellowOn = 0;

void updateLeds()
{
    usbShowStatusWithGreenLed();
	LED_RED(redOn);
    if(redOn) redOn--;
	LED_YELLOW(yellowOn);
    if(yellowOn) yellowOn--;
}

void radioRxService()
{
	uint8 bytesLeft = radioComRxAvailable();
	uint8 XDATA * pbuf;

	if(!bytesLeft) return;

	radioBuf[0] = radioComRxReceiveByte();
	bytesLeft--;
	if(radioBuf[0]< bytesLeft)
		bytesLeft = radioBuf[0];
	pbuf = (radioBuf+1);
    while(bytesLeft--)
    {
        *pbuf = radioComRxReceiveByte();
        pbuf++;
    }
    yellowOn= 0x1000;
    sendBuf = true;
}

void radioTxService()
{
	uint8 bytesLeft;
    uint8 XDATA * pbuf;

    if(!sendBuf)return;
    if(!radioComTxAvailable())return;

    bytesLeft = radioBuf[0]+1;
    pbuf = radioBuf;

    while(bytesLeft--)
    {
        radioComTxSendByte(*pbuf);
        pbuf++;
    }
    sendBuf = false;
    redOn = 0x1000;
}


#define TIME_TO_SEND 5000

void imHere()
{   static uint32 lastSend = getMs();

	if(((getMs()-lastSend)>TIME_TO_SEND)&& !sendBuf)
	{
    	radioBuf[0] = 0x04;
    	radioBuf[1] = myID;        // sender
    	radioBuf[2] = computerID;  // recipient
    	radioBuf[3] = packID;      // packet ID
    	radioBuf[4] = msgImHere;   // message
    	packID++;
        lastSend = getMs();
        sendBuf = true;
	}
}


void main()
{
    systemInit();
    usbInit();
    radioComInit();

    while(1)
    {
        updateLeds();
        boardService();
        usbComService();

        radioRxService();
        radioTxService();

        imHere();
    }
}

I haven’t looked at your code carefully, but I see that you are forgetting to call radioComTxService() in your main loop, and that could definitely be causing your problems.

–David

Thanks a lot David, program works fine now.