DigitalInOut performance

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
nelfata
 
Posts: 31
Joined: Wed May 07, 2014 9:44 am

DigitalInOut performance

Post by nelfata »

Hello,
I am trying to write to a list of GPIO pins (nrf52840) and that is impacting the performance as it takes about 500 to 1000usec to write 16 bits (it is bit by bit).
Is there a way to write to a whole port or byte (or a subset) in one go?

User avatar
mikeysklar
 
Posts: 13824
Joined: Mon Aug 01, 2016 8:10 pm

Re: DigitalInOut performance

Post by mikeysklar »

Are you doing this with Arduino or CircuitPython?

User avatar
nelfata
 
Posts: 31
Joined: Wed May 07, 2014 9:44 am

Re: DigitalInOut performance

Post by nelfata »

I am using CircuitPython, here is a sample:

Code: Select all

        # turn off all cols 
        self.gpio.col[0].value = 0
        self.gpio.col[1].value = 0
        self.gpio.col[2].value = 0
        self.gpio.col[3].value = 0
        # set rows
        self.gpio.row[0].value = (row >> 0 ) & 1
        self.gpio.row[1].value = (row >> 1 ) & 1
        self.gpio.row[2].value = (row >> 2 ) & 1
        self.gpio.row[3].value = (row >> 3 ) & 1
        self.gpio.row[4].value = (row >> 4 ) & 1
        self.gpio.row[5].value = (row >> 5 ) & 1
        self.gpio.row[6].value = (row >> 6 ) & 1
        self.gpio.row[7].value = (row >> 7 ) & 1
        # set cols
        self.gpio.col[0].value = (col     ) & 1
        self.gpio.col[1].value = (col >> 1) & 1
        self.gpio.col[2].value = (col >> 2) & 1
        self.gpio.col[3].value = (col >> 3) & 1

User avatar
nelfata
 
Posts: 31
Joined: Wed May 07, 2014 9:44 am

Re: DigitalInOut performance

Post by nelfata »

Just to be complete:

Code: Select all

        for i in range(len(Gpio.ROWS)):
            self.row[i] = digitalio.DigitalInOut(Gpio.ROWS[i])
            self.row[i].direction = digitalio.Direction.OUTPUT
        for i in range(0, 4):
            self.col[i] = digitalio.DigitalInOut(Gpio.COLS[i])
            self.col[i].direction = digitalio.Direction.OUTPUT

User avatar
mikeysklar
 
Posts: 13824
Joined: Mon Aug 01, 2016 8:10 pm

Re: DigitalInOut performance

Post by mikeysklar »

So you are not using the GPIO library, correct that is just your variable name for the row/col arrays?

Can you post the full code?

User avatar
nelfata
 
Posts: 31
Joined: Wed May 07, 2014 9:44 am

Re: DigitalInOut performance

Post by nelfata »

I am using the standard DigitalInOut library. I looked into the source code and the nrf port, it seems that there is only bit access API.

User avatar
mikeysklar
 
Posts: 13824
Joined: Mon Aug 01, 2016 8:10 pm

Re: DigitalInOut performance

Post by mikeysklar »

Looking through the readthedocs it does only look like bit access.

I remember the days where setting by PORT was the norm for Arduino code. It might be worth making a request in the CircuitPython github repo for PORT setting with Digital IO or a faster way to set multiple bits.

https://github.com/adafruit/circuitpython/issues

User avatar
nelfata
 
Posts: 31
Joined: Wed May 07, 2014 9:44 am

Re: DigitalInOut performance

Post by nelfata »

Thank you for your reply.
Sure I will file a request for this feature. By the way, I ended up writing a C module to improve the performance, and that worked great, but even the C API as provided by NRF (I think) does not have port access, only bit access to the GPIOs.

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”