sauttefk / RS485HwSerial

Enhanced Arduino serial library with RS485 transmit enable control
GNU General Public License v3.0
6 stars 2 forks source link

bare metal access to port control to avoid digitalWrite overhead #2

Closed elsp1991 closed 3 years ago

elsp1991 commented 4 years ago

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

Erik84750 commented 3 years ago

Interesting. But no response after 4 months?

sauttefk commented 3 years ago

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

Erik84750 commented 3 years ago

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

sauttefk commented 3 years ago

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

elsp1991 commented 3 years ago

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

elsp1991 commented 3 years ago

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

sauttefk commented 3 years ago

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.