Tool/software:
Hello,
I am working on trying to send data from a computer to a MSP430F2232 using USB. Therefore I am using a CP2102 to get UART from the USB.
I am trying to receive the data from this UART. I use the program PuTTY to send data over USB and I want to get this on the microcontroller.
Is there code for receiving the data? I am currently trying to use the next code (but i get the error UCFE(USCI Frame Error Flag)):
#include <msp430f2232.h>
#define BUFFER_SIZE 64
volatile unsigned char rxBuffer[BUFFER_SIZE];
volatile unsigned int rxIndex = 0;
void UART_Init(void) {
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
// Configure DCO to ~1MHz
BCSCTL1 = CALBC1_1MHZ;
DCOCTL = CALDCO_1MHZ;
// Configure UART pins
P3SEL |= BIT4 + BIT5; // P3.4 = RXD, P3.5 = TXD
P3DIR |= BIT5; // TXD as output
// Configure USCI_A0 for UART
UCA0CTL1 |= UCSWRST; // Hold USCI in reset
UCA0CTL1 |= UCSSEL_2; // SMCLK
UCA0BR0 = 104; // 1MHz / 9600 baud
UCA0BR1 = 0;
UCA0MCTL = UCBRS_1; // Modulation
UCA0CTL1 &= ~UCSWRST; // Initialize USCI
IE2 |= UCA0RXIE; // Enable RX interrupt
}
#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCI0RX_ISR(void) {
unsigned char received = UCA0RXBUF;
if (rxIndex < BUFFER_SIZE) {
rxBuffer[rxIndex++] = received;
}
}
int main(void) {
UART_Init();
__enable_interrupt(); // Enable global interrupts
while (1) {
// MCU in low-power mode, wake-up via UART interrupt
__bis_SR_register(LPM0_bits + GIE);
// Do something with rxBuffer in debug/watch
}
}