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(){
29 while (!(UC1IFG&UCA1RXIFG)); // USCI_A1 TX buffer ready?
37 void serial0_tx(unsigned char x){
38 while ((IFG2 & UCA0TXIFG) == 0); //loop until buffer is free
39 UCA0TXBUF = x; /* send the character */
40 while(!(IFG2 & UCA0TXIFG));
42 //! Transmit a byte on the second UART.
43 void serial1_tx(unsigned char x){
44 while ((UC1IFG & UCA1TXIFG) == 0); //loop until buffer is free
45 UCA1TXBUF = x; /* send the character */
46 while(!(UC1IFG & UCA1TXIFG));
50 void serial_tx_old(unsigned char x){
51 while ((IFG2 & UCA0TXIFG) == 0); //loop until buffer is free
52 UCA0TXBUF = x; /* send the character */
53 while(!(IFG2 & UCA0TXIFG));
57 //! Set the baud rate.
58 void setbaud0(unsigned char rate){
60 //Table 15-4, page 481 of 2xx Family Guide
86 //! Set the baud rate of the second uart.
87 void setbaud1(unsigned char rate){
88 //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
142 // Serial 1 on P3.6, 3.7
145 UCA1CTL1 |= UCSSEL_2; // SMCLK
146 setbaud1(5); //115200
148 UCA1CTL1 &= ~UCSWRST; // Initialize USCI state machine
153 //This must be in .noinit.
154 __attribute__ ((section (".noinit"))) char dcochoice;
156 //! Initialization is correct.
157 void msp430_init_dco_done(){
158 //char *dcochoice=(char *) DCOCHOICEAT; //First word of RAM.
162 //! Initialize the MSP430 clock.
163 void msp430_init_dco() {
165 //char *dcochoice=(char *) DCOCHOICEAT; //First word of RAM.
167 #ifdef __MSP430_HAS_PORT8__
168 P8SEL = 0; // disable XT2 on P8.7/8
171 //Set P2.6 mode for MSP430F2274
172 #ifndef __MSP430_HAS_PORT5__
173 P2SEL = 0; //disable XIN on 2274
178 BCSCTL1 = (STATICDCO>>8);
179 DCOCTL = (STATICDCO&0xFF);
181 if(CALBC1_16MHZ!=0xFF){
182 //Info is intact, use it.
183 BCSCTL1 = CALBC1_16MHZ;
184 DCOCTL = CALDCO_16MHZ;
187 Info is missing, guess at a good value.
189 A list of correct calibrations in included as dco_calib.c,
192 DCOCTL = 0x00; //clear DCO
194 BCSCTL1 = dco_calibrations[2*dcochoice+1];
195 DCOCTL = dco_calibrations[2*dcochoice];
197 dcochoice%=dco_calibrations_count;