Hi,
I am trying to interface MSP430FR2433 with the PC over UART with a baud rate of 115200. I want to send some data from PC to microcontroller and depending on what data is received, the microcontroller is supposed to behave differently. I am able to send the data to PC but not able to receive it back. I am using FTDI TTL Serial USB cable, and connecting TX, RX, and GND using fly wires which connect to PC on COM port. I have UCA0 UART ISR which supposed to trigger when anything is received on RX line. But it's not triggering at all. I have tried using the different serial terminals, but no luck. And I don't know if there is anything I am missing. Any help will be greatly appreciated, thanks in advance.
Here is the code:
// ========== header file includes ============================================ #include <msp430fr2433.h> #include <stdbool.h> #include <stdint.h> #include <stdio.h> #include <string.h> // ========== constants ======================================================= #define CR 13 #define LF 10 #define UART_TIMEOUT 9876 // ========== global variables ================================================ char rx_data; char debug_string [123]; uint64_t seconds = 0; // ========== function prototypes ============================================= void uart_init(void); bool uart_send_debug_string(char []); bool uart_send_byte(char); void init_RTC(void); // ========== function definitions ============================================ /* * @brief This is the main function * @param None * @return None */ void main (void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer uart_init(); // Disable the GPIO power-on default high-impedance mode // to activate previously configured port settings PM5CTL0 &= ~LOCKLPM5; __enable_interrupt(); // enable all interrupts --> GIE = 1 (HIGH) uart_send_debug_string("Hello World"); while(1) { } } // UCA0 UART ISR #pragma vector=USCI_A0_VECTOR __interrupt void USCI_A0_ISR(void) { switch(__even_in_range(UCA0IV,USCI_UART_UCTXCPTIFG)) { case USCI_NONE: break; case USCI_UART_UCRXIFG: UCA0IFG &=~ UCRXIFG; // Clear interrupt rx_data = UCA0RXBUF; // Store buffer sprintf(debug_string, "Received: %c", rx_data); uart_send_debug_string(debug_string); break; case USCI_UART_UCTXIFG: break; case USCI_UART_UCSTTIFG: break; case USCI_UART_UCTXCPTIFG: break; } } // end UCA0 UART ISR // **************************************************************************** // RTC interrupt service routine #pragma vector=RTC_VECTOR __interrupt void RTC_ISR(void) { switch(__even_in_range(RTCIV,RTCIV_RTCIF)) { case RTCIV_NONE: break; // No interrupt case RTCIV_RTCIF: // RTC Overflow P1OUT ^= BIT0; // Blink P1.0 seconds++; sprintf(debug_string, "Seconds: %llu", seconds); uart_send_debug_string(debug_string); break; default: break; } } // end RTC interrupt service routine // **************************************************************************** /* * @brief Initialize the USCI A0 UART communication * @param None * @return None */ void uart_init (void) { // Configure UART pins P1SEL0 |= BIT4 | BIT5; // set 2-UART pin as second function // Configure UART UCA0CTLW0 |= UCSWRST; // Put eUSCI in reset UCA0CTLW0 |= UCSSEL__SMCLK; // Chose SMCLK as clock source // Baud Rate calculation for 115200 with SMCLK (1MHz) // 1000000/115200 = 8.68 // 1000000/115200 - INT(1000000/115200)=0.68 // UCBRSx value = 0xD6 (See UG) UCA0BR0 = 8; UCA0MCTLW = 0xD600; UCA0BR1 = 0; UCA0CTLW0 &= ~UCSWRST; // Initialize eUSCI UCA0IE |= UCRXIE; // Enable USCI_A0 RX interrupt } // end uart_init // **************************************************************************** /* * @brief This function send the given byte over USCI A0 UART * @param[in] data - char byte to send * @return true is successful, false if failed */ bool uart_send_byte (char data) { uint16_t uart_timeout = UART_TIMEOUT; // load time out value while((!(UCA0IFG & UCTXIFG))&&(uart_timeout>0)) { uart_timeout--; // wait till TX interrupt pending } if(uart_timeout == 0) { return false; // failure if time out } UCA0TXBUF = data; uart_timeout = UART_TIMEOUT; // again load time out value while((!(UCA0IFG & UCTXIFG))&&(uart_timeout>0)) { uart_timeout--; // wait till TX interrupt pending } if(uart_timeout == 0) { return false; // failure if time out } return true; // success otherwise } // end uart_send_byte // **************************************************************************** /* * @brief This function send the given string over USCI A0 UART * @param array char array to send * @return true is successful, false if failed */ bool uart_send_debug_string (char array[]) { uint16_t size = strlen(array); uint16_t index = 0; for(index=0; index<size; index++) { if(!uart_send_byte(array[index])) // send char one by one { return false; } } if(!uart_send_byte(CR)) // send carriage return { return false; } if(!uart_send_byte(LF)) // send line feed for new line { return false; } return true; } // end uart_send_debug_string // **************************************************************************** /* * @brief Initialize the system RTC, to tick multiple of 1 second * @param None * @return None */ void init_RTC (void) { // RTC count re-load compare value RTCMOD = (1026); // Source = SMCLK (1MHz), divided by 1024 RTCCTL = RTCSS__SMCLK | RTCSR | RTCPS__1024 | RTCIE; P1DIR |= BIT0; // Set P1.0 to output direction } // end init_RTC // ****************************************************************************
And data captured by Putty: