Hello All,
I am new to Microcontroller programming so please bear with me. I appreciate any help the community can provide. I'm working to put two pieces of code together. One controls an RGB led and one is the msp430g2xx3_usci_uart_9600 sample code. I can run both pieces of code independently and they work great. The problem comes in when I attempt to combine them. Apparently after I set the clock using BCSCTL1 = CALBC1_16Mhz, the uart stuff does not function. I've included the USCI UART demo I'm building from below. It works great until I add the bit about setting the clock to 16Mhz. Any help would be greatly appreciated. I know I'm missing something obvious so please go easy on me. :) Thanks! -Corey
//******************************************************************************// MSP430G2xx3 Demo - USCI_A0, 9600 UART Echo ISR, DCO SMCLK//// Description: Echo a received character, RX ISR used. Normal mode is LPM0.// USCI_A0 RX interrupt triggers TX Echo.// Baud rate divider with 1MHz = 1MHz/9600 = ~104.2// ACLK = n/a, MCLK = SMCLK = CALxxx_1MHZ = 1MHz//// MSP430G2xx3// -----------------// /|\| XIN|-// | | |// --|RST XOUT|-// | |// | P1.2/UCA0TXD|------------>// | | 9600 - 8N1// | P1.1/UCA0RXD|<------------//******************************************************************************/* * ======== Standard MSP430 includes ======== */#include <msp430.h>
/* * ======== Grace related declaration ======== */extern void CSL_init(void);
/* * ======== main ======== */int main(void){ CSL_init();
//Code added here... //Set clock BCSCTL1 = CALBC1_16MHZ; //set range DCOCTL = CALDCO_16MHZ;//set dco step and modulation BCSCTL3 |= LFXT1S_2; // dco ////IFG1 &= ~OFIFG; //osc fault flag BCSCTL2 |= SELM_0; //sel DCO = mclk //End of added code...
__bis_SR_register(LPM0_bits + GIE); // Enter LPM0, interrupts enabled}
void USCI0RX_ISR(void){ while (!(IFG2&UCA0TXIFG)); // USCI_A0 TX buffer ready? UCA0TXBUF = UCA0RXBUF; // TX -> RXed character}
The Baud rate divider from the demo is commented as being calculated on the assumption that MCLK = SMCLK = 1MHz.
If the MCLK has been increased to 16 MHz then the baud rate divider needs to increased to 16MHz/9600 = ~1666.7
Thanks for reply! That makes sense. Do you know how I would go about updating the baud rate divider?
Hello Corey,
You are already using Grace. Why not look into configuring the USCI there?
Regards,Michael
www.ti.com/grace
MSP430 16 bit Microcontroller | MCU | MSP430 Microcontroller Code | MSP430 Microcontroller Kits | MSP430 8 bit Microcontroller | MCU | TI Microcontroller | MCU
Thanks Michael! That put me on the right track! Setting the clock to 16Mhz in the grace configuration did the trick for both pieces of code. Thanks!