MKRWiFi1010 and RS485

I’m doing some tests with MKRWiFi1010 to drive an RS485 line.
I used the library proposed here.

I noticed that this library blocks the processor for the whole time of the transmission.
To demonstrate this I have slightly modified the transmission example:

#include <ArduinoRS485.h>

#define TRIGGER 3  // use output D3 on connector to trigger oscilloscope
int counter = 0;

void setup() {

void loop() {
  digitalWrite(TRIGGER, HIGH);
  RS485.print("hello ");
  digitalWrite(TRIGGER, LOW);

I add an output to trigger the oscilloscope and see the time when the processor start to transmit and when return from the transmission. See attached image TEK00033.PNG, as you can see the processor is occupied for all the time of the transmission, and go back to loop (falling edge of yellow signal) only at the end of transmission.

Other library that transmit with UART use a different method: interrupt.
The problem of the RS485 Vs simple UART is that is needed a signal to enable transmission or enable receiving (half duplex channel)
The library I found for this board do not provide for the management of this signal. Right?
So I started modifying the libraries and managed to find a solution.
I had to edit the library: Uart and SERCOM.
Now, as you can see in the attachment TEK00034.png, the processor is busy only to transmit the first byte, then go back to the loop. The other byte are transmitted by interrupt.
When the first byte is about to be transmitted the line EN485, needed to put the external driver RS485 in transmission is put HIGH.
I had to manage one more interrupt: END OF TRANSMISSION, when this interrupt occurs the line EN485 is put LOW.

Now I would like to propose to those who manage the libraries to insert these changes, could be useful to everyone.

I had attached some notes about my changes.
Keep in mind that I used, as RS485 driver, a SN75176 with -RE and DE connected togheter, so I need only one line EN485, high during transmission, on the board MKR 485 Shield you need two lines, one for DE and on for -RE, so my notes need to be slightly changed.

Hope to be useful.



notes.txt (2.45 KB)