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(){
32 void serial0_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 setbaud0(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){
86 void msp430_init_uart(){
88 // Serial on P3.4, P3.5
92 //UCA0CTL1 |= UCSWRST; /* disable UART */
97 UCA0CTL1 |= UCSSEL_2; // SMCLK
99 //UCA0BR0 = BAUD0EN; // 115200
101 setbaud(5);//default baud, 115200
103 UCA0MCTL = 0; // Modulation UCBRSx = 5
104 UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
107 //Leave this commented!
108 //Interrupt is handled by target code, not by bootloader.
113 //This must be in .noinit.
114 __attribute__ ((section (".noinit"))) char dcochoice;
116 //! Initialization is correct.
117 void msp430_init_dco_done(){
118 //char *dcochoice=(char *) DCOCHOICEAT; //First word of RAM.
122 //! Initialize the MSP430 clock.
123 void msp430_init_dco() {
125 //char *dcochoice=(char *) DCOCHOICEAT; //First word of RAM.
127 #ifdef __MSP430_HAS_PORT8__
128 P8SEL = 0; // disable XT2 on P8.7/8
131 //Set P2.6 mode for MSP430F2274
132 #ifndef __MSP430_HAS_PORT5__
133 P2SEL = 0; //disable XIN on 2274
138 BCSCTL1 = (STATICDCO>>8);
139 DCOCTL = (STATICDCO&0xFF);
141 if(CALBC1_16MHZ!=0xFF){
142 //Info is intact, use it.
143 BCSCTL1 = CALBC1_16MHZ;
144 DCOCTL = CALDCO_16MHZ;
147 Info is missing, guess at a good value.
149 A list of correct calibrations in included as dco_calib.c,
152 DCOCTL = 0x00; //clear DCO
154 BCSCTL1 = dco_calibrations[2*dcochoice+1];
155 DCOCTL = dco_calibrations[2*dcochoice];
157 dcochoice%=dco_calibrations_count;