Outputting a String to the UART

Go To Last Post
11 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi.

Bit of a daft question but does anyone know how to output a string to the UART using CodevisionAVR?

Their documentation isnt really helpful and they have almost no example code on the light version of the software.

Does anyone know how to do this?

Cheers.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Send one character after the other?

Klaus
********************************
Look at: www.megausb.de (German)
********************************

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

There are ansi c library functions for sending strings to the 'standard output', which hopefully is the uart. Look up 'printf' and 'puts' in the c book

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

my simple way of doing it in winavr:

//transmit a null-terminated string, max length = 255
void transmit_string(char * string) {
	uint8_t i = 0;
	do {
		uart_transmit(string[i++]);
	} while (string[i] != 0x00);
	uart_transmit(0x00);
}

where uart_transmit just sends a byte over the (already set up) uart.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Why send the null, Bob? Doesn't it put out a happy face or a club or spade?

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

bobgardner wrote:
Why send the null, Bob? Doesn't it put out a happy face or a club or spade?

If the app on the recieving end is a terminal, Yes (or maybe).

If the recieving app is a "C" program reading unsigned chars it might want to see the null character to determine the end of the string. Otherwise another scheme would have to be in place, eg fixed length of string(s) agreed upon by sender and reciever, or sending a length byte before the string.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Do it the same way its been done since the teletype days. Tack a carriage return and/or a line feed onto the end of it. I've been going to a lot of trouble to NOT send the null to my lcd displays and stuff. They have katakana chars down in the control chars and wierd stuff like that.

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It's just that I can't see where OP sas the recieving end is a display, Bob, and that was my point: It all depends on what will be recieving the string.

Suppose the reciever is a "C" program running on a PC, and that it will do further processing of a string, and for this want's it as a null terminated string. Why go through the trouble with replacing the null with a CR before sending from the AVR and then replace the CR with a null after recieving the string on the PC.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think Kernigan invented the null terminator to keep strings in ram. They didnt have any problem terminating them on the tty line. Intel assembler used $ as a terminator, moto used something else 0x04 I think. I'd seen 0x80 used (wasn't really an ascii char), but it was easy to check for... it was 'branch if minus'

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yup, this was written for interfacing with a c++ program. If this was for a terminal receiver, it's better to omit transmitting the null character and send a CR-LF instead:

uart_transmit(0x0D);
uart_transmit(0x0A);
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So the transmitter sends P123.45,R234.56,Y345.67CR (24 chars), the receiving program sees the cr, and writes the string to the file. No nulls anywhere.

Imagecraft compiler user