1 //! MSP430F2618 clock and I/O definitions
3 // Included by other 2xx ports, such as the 2274.
13 unsigned char serial_rx(){
16 while(!(IFG2&UCA0RXIFG));//wait for a byte
20 //UCA0CTL1 &= ~UCA0RXSE;
25 unsigned char serial1_rx(){
31 void serial_tx(unsigned char x){
32 while ((IFG2 & UCA0TXIFG) == 0); //loop until buffer is free
33 UCA0TXBUF = x; /* send the character */
34 while(!(IFG2 & UCA0TXIFG));
37 void serial_tx_old(unsigned char x){
38 while ((IFG2 & UCA0TXIFG) == 0); //loop until buffer is free
39 UCA0TXBUF = x; /* send the character */
40 while(!(IFG2 & UCA0TXIFG));
43 //! Transmit a byte on the second UART.
44 void serial1_tx(unsigned char x){
48 //! Set the baud rate.
49 void setbaud(unsigned char rate){
51 //Table 15-4, page 481 of 2xx Family Guide
77 //! Set the baud rate of the second uart.
78 void setbaud1(unsigned char rate){
80 //http://mspgcc.sourceforge.net/baudrate.html
103 void msp430_init_uart(){
105 // Serial on P3.4, P3.5
106 P3SEL |= BIT4 + BIT5;
109 //UCA0CTL1 |= UCSWRST; /* disable UART */
112 //UCA0CTL0 |= UCMSB ;
113 UCA0CTL1 |= UCSSEL_2; // SMCLK
115 //UCA0BR0 = BAUD0EN; // 115200
117 setbaud(5);//default baud, 115200
119 UCA0MCTL = 0; // Modulation UCBRSx = 5
120 UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
123 //Leave this commented!
124 //Interrupt is handled by target code, not by bootloader.
129 //! Initialize the MSP430 clock.
130 void msp430_init_dco() {
131 //LED lights when init_dco begins,
132 //then dims when successful.
135 if(CALBC1_16MHZ!=0xFF && CALDCO_16MHZ!=0xFF){
136 //Info is intact, use it.
137 BCSCTL1 = CALBC1_16MHZ;
138 DCOCTL = CALDCO_16MHZ;
140 //Info is missing, guess at a good value.
141 switch(*((int*)0xff0)){
143 case 0x6ff2: //f26f, the MSP430F2618
144 BCSCTL1 = 0x8f; //CALBC1_16MHZ at 0x10f9
145 DCOCTL = 0x7f; //CALDCO_16MHZ at 0x10f8
150 //Hopefully by here the clock is meaningful.