Go Down

Topic: Arduino Due libraries (official and 3rd party) (Read 126682 times) previous topic - next topic


Hi all,

I have developed a software serial library for the Arduino DUE which provides up to nine software serial objects associated with the Timer/Counter module channels available in the Atmel ATSAM3X8E. You can use those serial objects in the same manner that the hardware serial objects Serial, Serial1, Serial2 and Serial3.

I have called the library soft_uart, and it is openly available in the following link:


I have checked the library intensively with the hardware I have available, but any feedback or suggestion for improvement will be welcomed.

I hope it helps.



Hi all,

I have made a small improvement to WInterrupts.c which allows a faster interrupt dispatching associated to generic I/O pins. That is, the callbacks we set with function attachInterrupt().

Basically I have modified the code of the interrupt handler functions PIOA_Handler(), PIOB_Handler(), PIOC_Handler() and PIOD_handler() in the original WInterrupts.c. The improvement consists mainly in taking advantage of ATSAM3XE assembler instruction CLZ. With this instruction it is possible to calculate the number of leading zeros in a 32 bit value in just one machine instruction. CLZ is available in C/C++ using CMSIS function __CLZ().

Using this small improvement I have been able to get to a bit rate of 115200 with my software serial library for the DUE, soft_uart (using the example provided with soft_uart and two stop bits). Take into account that soft_uart uses the interrupt for pin level changes on the RX pin associated to the software serial object when used. Without the improvement soft_uart could only get to 57600 (same example also with two stop bits).
Herein I include attached the file WInterrupts.c with the PIO handlers modified (the previous versions of the handlers are also on the file, but commented). To illustrate the change here you have the code for handler PIOA_Handler() (the previous one appears commented), the other ones are alike:

Code: [Select]

//void PIOA_Handler(void) {
//      uint32_t isr = PIOA->PIO_ISR;                                                
//      uint32_t i;
//      for (i=0; i<32; i++, isr>>=1) {                                              
//              if ((isr & 0x1) == 0)                                                
//                      continue;
//              if (callbacksPioA[i])                                                
//                      callbacksPioA[i]();                                          
//      }      

void PIOA_Handler(void) {                                                            
 register uint32_t isr = PIOA->PIO_ISR;                                              
 register uint8_t leading_zeros;                                                    
   register uint8_t pin=32-leading_zeros-1;                                          
   if(callbacksPioA[pin]) callbacksPioA[pin]();                                      

If you want to check this version of WInterrupts.c just overwrite the original with this new one.

Sincerely, I consider this change can benefit any code using interrupts associated to any Arduino DUE I/O pin with function attachInterrupt(). Once tested enough by more people, maybe it might be convenient to apply the change to the official Arduino DUE standard library. Anybody knows to whom I have to address to propose the change?.



""Anybody knows to whom I have to address to propose the change?""

i am not sure but probably Nick Gammon is the one you are looking for.


Hi, I'm having a lot of problems with the libraries of DHT22 humidity and temperature sensor and Arduino DUE.

It seems to have an ARM microcontroller, that driver must have a configuaciĆ³n different pins, and not just go well.

There is someone who can send me a code that I work at least to put the value in a variable moisture and other temperature value?

From there and I would deal myself.

Thank you so much for everything.


Go Up