USART Usage

Hello folks,

I’m new in this microcontroller. I come from programming in PIC assembly and I’m not used yet to the power of hi level like C programming.

My doubt is regarding the USART. I want to write extensive USART aplications like GPS NMEA pharsing, command interpreter, etc…

I have the void UART_transmit (unsigned char transmit_data); function that transmits one char, but I need more power, something like redirect the stdout or something.

Is there any strings handling example that could help me? I need to see some written code in IAR C to get started.

Thank you in advance.

Dixon

Your problem isn’t really with the MSP430 but with programming microcontrollers in C.

You should look for examples of string handling without regard to which microcontroller is targetted – it’s basically the same for all of them and that’s the point of using C.

If you want specific examples of how to setup and use the peripherals of the MSP430, then look in the examples directory of IAR. They have lots and lots of them that will compile and run as-is. All the other tool vendors I’ve looked at supply similar examples.

Hi MGP,

You are right. My doubt is more related with programming microcontrollers in C rather than especifically the MSP430. At the end I will always have a routine called “send_char_to_usart1(const *char)” indepently of the initialization and implementation of this usart.

I know how to handle this serial port comunications more or less in C. C is not the problem either.

The issue is that I used to program in assembly for PIC by one side and in hi level languages for PC, so I would like to see code examples in C for microcontrollers because I want to see coding “stiles” of other people. You always learn a lot viewing how other people do the same in other way.

There are 2 techniques to do this:

  1. Looping through the data that you want to send and calling the “send” function, then wait for it to transmit before sending the next character in the string.

  2. Set aside a large chunk of RAM and keep a beginning and end pointer (or index number) for what is a circular buffer. On a transmit-complete interrupt or the a register check in the main looop of the program, stuff the next character in the transmit buffer until the beginning and end pointers point to the same location (emptied buffer).

The first way is very easy to implement, but while you are transmitting you cannot do anything else. The second way allows you to do many things while each character transmitts, but can be very tricky to implement and prone to possible buffer overflows.

(nope, I’ve never used an MSP chip, but the techiniques are similar across the board… I use it on PICs which I believe have fewer resources, and it works well.)

Thank you Kuroy,

That is what i mean, I’m now more interested in learning technique like this you told me rather than the MSP430 specific implementation.

Such how to re-direct a printf (stdout) to RS232 in order to avoid the need of coding formating functions, and so.

In other words see how people deals with this things more usually.

By the way, when I include stdio.h in order to use printf, the compiler says “more than 1000 words-> insert coin”