Hi everyone,
I'm using CCS composer and I want to communicate from the msp430FR5969 with the ESP8266 module through UART communication. Basically I want to send an AT command to the ESP8266 through the USCI_A1 interrupt in order to obtain an answer (OK) and send it to the serial monitor on my PC using the USCI_A0 module.
The problem is that the code never enters the interrupt of USCI_A1, but only the one of USCI_A0.
//*************************************************************************************** // Sending data via UART: try to catch response to AT //*************************************************************************************** // #include <msp430.h> #include "driverlib.h" #include "stdint.h" #include <stddef.h> #include <string.h> #define RX_BUFFER_LENGTH 100 static volatile uint8_t RXbuffer[RX_BUFFER_LENGTH]; static volatile uint8_t RXbufferIDX; #define RX_BUFFER_LENGTH1 100 static volatile uint8_t RXbuffer1[RX_BUFFER_LENGTH1]; static volatile uint8_t RXbufferIDX1; // ------------------------------------------------------------------------- // UART SEND/PARSE STRING FUNCTIONS // ------------------------------------------------------------------------- // ------------------------------------------------------------------------------ // UART interface // ------------------------------------------------------------------------------- //USCI_A0 #define UART_TX_READY (UCA0IFG & UCTXIFG) #define UART_RX_READY (UCA0IFG & UCRXIFG) #define UART_TX_DONE (UCA0IFG & UCTXCPTIFG) #define UART_RESET_TX_DONE (UCA0IFG &= ~UCTXCPTIFG) //USCI_A1 #define UART_TX_READY_1 (UCA1IFG & UCTXIFG) #define UART_RX_READY_1 (UCA1IFG & UCRXIFG) #define UART_TX_DONE_1 (UCA1IFG & UCTXCPTIFG) #define UART_RESET_TX_DONE_1 (UCA1IFG &= ~UCTXCPTIFG) //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // --------------------------------------------------------------- // FUNCTIONS for USCI_A0 // --------------------------------------------------------------- // Send a single character using UART static void send_char(char c) { // Sending data through UART test while (!UART_TX_READY) ; UCA0TXBUF = c; while (!UART_TX_DONE) ; UART_RESET_TX_DONE; } // Send a string using UART static void send_str(char str[]) { while (*str != '\0') { send_char(*str); str++; } } static void send_int(int n, int b) { static char digits[] = "0123456789ABCDEF"; char buffer[5]; int i = 0, sign; if ((sign = n) < 0) { n = -n; } do { buffer[i++] = digits[n % b]; } while ((n /= b) > 0); if (sign < 0) { buffer[i++] = '-'; } while (--i >= 0) { send_char(buffer[i]); } } static void new_line() { send_char(0xD); send_char(0xA); } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // --------------------------------------------------------------- // FUNCTIONS for USCI_A1 // --------------------------------------------------------------- static void send_char1(char c) { // Sending data through UART test while (!UART_TX_READY_1) ; UCA1TXBUF = c; while (!UART_TX_DONE_1) ; UART_RESET_TX_DONE_1; } static void send_str1(char str[]) { while (*str != '\0') { send_char1(*str); str++; } } static void send_int1(int n, int b) { static char digits[] = "0123456789ABCDEF"; char buffer[5]; int i = 0, sign; if ((sign = n) < 0) { n = -n; } do { buffer[i++] = digits[n % b]; } while ((n /= b) > 0); if (sign < 0) { buffer[i++] = '-'; } while (--i >= 0) { send_char1(buffer[i]); } } static void new_line1() { send_char1(0xD); send_char1(0xA); } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // --------------------------------------------------------------- // UART INITIALIZATIONS // --------------------------------------------------------------- void init_UART_A0(void) { // UART1 port // 2.0 : TX // 2.1 : RX P2SEL1 |= (BIT0 | BIT1); P2SEL0 &= ~(BIT0 | BIT1); // --------------------------------------------------------------------- // Initialization of the UART // - No parity // - LSB first // - One stop bit // - 8-bit data // - UART mode (asynchronous) // - SMCLK clock is used (rate = 1MHz) // - Erroneous characters rejected // - No break characters interrupts // - Not dormant // - Software reset disabled // - Baudrate: 9600 baud // --------------------------------------------------------------------- UCA0CTLW0 = UCSWRST; // Reset UCA0CTLW0 = UCSSEL__SMCLK; // Setting the baudrate UCA0BR0 = 6; UCA0BR1 = 0x00; UCA0MCTLW |= UCOS16 | UCBRF_8; UCA0IE |= UCRXIE; // Enable USCI_A0 RX interrupt UCA0CTLW0 &= ~UCSWRST; // Unreset } void init_UART_A1(void) { // UART1 port // 2.5 : TX // 2.6 : RX P2SEL1 |= (BIT5 | BIT6); P2SEL0 &= ~(BIT5 | BIT6); UCA1CTLW0 = UCSWRST; // Reset UCA1CTLW0 |= UCSSEL__SMCLK; // Setting the baudrate UCA1BR0 = 6; UCA1BR1 = 0x00; UCA1MCTLW |= UCOS16 | UCBRF_8; UCA1IE |= UCRXIE; // Enable USCI_A1 RX interrupt UCA1IE |= UCTXIE; // Enable USCI_A1 TX interrupt UCA1CTLW0 &= ~UCSWRST; // Unreset } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // --------------------------------------------------------------- // Init the clock // --------------------------------------------------------------- static void init_clock(void) { // ------------------------------------------------------------------- // Setting the clock // MCLK at 1MHz sourced by DCO // SMCLK at 1MHz sourced by DCO for UART com // ACLK at 32Khz sourced by LFXT for I2C com with the sensor bord // ------------------------------------------------------------------- CSCTL0_H = CSKEY >> 8; // Unlock CS registers CSCTL1 = DCOFSEL_0; // Set DCO to 8 MHz CSCTL2 = SELA__LFXTCLK | SELS__DCOCLK | SELM__DCOCLK; // Set ACLK = LFXT (32kHz) and MCLK = SMCLK = DCO. CSCTL3 = DIVA__1 | DIVS__1 | DIVM__1; // All dividers set to 1 CSCTL0_H = 0x01; // Lock Register } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% //------------------------------------------------------------------------------ // USCI_A0 interrupt vector service routine. //------------------------------------------------------------------------------ #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__) #pragma vector=USCI_A0_VECTOR __interrupt #elif defined(__GNUC__) __attribute__((interrupt(USCI_A0_VECTOR))) #endif void USCI_A0_ISR(void) { switch (__even_in_range(UCA0IV, USCI_UART_UCTXCPTIFG)) { case USCI_NONE: break; case USCI_UART_UCRXIFG: RXbuffer[RXbufferIDX] = UCA0RXBUF; RXbufferIDX = (RXbufferIDX + 1) % RX_BUFFER_LENGTH; LPM3_EXIT; break; case USCI_UART_UCTXIFG: break; case USCI_UART_UCSTTIFG: break; case USCI_UART_UCTXCPTIFG: break; } } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% //------------------------------------------------------------------------------ // USCI_A1 interrupt vector service routine. //------------------------------------------------------------------------------ #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__) #pragma vector=USCI_A1_VECTOR __interrupt #elif defined(__GNUC__) __attribute__((interrupt(USCI_A1_VECTOR))) #endif void USCI_A1_ISR(void) { //debug string just to know if the interrupt works send_str("Success USCI_A1_ISR"); new_line(); switch (__even_in_range(UCA1IV, USCI_UART_UCTXCPTIFG)) { case USCI_NONE: break; case USCI_UART_UCRXIFG: RXbuffer1[RXbufferIDX1] = UCA1RXBUF; RXbufferIDX1 = (RXbufferIDX1 + 1) % RX_BUFFER_LENGTH1; send_str("Data recieved!"); send_int(RXbufferIDX, 10); new_line(); LPM3_EXIT; break; case USCI_UART_UCTXIFG: break; case USCI_UART_UCSTTIFG: break; case USCI_UART_UCTXCPTIFG: break; } } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% //MAIN void main(void) { volatile unsigned j; WDTCTL = WDTPW | WDTHOLD; // Stop Watchdog Timer PM5CTL0 &= ~LOCKLPM5; // This is Needed for MSP430FR5969! init_clock(); init_UART_A0(); init_UART_A1(); _EINT(); // Enable interrupts globally. while (1) { send_str("begin"); new_line(); send_char1('A'); send_char1('T'); new_line1(); send_str("AT sent"); new_line(); LPM3; } }
Here we can see that the code never enters in USCI_A1 interrupt.