I have two problems as below:
How can I disable all external interrupts except UART AND USART interrupts when using Arduino Due?
And how can I reset an IO to initial state (Not Input and Output mode)?
Please help me to solve that problems, thank you!
You are supposed to know what your code is doing, i.e. what interrupts have been enabled in which peripheral.
E.g. for UART:
You have somewhere :
UART->UART_IER = ......;
Conversely, if you have enabled somewhere an interrupt for TC0 and you don't need it anymore, you can write this:
However, Systick or Hardfault interrupts will still fire.
If you have an external interrupt with an attachinterrupt() somewhere, you can disable it with a detachinterrupt().
I guess you could even use a noInterrupts(); to stop peripheral interrupts and write e.g.:
NVIC_EnableIRQ(UART_IRQn); and NVIC_EnableIRQ(USART0_IRQn); to select interrupts from UART and USART0.
For PIO, they are in Input state enable by default.
Thank for your reply,
Firstly, I configured an external interrupt on a Pin for capturing a pulse (almost 0.01-1Mhz), and also configure a USART2 to communicate with another board.
Everything is fine (communication and capturing pulse) if the input pulse at low frequency (0.01-0.1 Mhz), but when the pulse at high frequency (0.1-1Mhz) then I can not communicate with other board.
If I don't configure to capture the pulse, the communication is fine also (even though the input pulse at high frequency). Then I am doubting about I did not detach interrupt pin in a right way.
I only used detachInterrupt(pin) but it does not solve my problem, then I also try to set the pin for capturing pulse to output mode, however no luck!.
After reading your reply,
Can you give me a suggestion to solve this problem
Although you didn't post all your code, at 1 MHz, you fire your attached interrupt every 1 us. Meanwhile, a Serial.println can take about 1 ms.
You should use a Timer Capture instead and avoid Serial printing at every pulse edge. Buffer your results and at the end of your experiment, print only what is necessary.