SAMD21 board..slow SPI?

Discussion and questions about boards that can run MicroPython but don't have a dedicated forum.
Target audience: Everyone interested in running MicroPython on other hardware.
Post Reply
winneymj13
Posts: 2
Joined: Sat Nov 10, 2018 2:19 am

SAMD21 board..slow SPI?

Post by winneymj13 » Sat Nov 10, 2018 2:44 am

Hi,
I have been writing a driver for the SH1106 Driver based OLED display and it is running extremely slow (about 2 frames per second). The SH1106 display uses paging which means I cannot write all the bytes via SPI in a single byte stream. I have set up the SPI seen below.
Although it could be my code above being slow, I have seen examples of code using machine.SPI to use the hardware SPI. I tried to import machine, but it does not appear to exist, and I see in the circuitpython documentation "No machine API on Atmel SAMD21 port."
Does this mean there is no Hardware SPI implemented?

[code]
# Create the SPI interface.
spi_bus = busio.SPI(board.SCK, board.MOSI)
spi_bus.try_lock()
spi_bus.configure(baudrate=24000000, polarity=0, phase=0)
spi_bus.unlock()
[/code]

Code to write the frame buffer in the driver is below:

def write_framebuf(self):
"""write to the frame buffer via SPI"""

for page in range(0, 7): # Pages
page_mult = (page << 7)
self.write_cmd(0xB0 + page) # set page address
self.write_cmd(0x02) # set lower column address
self.write_cmd(0x10) # set higher column address

self.dc_pin.value = 1
with self.spi_device as spi:
spi_write = spi.write
for pixel in range (0, self.width):
spi_write(bytearray([self.buffer[page_mult + pixel]]), end=1)

Any suggestions on how to speed up the method above is greatly appreciated.
Mark

tannewt
Posts: 51
Joined: Thu Aug 25, 2016 2:43 am

Re: SAMD21 board..slow SPI?

Post by tannewt » Mon Nov 12, 2018 9:28 pm

Hi Mark,
Please post on the Adafruit CircuitPython forum here: https://forums.adafruit.com/viewforum.php?f=60

That's where we support CircuitPython.
Thanks!
~Scott

Post Reply