Why this simple program not working?

I am feeling my way around programming a Wixel board. The program below is based on example_usb_com.c. It should send string “AB” every 2 seconds to the com port. It doesn’t work and the Wixel board becomes invisible to the computer as soon as I upload the program. Any help is appreciated.

/** To send "AB" every 2 seconds to the com port. */
#include <wixel.h>
#include <usb.h>
#include <usb_com.h>
#include <stdio.h>

uint8 XDATA response[32];

void main()
{
    uint32 time;
    uint8 bytesLeft;
    systemInit();
    usbInit();
    while(1)
    {
        boardService();
        usbShowStatusWithGreenLed();
        usbComService();

        bytesLeft = usbComRxAvailable();

        response[0] = 'A';
        response[1] = 'B';

        if (usbComTxAvailable()) {
			usbComTxSend(response,2);
		}

        time = getMs();
        while ((getMs() - time) < 2000);
    }
}

Hello. The main thing that is causing problems is that you are not calling usbComService often enough. You are not calling it at all during the 2000 ms wait. Another problem is that you are sending two bytes to the COM port with usbComTxSend, but you didn’t actually check the return value of usbComTxAvailable to make sure that it was at least 2; this could cause unpredictable behavior.

I recommend that you take a look at some of the example apps that regularly send data to the computer, like test_adc.

–David