Go Down

Topic: USART2 Interrupt handler issue in SAM3X8e arduino due (Read 520 times) previous topic - next topic

PoovaiAnitha

Hi All,


I'm working with USART2 in arduino due. In which below mention my code,

void setup() {
 

  System_Init();
   

}

void loop() {
 
 USART2->US_THR = 's';


}


void USART2_Handler(void)

 
  if (USART2->US_CSR & 0x00000001)
  {
    uint8_t in =  USART2->US_RHR; // Read in received byte   
   
    if (in == 'b')
    {
     
      USART2->US_THR = 's';
     
    }
   
    }
}

void System_Init(void)
{
  // port peripheral initialization
 
  WDT->WDT_MR = WDT_MR_WDDIS;
  PIOB->PIO_IDR |= PIO_PB20_USTXD | PIO_PB21_USRXD ;
  PIOB->PIO_PDR |=  PIO_PB20_USTXD | PIO_PB21_USRXD ;
  PIOB->PIO_ABSR &= ~(PIO_ABSR_TX_RX);
  PIOB->PIO_PUER |= PIO_PB20_USTXD | PIO_PB21_USRXD;
  PMC->PMC_PCER0 |= PMC_PERIPHERAL_ID;
  USART2->US_CR = USART_CR_RSTRX | USART_CR_RSTTX | USART_CR_RXDIS | USART_CR_TXDIS;
  USART2->US_MR = USART_MR_USCLKS | USART_MR_CHRL | USART_MR_SYNC | USART_MR_PAR | USART_MR_MSBF;
  USART2->US_BRGR = USART_BRCD | USART_BRFP ;
  NVIC_EnableIRQ(USART2_IRQn );

 
  USART2->US_IER = 0x00000002  | 0x00000001 | 0x00000005 |0x00000006;

    USART2->US_CR = USART_CR_RXEN | USART_CR_TXEN;
   
 
}




when I enable the receiver and transmitter in USART2, loop function isn't work. But when i send the data from PC to arduino due, it's work fine.. it mean the interrupt handler act also work fine.. But our main problem to be
 1.why the Void loop() function isn't executed when i enable the transmitter and receiver in USART2?
 2. How to activate both interrupt handler and loop function? check whether I miss any configuration on my code?
3. why the SAM3X8E controller goes to sleep mode when i enable the RX and TX?

Kindly give any suggestion for my problem.

Thanks & regards,
Poovai Anitha.L

ard_newbie

Firstly you have to alter variant.h to write your own USART2 interrupt handler

PoovaiAnitha


PoovaiAnitha

I modified the variant.c and header file for USART2. But I had receive continuous receiver interrupt. How can I resolved this issue ?

#include <variant.h>

void setup() {
  // put your setup code here, to run once:
  init();
  Serial4.begin(9600);
  Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  USART2->US_THR = 'S';
  while((USART2->US_CSR & 0x000000002) == 0);

}


void serialEvent4()
{
 
 
  if (Serial4.available())
  {
  USART2->US_THR = USART2->US_RHR;
 
  while((USART2->US_CSR & 0x000000002) == 0);
  }

}



continuously i get the serialevent4 interrupt. Please give solution for my issue..


Thanks & Regards,
Poovai Anitha.L

ard_newbie


The DUE configuration initializes Serial, Serial1, Serial2 and Serial3. For Serial4 initialization, you need some extra lines of code (search example codes in the DUE sub forum for Serial4 initialization).

Go Up