USB communication

Hey i have made a simple test program for USB communication. But I am experiencing some weird behavior that that I just cannot understand and was hoping someone here would know.
If I send 18 or more characters it works fine but if I send less I can’t see anything on the screen (the green LED is still blinking).
I am using a Terminal program to see the data. I have tried both Tera Term and Br@y Terminal.

this work

#include <wixel.h>
#include <usb.h>
#include <usb_com.h>
#include <stdio.h>

uint8 XDATA response[32];

void send() {
	uint8 responseLength;
	responseLength = sprintf(response, "abcdefghijklmn\r\n");
	usbComTxSend(response, responseLength);
	delayMs(40);
}

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

	while (1) {
		boardService();
		usbComService();
		usbShowStatusWithGreenLed();
		send();
	}
}

this doesn’t

#include <wixel.h>
#include <usb.h>
#include <usb_com.h>
#include <stdio.h>

uint8 XDATA response[32];

void send() {
	uint8 responseLength;
	responseLength = sprintf(response, "abcdefghijklm\r\n");
	usbComTxSend(response, responseLength);
	delayMs(40);
}

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

	while (1) {
		boardService();
		usbComService();
		usbShowStatusWithGreenLed();
		send();
	}
}

Hello.

You need to call usbComTxAvailable to make sure there is space available in the USB buffers before sending data to the computer. More information about this is available in the documentation of usbComTxSend. Also, your program will probably perform better if you do not call delayMs, because that blocks all the other tasks you have in the main loop from running. You can use getMs() to help schedule sending regular reports to the computer. There is an example of this in the test_adc app in the Wixel SDK, but parts of that example are more complicated than you need it to be: since your reports are less than 128 characters you should be able to send them with one call to usbComTxSend. You can also look at the example_blink_led app for an example of how to schedule a periodic task.

–David