Skip to content

Instantly share code, notes, and snippets.

@rclabs
Last active December 12, 2015 09:29
Show Gist options
  • Save rclabs/4752294 to your computer and use it in GitHub Desktop.
Save rclabs/4752294 to your computer and use it in GitHub Desktop.
uart test code
#include <msp430.h>
#include <legacymsp430.h>
// https://github.com/wendlers/msp430-harduart/blob/master/src/uart.c
// https://github.com/ideasium/msp430-uart/blob/master/msp430-uart/uart.c
// http://www.geom.uiuc.edu/~huberty/math5337/groupe/digits.html
char *pi = "3.141592653589793238462643383279502884197169399375105820974944592307816406286";
int pos = 0;
void transmit_char() {
UCA0TXBUF = pi[pos];
pos++;
if (pi[pos] == '\0') pos = 0;
}
interrupt(USCIAB0TX_VECTOR) uart_transmit_isr() {
P1OUT ^= BIT6 | BIT0;
transmit_char();
}
int main() {
WDTCTL = WDTPW + WDTHOLD;
// configure clocks
DCOCTL = CALDCO_16MHZ;
BCSCTL1 = CALBC1_16MHZ;
// i/o
P1DIR = BIT6 | BIT0;
P1OUT = 0x00;
P1SEL |= BIT1 | BIT2;
P1SEL2 |= BIT1 | BIT2;
// initialise usci
UCA0CTL1 |= UCSSEL_2; // hold reset, set smclk
UCA0BR0 = 0x82;
UCA0BR1 = 0x06;
UCA0MCTL = UCBRS2 | UCBRS1;
UCA0CTL1 &= ~(UCSWRST);
IE2 |= UCA0TXIE;
__enable_interrupt();
transmit_char();
for (;;) {}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment