Hi
I am using the MSP430F5529 Launchpad, interfaced with an OBD-II UART (https://www.sparkfun.com/products/9555) module in vehicles.
The uart is interrupt driven, and my question is how do we know when to disable the receive interrupt if the amount of bytes coming from the vehicles OBD isn't known?
#include "msp430x552x.h" #include "delay.h" #include <stdlib.h> #include <stdio.h> unsigned int _rxCounter; //char tx[]; char rx[]; unsigned char *transmit; unsigned char currChar; unsigned char charCount; void UART_transmit(unsigned char *cmd, unsigned char count); void main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop WDT //P1DIR |= 0x1; //P4DIR |= 0x8; P3SEL |= BIT3+BIT4; // P3.3,4 = USCI_A0 TXD/RXD P3REN |= BIT3 + BIT4; UCA0CTL1 |= UCSWRST; // **Put state machine in reset** UCA0CTL1 |= UCSSEL_2; // SMCLK UCA0BR0 = 208; // 1MHz (see User's Guide) UCA0BR1 = 0; // 1MHz 115200 UCA0MCTL |= UCBRS_1 + UCBRF_0; // Modulation UCBRSx=1, UCBRFx=0 UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine** //UCA0IE |= UCRXIE; // Enable USCI_A0 RX interrupt __enable_interrupt(); UART_transmit("ATZ", 3); _rxCounter = 0; UART_transmit("ATRV", 4); UART_receive(); while(1); //__bis_SR_register(LPM0_bits + GIE); // Enter LPM0, interrupts enabled //__no_operation(); // For debugger } void UART_transmit(unsigned char *cmd, unsigned char count) { transmit = cmd; charCount = count; UCA0IE |= UCTXIE; //__bis_SR_register(LPM0_bits + GIE); //__no_operation(); } void UART_receive(void){ UCA0IE |= UCRXIE; //__bis_SR_register(LPM0_bits + GIE); __no_operation(); } #pragma vector=USCI_A0_VECTOR __interrupt void USCI_A0_ISR(void) { switch(__even_in_range(UCA0IV,4)){ case 0:break; case 2: rx[_rxCounter++] = UCA0RXBUF; break; case 4: if(charCount) { UCA0TXBUF = *transmit++; charCount--; } else { UCA0IFG &= ~UCTXIFG; //__bic_SR_register_on_exit(LPM0_bits); } break; default: break; } }