This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Hello!
I ask for help in solving the following problem: I submit characters from the terminal program (PuTTY) to the input of the UART receiver, in the RX interrupt I put the received symbol to the transmit buffer, but I cannot correctly receive more than half of the ASCII table symbols, instead of the symbol I receive 0xFF. I see correct test message after UART initiated, so I suspect that TX part works well. The second problem is that UART starts transmitting the symbol without waiting for the reception to end. Code and screenshots of the logic analyzer are attached.
I would be very grateful if this problem is solved.
Code
// Init UART static void msp430_uart_init() {
// Put the USCI state machine in reset UCA1CTL1 |= UCSWRST; // P4.4,5 = USCI_A1 TXD/RXD P4SEL |= BIT4 | BIT5; UCA1CTL1 |= UCSSEL1; UCA1BR0 = 34; // 115200 UCA1BR1 = 0; UCA1MCTL |= ( UCBRS_2 | UCBRS_1 ); // 115200 --> 6 // Take the USCI state machine out of reset UCA1CTL1 &= ~UCSWRST; // Enable the RX interrupt. UCA1IE |= UCRXIE; puts_u1("HELLO!\r\n"); // saw this correct } // Interrupt handler #pragma vector = USCI_A1_VECTOR __interrupt void USCI_A1_ISR(void) { volatile uint8_t symbol; switch(__even_in_range(UCA1IV,4)) { case 0:break; // Vector 0 - no interrupt case 2: // Vector 2 - RXIFG symbol = UCA1RXBUF; putchar_u1(symbol); break; case 4: // Vector 4 - TXIFG break; default: break; } } // Send debug info // Send char to UART1 void putchar_u1(uint8_t ch) { while(!(UCA1IFG & UCTXIFG)) {;} UCA1TXBUF = ch; } // Send string to UART1 void puts_u1(uint8_t *str) { while(*str) { putchar_u1(*str++); } }
"
case
2:
// Vector 2 - RXIFG
symbol = UCA1RXBUF;
putchar_u1(symbol); // This is probably a bad idea in an ISR For echo use registers
break
;
Yes, Peter, I fully agree with this and use deferred interrupts as much as possible. It all started with a search for the reason why such simple code doesn't work.
#pragma vector = USCI_A0_VECTOR
__interrupt void USCI_A0_ISR(void)
void __attribute__ ((interrupt(USCI_A0_VECTOR))) USCI_A0_ISR (void) { volatile uint8_t symbol; if(UCA0IFG & UCRXIFG != 0) { symbol = UCA0RXBUF; serial_buf[head++] = symbol; if(head == max_idx) { head = 0; } if(symbol == '\n') { // tell upstairs
// ... LED_RED_TOGGLE; } } }
Bruce, thank you very much for the hint, I checked the frequency of the SMCLK and it was twice as high as the frequency of quartz (using it on XT2). So I changed the initialization constants of the UARTs and got rid of the problem. I'm newbie with MSP430,so maybe I'm forgot to init clocks properly.
Thanks a lot!
**Attention** This is a public forum