I’ve been trying to implement a program on an Arduino UNO that samples AD values at 1 kHz and sends the acquired data via UART0 (USB) to a Raspberry Pi with a sufficient pySerial Interface.
My problem however is that the Serial.write command needs about 1 ms to execute, which is far too long because i try sampling with 1ms period and have to send out at least 4 bytes per ms, meaning at least 2 calls of Serial.write.
The code in v1.ino in the attachments was the first approach, where the problem appeared.
Since the overhead of the HardwareSerial class can’t be neglegted i tried to configure the UART and all the other needed modules manually and implemented my own ISR.
Note that i made some improvements regarding GPS synchronisation from v1 to v2.
Unfortunately the last version doesn’t seem to work at all.
To sum up the needed functionality of the program:
The Arduino receives a single byte representing the current run mode.
An auto-triggered ADC shall be executed every 1 ms.
For counting the Timer1 is used.
Timer1 is being reset by the PPS (pulse per second) signal of the GPS for synchronisation.
In mode ‘1’ the result, aswell as a timestamp representing the expired ms, shall be sent as uint16_t via USB.
In mode ‘2’ the GPS Location is written to the port as 3 floats.
For the record: I don’t own a oscilloscpe or logic analyzer to test the timer frequency or the UART ports
To view the output i use either my python interface or the screen packet on linux:
screen /dev/ttyACMx y
where x is the Portnumber and y is the baud rate
I noticed that the data gets completly corrupted if i select baud rates higer than 115200 and even at 115200 i get corruption. At 38400 the data seems to be perfectly normal.
Thank you all for your help.
v1.ino (4.27 KB)
v2.ino (4.21 KB)