1 //! MSP430F2618 clock and I/O definitions
3 // Included by other 2xx ports, such as the 2274.
10 #include "dco_calib.h"
15 unsigned char serial0_rx(){
18 while(!(IFG2&UCA0RXIFG));//wait for a byte
22 //UCA0CTL1 &= ~UCA0RXSE;
27 unsigned char serial1_rx(){
31 while (!(UC1IFG&UCA1RXIFG)); // USCI_A1 TX buffer ready?
40 void serial0_tx(unsigned char x){
41 while ((IFG2 & UCA0TXIFG) == 0); //loop until buffer is free
42 UCA0TXBUF = x; /* send the character */
43 while(!(IFG2 & UCA0TXIFG));
45 //! Transmit a byte on the second UART.
46 void serial1_tx(unsigned char x){
48 while ((UC1IFG & UCA1TXIFG) == 0); //loop until buffer is free
49 UCA1TXBUF = x; /* send the character */
50 while(!(UC1IFG & UCA1TXIFG));
55 //! Set the baud rate.
56 void setbaud0(unsigned char rate){
58 //Table 15-4, page 481 of 2xx Family Guide
84 //! Set the baud rate of the second uart.
85 void setbaud1(unsigned char rate){
87 //Table 15-4, page 481 of 2xx Family Guide
117 void msp430_init_uart(){
119 // Serial0 on P3.4, P3.5
120 P3SEL |= BIT4 + BIT5;
123 //UCA0CTL1 |= UCSWRST; /* disable UART */
126 //UCA0CTL0 |= UCMSB ;
128 UCA0CTL1 |= UCSSEL_2; // SMCLK
130 //UCA0BR0 = BAUD0EN; // 115200
132 setbaud(5);//default baud, 115200
134 UCA0MCTL = 0; // Modulation UCBRSx = 5
135 UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
138 //Leave this commented!
139 //Interrupt is handled by target code, not by bootloader.
140 //IE2 |= UCA0RXIE; //DO NOT UNCOMMENT
144 // Serial 1 on P3.6, 3.7
147 UCA1CTL1 |= UCSSEL_2; // SMCLK
148 setbaud1(5); //115200
150 UCA1CTL1 &= ~UCSWRST; // Initialize USCI state machine
155 //This must be in .noinit.
156 __attribute__ ((section (".noinit"))) char dcochoice;
158 //! Initialization is correct.
159 void msp430_init_dco_done(){
160 //char *dcochoice=(char *) DCOCHOICEAT; //First word of RAM.
164 //! Initialize the MSP430 clock.
165 void msp430_init_dco() {
167 //char *dcochoice=(char *) DCOCHOICEAT; //First word of RAM.
169 #ifdef __MSP430_HAS_PORT8__
170 P8SEL = 0; // disable XT2 on P8.7/8
173 //Set P2.6 mode for MSP430F2274
174 #ifndef __MSP430_HAS_PORT5__
175 P2SEL = 0; //disable XIN on 2274
180 BCSCTL1 = (STATICDCO>>8);
181 DCOCTL = (STATICDCO&0xFF);
183 if(CALBC1_16MHZ!=0xFF){
184 //Info is intact, use it.
185 BCSCTL1 = CALBC1_16MHZ;
186 DCOCTL = CALDCO_16MHZ;
189 Info is missing, guess at a good value.
191 A list of correct calibrations in included as dco_calib.c,
194 DCOCTL = 0x00; //clear DCO
196 BCSCTL1 = dco_calibrations[2*dcochoice+1];
197 DCOCTL = dco_calibrations[2*dcochoice];
199 dcochoice%=dco_calibrations_count;