Hello,
I just wanted to make sure that I have set up the clocks and other things correctly.
I am working on MSP430F2416 , UART1 with no hardware flow control. Still I have set CTS and RTS input and output low. They are left unconnected/floating on PCB. MCU is connected to Vcc, GND, UART-TX, UART-RX (115200 baud rate).
//////////////////////////CODE - START/////////////////////////////////////////////////////////////////////////////////////////
#include "msp430f2416.h"
int main(void)
{
unsigned int i;
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
// Setup Clocks for DCO = 16 MHz
// For DCO frequency = 16 MHz, RSELx = 15, DCOx = 7, MODx = 0
DCOCTL = DCO2 + DCO1 + DCO0;
BCSCTL1 = XT2OFF + RSEL3 + RSEL2 + RSEL1 + RSEL0;
// Do 'Oscillator Fault Interrupt Disable' and 'Oscillator Fault Interrupt Flag Clear' have to be done explicitely?????
// Configure pins
P3SEL = 0xc0; // Primary peripheral module function is selected for pins P3.6 (UCA1TXD), P3.7(UCA1RXD)
P3DIR = 0x40; // All pins of port 3 are as input and only P3.6 (UCA1TXD) needs to be set as output
P1SEL = 0x00; // Select pin 1.4 for I/O functions
P1DIR = 0x00; // Change CTS pin 1.4 to input direction
P1IN = 0x00; // Change CTS pin 1.4 to input always low
P4SEL = 0x00; // Select pin 4.3 for I/O functions
P4DIR = 0xff; // Change RTS pin 4.3 to output direction
P4OUT = 0x00; // Change RTS pin 4.3 to output always low
// UART1 settings -> no parity, 8-bit, 1 stop bit, UART mode; hence no changes in UCA1CTL0
UCA1CTL0 = 0x00;
// Resets UART1 and selects SMLK as clock source
UCA1CTL1 = UCSSEL1 + UCSSEL0 + UCSWRST;
// Setup Baud Rate/Modulation control of clock - 115200 baud
UCA1BR0 = 138; // Prescalar is 138 (BRCLK/BaudRate = 16,000,000/115200 = 138)
UCA1BR1 = 0;
UCA1MCTL = 0x00; // No Modulation Necessary!
// Initialize USCI state machine
UCA1CTL1 &= ~UCSWRST;
// Enable USCI_A1 TX & RX interrupts
UC1IE = UCA1TXIE + UCA1RXIE;
UC1IFG = 0x00; // Clearing UCSWRST sets TX interrupt flag which needs to be cleared
// or it calls TX interrupt even when there is no transmission
// Enable Interrupts
__bis_SR_register(GIE);
while(1)
{
UCA1TXBUF = 'u';
for(i=0;i<10000;i++); // Delay
}
}
#pragma vector=USCIAB1TX_VECTOR
__interrupt void usciab1_tx(void)
{
}
#pragma vector=USCIAB1RX_VECTOR
__interrupt void usciab1_rx(void)
{
}
//////////////////////////CODE - END/////////////////////////////////////////////////////////////////////////////////////////
I would really appreciate if someone can check my Clock settings and UART initialization. My hardware for hyperterminal / TeraTerm is working properly. However there seems to be some problem with setting up MCU/UART.
Thank you for your help.
Best,
Janet