leomar01 8 Posted October 14, 2011 Share Posted October 14, 2011 After many hours of struggling with datasheets, reading code samples, getting grace to work, asking a lot in this forum and getting much help, I finally got the SW UART on Port2.0 working (TX only - for now). /*####################################### This is one more way of a software uart, but on port2.0 for the 20pdip MSP430s. I have used many parts from here and there, but most of this code is generated in grace and afterwards slightly modified to achieve the goal of a software uart on port2.0 My MSP430G2553 runs on 16MHz, if you want to use an other clockspeed, you have to adjust the bittime for suggestions and complaints, please feel free to contact me on 43oh.com leomar01 */ #include void putstr(char *str); // transmit string void transmit(unsigned char ch); // transmit a character void setup(void); // function for setting up the device #define BITIME (13 * 16) // prescaler: 8 -> 2 MHz /(13*8*2) = 9600 bits/sec unsigned char bitCnt; // number of bits to transmit unsigned int txByte; // transmit buffer with start/stop bits void setup(void) { BCSCTL1 = CALBC1_16MHZ; DCOCTL = CALDCO_16MHZ; /* Port 2 Output Register */ P2OUT = 0; /* Port 2 Port Select Register (see page 50 in datasheet -> port2.0 will be Timer1_A3.TA0) */ P2SEL = BIT0; /* Port 2 Direction Register */ P2DIR = BIT0; /* Port 2 Interrupt Edge Select Register */ P2IES = 0; /* Port 2 Interrupt Flag Register */ P2IFG = 0; /* Configure Timer1 (See Users Guide page 374) */ TA1CCTL0 = CM_0 + CCIS_0 + OUTMOD_0 + CCIE + OUT; TA1CCR0 = 1200; /* users guide page 372 -> clock source: SMCLK, input divider: 8, mode control: continuous up to 0xFFFF */ TA1CTL = TASSEL_2 + ID_3 + MC_2; __bis_SR_register(GIE); // enable GIE in status register } void putstr(char *str) { char *cp; for (cp = str; *cp != '\0'; cp++) { transmit(cp[0]); } } void transmit(unsigned char ch) { bitCnt = 0xA; // Load Bit counter, 8data + ST/SP txByte = (unsigned int)ch | 0x100; // Add mark stop bit to txByte txByte = txByte << 1; // Add space start bit TA1CCR0 = TA1R + BITIME; // Some time till first bit TA1CCTL0 = OUTMOD0 + CCIE; // TXD = mark = idle while (TA1CCTL0 & CCIE); // Wait for ISR to complete TX } void main(){ WDTCTL = WDTPW|WDTHOLD; // Stop watchdog timer // Kalibrierdaten f bluehash and SirZusa 2 Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.