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.

Doubt with UART interrupt routine



Hello, i am trying to send continous data from my MSP430f2xxx uC to cmputer via UART. in the UI on computer, i have programmed in such a way, that when i receive (FFFFFFFFF)h from uC, the UI sends back a command to uC saying STOP sending data. now, on the MSP430, whenever i get any data on UART RX port, it generates an intr, and i have written the routine for that as well...

however, when i send this STOP command from UI, the prog below fails to understand the interrupt, and keeps on sending data to the computer. can anyone please tell me what could be goind wrong with the code?

 
/********************************************************/
#pragma vector = USCIAB1RX_VECTOR
  __interrupt void USCI1RX_ISR(void)
  {
       Recvd_Char[Buffer_Index] = UCA1RXBUF;                    // Take Data from RX Buffer
       if(Recvd_Char[Buffer_Index] == 'Z')                      // check the end of data stream from UI

       {
          __bic_SR_register_on_exit(LPM3_bits);
       }
       else
        Buffer_Index++;
  }

/********************************************************/
int Download_Data()
    {
       
        static int Read_Block_Cntr;
        static char Read_Page_Cntr;
       // static char Read_Col_Cntr;
       // static char Prog_Page_Index;
       
       
        Buffer_Index = 0;
        __bis_SR_register(LPM3_bits + GIE);       // Enter LPM3*/
 
        RETURN:
 if(Recvd_Char[0] == 'R')                                        //check for start of data transfer command
        {
            __delay_cycles(10);
            while (!(UC1IFG & UCA1TXIFG));                 // USCI_A0 TX buffer ready?
            UCA1TXBUF = 0x40;
    
     Buffer_Index = 0;
    
     for(Read_Block_Cntr = 0; Read_Block_Cntr <4096; Read_Block_Cntr++)
            {
              for(Read_Page_Cntr = 0; Read_Page_Cntr <128; Read_Page_Cntr++)
              {
                         NAND_ReadData((Read_Block_Cntr*128)+Read_Page_Cntr, 0, NAND_PAGE_SIZE_READ);
               }
            }
            __delay_cycles(10);
        
 }
 
else
 if(Recvd_Char[0] == '$')      // check if end of data sent by UI
    {
        ShutDown();     // if yes, shutdown
   }  
   else
    goto RETURN;        return (rc);
    }


/********************************************************/
void NAND_ReadData(
unsigned long int a_uiPageNum,
unsigned short a_usColNum,
unsigned short a_usReadSizeByte)
{
 int i;
              
        /////////// R E A D    B Y T E S ////////////
   
                      PORT4_DIR_IN;                                           //Assign Port4 as Input
                       
                      for(i=0;i< a_usReadSizeByte;i++)
                      {
                           NAND_READ_LOW;                                     //RE# = 0; while(txbuf is ready)
                           while (!(UC1IFG & UCA1TXIFG));
                           UCA1TXBUF = P4IN;                                  //READ DATA FROM FLASH //txbuf = P4IN;
                           NAND_READ_HIGH;                                    //RE# = 1;
                       }
       
                       /*End of Read Bytes Routine*/
   
  //return 0;
 } /* NAND_ReadData */
  

  • Funny1234 Guy said:
    if(Recvd_Char[0] == '$')

    This only tests the first entry of the buffer.  You probably ought to use the latest entry or catch the value in the Rx ISR and set a flag for the main loop to monitor.

     

  • chris_m, i am checking only the 1st entry of the buffer Recvd_Char[]... i have switch cases depending on the 1st entry of the buffer... also, the value of Recvd_Char[]  gets updated when a new intr happens

  • Funny1234 Guy said:
    hen i send this STOP command from UI, the prog below fails to understand the interrupt, and keeps on sending data to the computer.

    Oh, no, it understands the interrupt and stops sending - but only after it has returned from the sending function. And alas, there' snothing to stop anymore as the sending has already finished.

    You'll need to check for "$" (and whether the buffer counter is >0 a tall) inside the NAND_ReadData funciton. If you only check it after the funciton has already done its job and sent everything, you're too late to stop it sending.

**Attention** This is a public forum