1 //! MSP430F2618 clock and I/O definitions
3 // Ought to be portable to other 2xx chips.
4 // 2274 looks particularly appealing.
14 unsigned char serial_rx(){
17 while(!(IFG2&UCA0RXIFG));//wait for a byte
21 //UCA0CTL1 &= ~UCA0RXSE;
26 unsigned char serial1_rx(){
32 void serial_tx(unsigned char x){
33 while ((IFG2 & UCA0TXIFG) == 0); //loop until buffer is free
34 UCA0TXBUF = x; /* send the character */
35 while(!(IFG2 & UCA0TXIFG));
38 void serial_tx_old(unsigned char x){
39 while ((IFG2 & UCA0TXIFG) == 0); //loop until buffer is free
40 UCA0TXBUF = x; /* send the character */
41 while(!(IFG2 & UCA0TXIFG));
44 //! Transmit a byte on the second UART.
45 void serial1_tx(unsigned char x){
49 //! Set the baud rate.
50 void setbaud(unsigned char rate){
52 //Table 15-4, page 481 of 2xx Family Guide
78 //! Set the baud rate of the second uart.
79 void setbaud1(unsigned char rate){
81 //http://mspgcc.sourceforge.net/baudrate.html
104 void msp430_init_uart(){
106 // Serial on P3.4, P3.5
107 P3SEL |= BIT4 + BIT5;
110 //UCA0CTL1 |= UCSWRST; /* disable UART */
113 //UCA0CTL0 |= UCMSB ;
114 UCA0CTL1 |= UCSSEL_2; // SMCLK
116 //UCA0BR0 = BAUD0EN; // 115200
118 setbaud(5);//default baud, 115200
120 UCA0MCTL = 0; // Modulation UCBRSx = 5
121 UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
124 //Leave this commented!
125 //Interrupt is handled by target code, not by bootloader.
130 //! Initialize the MSP430 clock.
131 void msp430_init_dco() {
132 //LED lights when init_dco begins,
133 //then dims when successful.
136 if(CALBC1_16MHZ!=0xFF && CALDCO_16MHZ!=0xFF){
137 //Info is intact, use it.
138 BCSCTL1 = CALBC1_16MHZ;
139 DCOCTL = CALDCO_16MHZ;
141 //Info is missing, guess at a good value.
142 switch(*((int*)0xff0)){
144 case 0x6ff2: //f26f, the MSP430F2618
145 BCSCTL1 = 0x8f; //CALBC1_16MHZ at 0x10f9
146 DCOCTL = 0x7f; //CALDCO_16MHZ at 0x10f8
151 //Hopefully by here the clock is meaningful.