1 //! MSP430F2618 clock and I/O definitions
3 // Included by other 2xx ports, such as the 2274.
10 #include <sys/crtld.h>
14 unsigned char serial0_rx(){
17 while(!(IFG2&UCA0RXIFG));//wait for a byte
21 //UCA0CTL1 &= ~UCA0RXSE;
26 unsigned char serial1_rx(){
30 while (!(UC1IFG&UCA1RXIFG)); // USCI_A1 TX buffer ready?
39 void serial0_tx(unsigned char x){
40 while ((IFG2 & UCA0TXIFG) == 0); //loop until buffer is free
41 UCA0TXBUF = x; /* send the character */
42 while(!(IFG2 & UCA0TXIFG));
44 //! Transmit a byte on the second UART.
45 void serial1_tx(unsigned char x){
47 while ((UC1IFG & UCA1TXIFG) == 0); //loop until buffer is free
48 UCA1TXBUF = x; /* send the character */
49 while(!(UC1IFG & UCA1TXIFG));
54 //! Set the baud rate.
55 void setbaud0(unsigned char rate){
57 //Table 15-4, page 481 of 2xx Family Guide
83 //! Set the baud rate of the second uart.
84 void setbaud1(unsigned char rate){
86 //Table 15-4, page 481 of 2xx Family Guide
116 void msp430_init_uart(){
118 // Serial0 on P3.4, P3.5
119 P3SEL |= BIT4 + BIT5;
122 //UCA0CTL1 |= UCSWRST; /* disable UART */
125 //UCA0CTL0 |= UCMSB ;
127 UCA0CTL1 |= UCSSEL_2; // SMCLK
129 //UCA0BR0 = BAUD0EN; // 115200
131 setbaud(5);//default baud, 115200
133 UCA0MCTL = 0; // Modulation UCBRSx = 5
134 UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
137 //Leave this commented!
138 //Interrupt is handled by target code, not by bootloader.
139 //IE2 |= UCA0RXIE; //DO NOT UNCOMMENT
143 // Serial 1 on P3.6, 3.7
146 UCA1CTL1 |= UCSSEL_2; // SMCLK
147 setbaud1(5); //115200
149 UCA1CTL1 &= ~UCSWRST; // Initialize USCI state machine
154 //This must be in .noinit.
155 __attribute__ ((section (".noinit"))) char dcochoice;
157 //! Initialization is correct.
158 void msp430_init_dco_done(){
159 //char *dcochoice=(char *) DCOCHOICEAT; //First word of RAM.
163 //! Initialize the MSP430 clock.
164 void msp430_init_dco() {
166 //char *dcochoice=(char *) DCOCHOICEAT; //First word of RAM.
168 #ifdef __MSP430_HAS_PORT8__
169 P8SEL = 0; // disable XT2 on P8.7/8
172 //Set P2.6 mode for MSP430F2274
173 #ifndef __MSP430_HAS_PORT5__
174 P2SEL = 0; //disable XIN on 2274
179 BCSCTL1 = (STATICDCO>>8);
180 DCOCTL = (STATICDCO&0xFF);
182 if(CALBC1_16MHZ!=0xFF){
183 //Info is intact, use it.
184 BCSCTL1 = CALBC1_16MHZ;
185 DCOCTL = CALDCO_16MHZ;
188 Info is missing, guess at a good value.
190 A list of correct calibrations in included as dco_calib.c,
193 DCOCTL = 0x00; //clear DCO
195 BCSCTL1 = dco_calibrations[2*dcochoice+1];
196 DCOCTL = dco_calibrations[2*dcochoice];
198 dcochoice%=dco_calibrations_count;