AnsweredAssumed Answered

ADuCM360:about uart

Question asked by bomlulu on Dec 17, 2015
Latest reply on Mar 17, 2016 by bomlulu

I want to realize the function:When uart receive the correct command,the code will output some words.When uart  receive the wrong command,code come back from interrupt,do nothing.And when uart  receive the correct command again,the code can work nommally.

 

BUT,the code I write ,once uart  receive the wrong  command,uart can't  receive anything.code can't come into the uart interrupt.

int fputc(int ch, FILE *f);               
void UARTINIT (void); 
unsigned char RxBufferFull  = 0;       
unsigned char  TxBufferEmpty = 0;    
unsigned char rxchar;
unsigned char ID=0x01;
unsigned char Pro_Flag[35]={0};
unsigned char Receive_Done=0;
unsigned char get_flag=0;
unsigned char count0;
int main (void)
{
   WdtCfg(T3CON_PRE_DIV1,T3CON_IRQ_EN,T3CON_PD_DIS); 
   ClkDis(CLKDIS_DISSPI0CLK|CLKDIS_DISSPI1CLK|CLKDIS_DISI2CCLK|CLKDIS_DISPWMCLK|CLKDIS_DIST0CLK|CLKDIS_DIST1CLK|CLKDIS_DISDMACLK); // Only enable clock to used blocks
   ClkCfg(CLK_CD0,CLK_HF,CLKSYSDIV_DIV2EN_DIS,CLK_UCLKCG); 
   ClkSel(CLK_CD7,CLK_CD7,CLK_CD0,CLK_CD7);  
   UARTINIT();                    
   NVIC_EnableIRQ(UART_IRQn);         
   printf("/*ADUCM360*/\r\n");
   while (1)
   {   unsigned  char i;
    if(Receive_Done==1)
  {     
  Receive_Done=0;
  for(i=0;i<=6;i++)
              printf("%u", Pro_Flag[i]);
   printf("\r\n");
  }
   }
}
void UARTINIT (void)                            
{   
   pADI_GP0->GPCON |= 0x3C;                       
   UrtCfg(pADI_UART,B9600,COMLCR_WLS_8BITS,0); 
    UrtMod(pADI_UART,COMMCR_DTR,0);              // Setup modem bits
   UrtIntCfg(pADI_UART,COMIEN_ERBFI|COMIEN_ETBEI|COMIEN_ELSI|COMIEN_EDSSI|COMIEN_EDMAT|COMIEN_EDMAR);   // Setup UART IRQ sources
}


 int fputc(int ch, FILE *f)      
{      
      while(!TxBufferEmpty);
      UrtTx(pADI_UART,ch);
      TxBufferEmpty = 0;
      return (ch);   
}
void UART_Int_Handler ()                               
{
   unsigned char tt;
   volatile unsigned char ucCOMSTA0 = 0;
   volatile unsigned char ucCOMIID0 = 0;

   ucCOMIID0 = UrtIntSta(pADI_UART);   // Read UART Interrupt ID register
   if ((ucCOMIID0 & 0x2) == 0x2)       // Transmit buffer empty
   {
      TxBufferEmpty = 1;
   }
   if ((ucCOMIID0 & 0x4) == 0x4)       // Receive byte
   {
      rxchar=UrtRx(pADI_UART);  
  if(rxchar==':')
  count0=0;
  Pro_Flag[count0++]=rxchar;
  if(rxchar=='\n')
  { 

  tt=((Pro_Flag[1]-0x30)*10)+(Pro_Flag[2]-0x30);
  if(tt==ID)
  {
  get_flag=((Pro_Flag[3]-0x30)<<4)+(Pro_Flag[4]-0x30);
  switch(get_flag)
  {
      case 0x41:
         if(count0==0x07)  
            Receive_Done=1;
         else 
            Receive_Done=0;
         count0=0;
         break;
      default:
         Receive_Done=0;
         count0=0;
         break;
  }
  }
      }
  }   
}

If I write the correct command ":0141\r\n" to the uart,it can work normally.But for example, if I write ":0148\r\n".uart can recieve,but then,whatever I write to the uart,it can't recieve.

Outcomes