So to talk to your embedded system yo need an uart connection. This is the most simple and hence robust connection. Here the most simple configuration I could implement. So mainly with almost default settings. Here we start with short register reminder. I hate them :D.
| Register | Function |
|---|---|
| WDTCTL | Watch dog timer control |
| P5SEL | Configure Port 5 pins to for uart tx/rx otherwise GPIO |
| UCA1CTL1 | Control serial com. e.g. clock selection |
| UCA1BR0/1 | Set Baud rate |
| UCA1MCTL | Set modulation |
| UCA1IE | Interrupt enable register |
| UCA1IFG | Interrupt flag register. to detect whether transmit or receive is pending |
| UCTXIFG | Transmit interrupt flag. UCTXIFG is set when UCxxTXBUF empty. 0b = No interrupt pending 1b = Interrupt pending |
And here our small program:
#include <msp430.h>
static void uart_putc(char c)
{
while(!(UCA1IFG & UCTXIFG))
;
UCA1TXBUF =c;
}
static void uart_puts(const char* s)
{
while(*s)
uart_putc(*s++);
}
int main(void)
{
WDTCTL = WDTPW | WDTHOLD;
//init uart
P5SEL |= BIT6;
P5SEL |= BIT7;
UCA1CTL1 |= UCSWRST; // Put state machine in reset
UCA1CTL1 |= UCSSEL_2; // Clock = SMCLK
UCA1BR0 = 104; // 1MHz/9600 baud (approx)
UCA1BR1 = 0;
UCA1MCTL |= UCBRS0;// + UCBRF_0; // Modulation
UCA1CTL1 &= ~UCSWRST; // Initialize USCI state machine
UCA1IE |= UCRXIE; // Enable RX interrupt
for(;;)
{
uart_puts("hellooo\r\n");
}
}
Build, ship it to chip and start your picocom:
-$ msp430-elf-gcc -g -mmcu=msp430f5438a -o soft_uart soft_uart.c
-$ mspdebug tilib ‘prog soft_uart’
-$ sudo picocom -b 9600 /dev/ttyACM2
That is it.
Subscribe to get last updates.