Question on uart lib

Hi,

I have several configuration strings I need to send with the UART. I was wondering if someone can tell me the best way to use uart1TxSend to send a string.
It doesn’t like uart0TxSend (“test_string”, size).

Thanks a lot,
Colin

Hello, Colin.

This should work:

uint8 XDATA buffer[] = "stuff";
if (uart1TxAvailable() >= sizeof(buffer)-1)
{
  uart1TxSend(buffer, sizeof(buffer)-1);
}

The documentation is here:
pololu.github.com/wixel-sdk/uart0_8h.html

If you’re going to be doing this kind of thing in a lot of places in your code, you might prefer to define a putchar() function that prints to the UART, and then use printf instead. There are example apps in the Wixel SDK that do that.

–David

Thank you David. I think printf is the way to go, especially since many strings need to be constructed out of integers. So my putchar() might look like this?

void putchar(char c)
{
	while ( !uart1TxAvailable() );
	uart1TxSendByte(c);
}

But how big is that Tx buffer? If it’s big enough for the whole string, I might be better off to just not call printf untill there’s room for it all.

Thanks again,
Colin

Yes, the putchar you wrote will work, but beware that your function could block for a long time, which might interfere with the requirements of other libraries you are using (e.g. you might want to call usbComService() in the loop).

The buffer is 256 bytes, so yes, you can move the call to uart1TxAvailable() to be before the calls to printf.

–David

Beautiful! Thanks David.

Colin