sauttefk / RS485HwSerial

Enhanced Arduino serial library with RS485 transmit enable control

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

bare metal access to port control to avoid digitalWrite overhead

elsp1991 opened this issue · comments

Hello Frank,
I am implementing an RS485 communication in an atmega328p base board. Since am I need to run in 1kHz and perform a significant amount of math. I was benchmarking every function of my code. So I figured that digitalWrite function is actually quite slow cause of the checks it performs. So I switched my DE_pin and all my slave select pins for SPI to direct port control and I saw significant improvements.
Will you be interested to merge such a pull request? basically instead of one pin you keep a port pointer and a bit number. So its is going to be minimum changes

digitalWrite benchmarking

commented

Interesting. But no response after 4 months?

actually it is 16 months, but I never received a pull request

commented

Thanks for you reply Frank. I am not so familiar here: when there is an issue, it should be posted under "Pull request"?

@Erik84750 there is no issue, but an improvement @elsp1991 suggested.
@elsp1991 should make a pull request with his code changes.

Hello guys the "@" actually worked to ping me :P.

I will have to dig it out from where I have the code and do a pull request as per your suggestion

The problem I see in such a change is that arduino eco-system does not provide a performance version of digitalWrite(). So for this reason we will have to do it architecture specific that kind of defeats the purpose of having a generic architecture agnostic library. I will have a look how I can do it and come back with PR

So I think, we should leave this as is.
The transmit enable pin has not to be switched that often, so the wasted cycles are not so much.
Also I no more use my own library as I have changed my hardware designs to a MAX13487 RS485 transceiver which saves all the hassle and one pin for enabling the transmitter.