Quantcast
Channel: Forums - Recent Threads
Viewing all articles
Browse latest Browse all 262198

UART ignoring first interrupt?

$
0
0

Hi guys/girls,

My UART seems to work with the exception of the first reply. I set it up, and wait till 5 bytes have been received before doing some processing and then returning 3 bytes. However, the first 5 bytes I send don't trigger a reply. Can anyone offer any help?

int main(void)
{
  WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT

  UART_Init();
  SPI_InitEEPROM();

  _enable_interrupts();
  UART_SendByte(0xDD);    /* shows successful start-up */

  while(1)
  {
      if(_DataReady == 1)
      {
          _DataReady = 0;
          UART_SendByte(_Command[0]);    /* echos command */
          UART_SendByte(CLI_Run());        /* sends SPI reply byte */
          UART_SendByte(0xA0);            /* used for debugging to show reached end of statement */
      }
  }
}

UART initalisation:

extern void UART_Init(void)
{

      DCOCTL = 0;
      BCSCTL1 = CALBC1_1MHZ;                    // Set DCO to 1MHz
      DCOCTL = CALDCO_1MHZ;

      UCA0CTL1 |= UCSWRST;                        // put UCSI in reset

      P1SEL = BIT1 + BIT2;
      P1SEL2 = BIT1 + BIT2;                        // P1.1 = USCI Tx, P1.22 = USCI_A0 Rx

      UCA0CTL1 |= UCSSEL_2;                     // SMCLK
      UCA0BR0 = 8;                              // 1MHz to 115200baud
      UCA0BR1 = 0;                              // 1MHz to 115200baud
      UCA0MCTL = UCBRS2 + UCBRS0;               // Modulation UCBRSx = 5

      UCA0CTL1 &= ~UCSWRST;                     // Bring USCI out of reset
      IE2 |= UCA0RXIE;                          // Enable USCI_A0 RX interrupt - put this before reset?
}

UART Tx function and Rx interrupt:

extern uint8 UART_SendByte(uint8 data)
{
    while (!(IFG2&UCA0TXIFG));    // USCI_A0 TX buffer ready?
    UCA0TXBUF = data;           // send byte
}
 /* USCI A0 Rx Interrupt Routine */
#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCI0RX_ISR(void)
{
      while (!(IFG2&UCA0TXIFG));                // Tx ready? i.e. make sure not currently transmitting
            if(_ByteCounter<N_BYTES)
            {
                _Command[_ByteCounter] = UCA0RXBUF;
                  _ByteCounter++;
            }
            else
           {
                _DataReady = 1;
                _ByteCounter = 0;
           }
}

I am still having trouble with my SPI and I am beginning to wonder if this is somehow linked?

Any help greatly appreciated!


Viewing all articles
Browse latest Browse all 262198

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>