The clock tree in the MSP430 is actually composed of several signals whose source is selectable. This flexibility helps power CPU and peripherals using different clocks to achieve either speed or low power. The main signals in the MSP430 include: ACLK: Auxiliary clock. ACLK is software selectable as LFXT1CLK or VLOCLK. ACLK is divided by 1, 2, 4, or 8. ACLK is software selectable for individual peripheral modules. MCLK: Master clock. MCLK is software selectable as LFXT1CLK, VLOCLK, XT2CLK (if available on-chip), or DCOCLK. MCLK is divided by 1, 2, 4, or 8. MCLK is used by the CPU and system. SMCLK: Sub-main clock. SMCLK is software selectable as LFXT1CLK, VLOCLK, XT2CLK (if available on-chip), or DCOCLK. SMCLK is divided by 1, 2, 4, or 8. SMCLK is software selectable for individual peripheral modules. Clock source for UART
Baud rate Generator Configure the MSP430 UART to transmit and receive at baud rate of 9600bps with 8 data bits, no Parity and 1 Stop bit Baud rate : The rate at which bits are transmitted per second. Ex: Baud rate 9600 is nothing but the module will transmit 9600 bits per second. Standard baud rates include 110, 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 38400, 57600, 115200 Easiest way to configure the baud rate of a MSP430 device is to use the Baud rate selection table listed in the user manual. Just find out the UCBRx values corresponding to your BRCLK frequency and the baud rate you wish to use. After finding out values just put them in the UCA0BR0 and UCA0BR1 register to configure the baud rate.
Baud Rate Generator 1MHz 1MHz 104 104
UART Registers Receiver Buffer Register( UC0RXBUF ): It is used to store the data byte received. After character is received, UC0RXIFG flag in IFG2 register will set indicating completion in receive of 8 bit data Transmit Buffer Register( UC0TXBUF ): Load this register the data need to be transmitted. After character is transmitted, UC0TXIFG flag in IFG2 register will set indicating completion in Transmit of 8 bit data UCA0CTL1 -The two important bits contained in this register are These bits are used to select the clock source to the USCI module.In our case we are going to select SMCLK @1MHz. This bit is used to put the USCI module in reset state. It is recommended to put the USCI module in reset state before making any changes to the registers. UCAxBR0 ( UCA0BR0 ) and UCAxBR1 ( UCA0BR1 ) are two 8 bit registers which are used to set the value for the Baud rate generator
Program to transmit character at 9600 baud rate and receive the same. If the character received is ‘A’, Blink the LED connected to P1.6 . Microcontroller-1 Microcontroller-2 If there are two microcontroller we can perform serial communication by connecting Tx of microcontroller-1 with Rx of microcontroller-2, and connecting Tx of microcontroller-2 with Rx of microcontroller-1 If there is only one microcontroller we can test the working of serial communication by connecting Tx of microcontroller with Rx of same microcontroller.
Program to transmit character at 9600 baud rate and re Program to transmit character at 9600 baud rate and receive the same. If the character received is ‘A’, Blink the LED connected to P1.6
Program to transmit character at 9600 baud rate and receive the same. If the character received is ‘A’, Blink the LED connected to P1.6 . #include "msp430g2553.h" void main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop the Watch dog if (CALBC1_1MHZ==0xFF) // If calibration constant erased { while(1); // do not load, trap CPU!! } DCOCTL = 0; // Select lowest DCOx and MODx settings BCSCTL1 = CALBC1_1MHZ; // Set range DCOCTL = CALDCO_1MHZ; // Set DCO step + modulation P1DIR = 0x41; // P1.0 and P1.6 output; 0x41= 0100 0001 P1OUT = 0 << 0; //BIT0 + BIT6; // P1.0 and P1.6 = 0 P1OUT = 0 << 6; P1SEL = 0x06; // P1.1 UCA0RXD input P1SEL2 = 0x06; // P1.2 UCA0TXD output UCA0CTL1 = UCSSEL_2 ; // USCI Clock = SMCLK,USCI_A0 disabled UCA0BR0 = 104; // 104 From datasheet table- UCA0BR1 = 0; // selects baud rate =9600,clk = SMCLK UCA0CTL1 &= ~UCSWRST; // Clear UCSWRST to enable USCI_A0 while(1) { UCA0TXBUF = 'A'; // Transmit a data while(!UCA0TXIFG); // Wait until transmission is complete P1OUT ^= 1; // Blink LED connexted to P1, when transmission is complete while(!UCA0RXIFG); // Wait until receiving of data is complete if (UCA0RXBUF == 'A') // if data received is 'A' { P1OUT ^= 1 << 6; // Blink led connected to P1.6 IFG2 &= ~UCA0RXIFG; // Clear RX flag } volatile unsigned int j = 50000; // delay while(j--); } } Check the calibration data. If it is 0xFF, the calibration data might have erased which was written at factory during the production of chip. Stop CPU from further processing if it is 0xFF. Set Digital Control Oscillator(DCO) The first line of code clears DCOCTL to set the DCOCLK to the lowest setting. Next the calibration data is copied into the DCOCTL and BCSCTL1 registers respectively. The DCOCLK is now running at 1MHz *Configure P1.0 & P1.6 for I/O Operation *Switch off LED connected to P1.0 and P1.6 P1.0 - --> RED Led P1.6 ---> Green Led *Configure P1.1 for RX Operation *Configure P1.2 for TX Operation *Select Clock(SMCLK) *Set data transmission/reception speed baud rate(number of bits per second) to 9600 By loading Character to be transmittd (‘A’) to UCA0TXBUF register, transmission will start. Wait for transmission to complete. After Transmission of character ‘A’, UCA0TXIFG flag will set. If flag is set, then toggle LED connected to P1.0 Wait for Reception of data to complete. After data received of character ‘A’, UCA0TRXIFG flag will set. The character received will be in UCA0RXBUF register. Check whether character received is ‘A’. If yes, then toggle LED connected to P1.6 Do not forget to Clear UCA0RXIFG flag.