Less intrusive serial out communication to pc with arduino due

Hello everyone,

I'm quite new in microcontroller programming and i would like to ask you some advices or suggestions for my problem.

I wrote a program that samples and adc at fixed frequency (40kHz) using a timer interrupt and makes some calculations between two samples. This part works nice.

Following, i need a slow task that sends a value on the serial each second in order to monitor this value on a pc. I've implemented this in the main loop, counting up to 40000 and executing a serial.print (one serial.print each 40000 samples).

The problem is that at the moment that the serial.print is executed, it seems to use a lot of calculation time and the main task that samples at fixed frequency lost several samples. It's like when the serial is used, the timer interrupt used to adc sample is not more high priority.

Could you please give me some advices or any idea on how i can have a slow serial communication not impacting my high priority activity? Maybe you know to do it somehow using low level code and not using serial arduino library.

I've read that it is faisable maybe with an rtos but it seems still not possible for arduino due. Moreover, i'm not a programmer and i have any knowledge in os.

Thank you very much in advance.

Have a nice day.

How much data are you printing each second over serial and at what baud rate? The hardware serial has a small ring buffer and as long as it's not full then serial print will return quickly but if the buffer is full then serial print will block until the buffer is empty/has enough room for your serial print data.

Are you trying to store the 40000 samples (where?) and send them once per second?