Parallel Output of a Byte

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
Post Reply
John Hasler
Posts: 2
Joined: Wed Apr 08, 2020 3:35 pm

Parallel Output of a Byte

Post by John Hasler » Wed Apr 08, 2020 4:06 pm

I need to write a byte to a GPIO port in a single operation. I can use any set of pins and any port. I've searched the documentation and can see no way to do it other than eight seperate pin() operations or using assembler or C.

User avatar
Roberthh
Posts: 1961
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Parallel Output of a Byte

Post by Roberthh » Wed Apr 08, 2020 6:23 pm

You can use viper code to write directly to a port register, and you can use uctypes.bytearray_at(addr, size) to read & write to a phsical memory location. For viper code, you find a documentation here: http://docs.micropython.org/en/latest/r ... de-emitter
I used that a lot in a SSD1963 driver for direct 8 bit wide port access. The sample driver is here:https://github.com/robert-hh/SSD1963-TF ... /TFT_io.py

John Hasler
Posts: 2
Joined: Wed Apr 08, 2020 3:35 pm

Re: Parallel Output of a Byte

Post by John Hasler » Wed Apr 08, 2020 6:41 pm

Viper was the hint I needed. Thank you. Don't know why that was so hard to find.

User avatar
jimmo
Posts: 1633
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: Parallel Output of a Byte

Post by jimmo » Thu Apr 09, 2020 12:33 am

John Hasler wrote:
Wed Apr 08, 2020 4:06 pm
I need to write a byte to a GPIO port in a single operation.
You can do this without Viper

On the STM32 port there's a 'stm' module which gives you constants for most registers. Combined with machine.mem32 you can pretty much do anything.

Code: Select all

import machine
import stm

machine.mem32[stm.GPIOA] = ...

User avatar
Roberthh
Posts: 1961
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Parallel Output of a Byte

Post by Roberthh » Thu Apr 09, 2020 5:15 am

machine.memxx calls are slow. If you need fast actions, viper works better.

Post Reply