Hardware UART example for MSP430G2553 using mps430-gcc on Linux
This example shows how to use hardware UART through USCI_A on the TI Launchpad with a MSP430G2553 MCU. Receiving is done through interrupts.
Note: If you have an MSP430 MCU which does not support hardware UART (e.g. the MSP430G2231), have a look at this example.
1. Hardware Setup
The wiring for this example is as follows:
| MSP430 | To |
| RXD P1.1 | TXD serial line |
| TXD P1.2 | RXD serial line |
Note: When using the TI Launchpad with a rev. before 1.5 (the once which shipped with the MSP430G2553 should all be >= 1.5 though) , “/dev/ttyACM0″ could be used as serial port at 9600 Bauds, but RX/TX must be crossed on the jumper bridge of the Launchpad.
2. Get the sources
You can download the sources on github:
git clone http://github.com/wendlers/msp430-harduart.git
3. Compilation
This project is written for msp430-gcc on Linux (I used v4.5.3 which is available as package on ubuntu). For flashing the “mspdebug” tool was used (also from the Ubuntu package).
To compile the source just issue a:
make
This builds the firmware in the “bin” subdirectory in various formats.
4. Flashing
To flash the firmware to your Launchpad you could use the “flash-target” make target:
make flash-target
5. Doxygen Docs
If you installed doxygen on your system, you could generate the HTML-based documentation by calling:
make gen-docs
This will create the documentation under “doc/gen/html”.
6. Usage
Connecting your Launchpad should give you a new serial device “/dev/ttyACM0″. Connect to this port at 9600 bauds – e.g. by using screen:
screen /dev/ttyACM0 9600
A greeter is shown on the serial line, and you are prompted to press any key to start the echo demo. After the first keypress, “OK” is printed, and from then on, every character you type is echoed back. Every time, a character is received, the red LED on the launchpad is toggled. The green LED stadily blinks.
Note: to actually see the greeter in your screen session, you either need to start the screen before flashing the target, or just press reset on the Launchpad after you started your screen session.




It’s not working for me, on a launchpad Rev 1.5 with a 2553 (on a hardware UART position so jumpers like =|||) both leds stays on and screen stays completely black
oh and the “captcha” in german can be a bit annoying
Please take my comment before with a pinch of salt, while playing with the leds to see where the problem is i had once the OK with a repeated character, never ever the invite (had to plugout/in the usb port tho…)
Dear moderator, please explain that you have to manually reset the board with reset button once screen is launched (and this is not working 100% of time).
you are too fast for me
I just was about trying it with both a rev. 1.4 board and a 1.5 board. And I will update the post in about the next five minutes. Since you are totally right that the screen thing needs some further clarification.
regards,
stefan
sory mod, i’m talking a bit about my life here, had to address a proble with cdcacm. but i’m still having a small kind of a problem with your code (maybe it’s related to my machine) the banner appears, then i have to enter 2 chars before it repeats the second one, added a second time the
c = uart_getc();
uart_putc(c);
uart_puts((char *)”\n\rOK\n\r”);
code
to make it happen twice and the problems stay the same, do not hesitate to mail me if you have an idea
Strange. Never had that problem with HW-UART (just tried it a few times, worked fine). Interestingly I saw that kind of behavior with SW-URAT …
Hey stefan, forcing flow control on seemed to solve the problem
(screen -f /dev/ttyACM0 9600) with the twiced echo sequence… you Rule ! every problem was on my side
Hi! Stefan Wendler, Your just awesome! Its working for me. Actually i have been trying for this UART communication past from two days. I have gone through so many data sheets, pdfs and i tested so many codes provided in CCS studio. i was scared while reading about UART in datasheet and pdfs related to MSP4302553. But finally you solved my problem in a simple manner. Thanks man! thanks A lot.
Now i have to test the Transmission section….
nice, useful and good site…
Hi,
Thanks for the code you shared!
Could you elaborate a bit on the uart_set_rx_isr_ptr() routine, why is it needed, why it’s called with 0 as a parameter just to be checked in the ISR whether it’s 0? Is it to distinguish the “source” of the interrupt?
One more thing that I cannot decipher is the syntax of line 62 (void uart_set_rx_isr_ptr(void (*isr_ptr)(unsigned char c)) ) and line 87 ((uart_rx_isr_ptr)(UCA0RXBUF);) – what is that??
Thanks again!
regarding “void uart_set_rx_isr_ptr(void (*isr_ptr)(unsigned char c))”:
This operation is used to register a callback function. The signature for that function is defined like so:
unsigned char c.
Thus, you are allowed to register any function which takes one byte as input. Later on, this registered function is called by dereferencing it, and that is exactely the:
(uart_rx_isr_ptr)(UCA0RXBUF);
Meaning: call the registered handler function and pass the currently received byte which is the UCA0RXBUF register of the MCU.
In case you don’t registered a callback (because you may not need it), the inital value of the pointer is set to 0L. An this is what is chacked in the ISR: if it points to 0L, no callback is set, thus, don’t try to call it.
I’m using rev 1.4 board with MSP430G2553. I’ve connected P1.1 TXD to P1.2 RXD.
I copied uart.c, uart.h, main.c to a new project file in Code Composer Studio.
When I run the program, it continuously repeats the first two characters, i.e. if comment out the first uart_puts line, all it does is print MSMSMSMSMS…
Both red and green LED remains lit, they do not flash. After pressing the reset button about 50 times, on one occasion the red LED was off and the green was blinking, but when I press reset it goes back to continuously printing the first two characters.
I’m not sure what’s causing it to be ‘stuck’ on the first two chars.
Hi Robo,
I never used CCS, but I know there are some differences regarding definition of that interrupt handler functions … it looks like if “interrupt(USCIAB0RX_VECTOR) USCI0RX_ISR(void)” gets never called (since it was not realized as ISR). If a character is received, and interrupting is enabled, the interrupt will be triggered until the received char is read by accessing “UCA0RXBUF”. Thus, I think the problem is, that CCS uses a different way to “mark” an ISR. Sorry I can not provide more details.
Thanks for the response. I found the problem.
Despite your clear instructions, I didn’t understand what you meant by crossing the jumpers although it’s obvious now. The fuzzy image threw me off a bit, it might help if you highlight the jumpers like you have with the Rev 1.5 image.
I haven’t got it fully working because currently I can only make one cross by holding a staple with my fingers, but with the one cross I was able to make it transmit text to the console, so I’m pretty sure that was the problem.
Thanks for your response. I will try to fix that image
.
Thanks for the code, I tried on my board which is a 1.5 revision. I am using ubuntu 12.10 and I had the same problem as mentioned by JG when using screen. -f didn’t help
I switched from screen to minicom and it seems to work
minicom -b 9600 -D /dev/ttyACM0
Whenever I press reset on the board, I get the greetings screen.
After the greeting if I press a key that gets printed twice i.e if I press a – on the screen it shows aa