faster spi transfers - cs control

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
User avatar
brave_ulysses
Posts: 3
Joined: Wed Apr 18, 2018 2:06 pm

faster spi transfers - cs control

Post by brave_ulysses » Wed Apr 18, 2018 2:26 pm

i'm using a hacked lobo micropython on a esp32-wroom module to send 16 bit data to a ti dac.

these are the changes to enable dma
spi_common.c:static uint8_t spi_dma_chan_enabled = 1;
spi_master_utils.c: spidev->dma_channel = 2;

after rebuild/loading, i get a faster-than-stock update rate, but the cs line control is taking a huge chunk of the total time. can this be adjusted?

i have an analyzer trace showing the behaviour - not sure how to attach it or to get the code block to work...

[code]
from machine import *
from math import *

mosi_pin=Pin(13,Pin.OUT)
miso_pin=Pin(12,Pin.IN)
sck_pin=Pin(14,Pin.OUT)
cs_pin=Pin(15,Pin.OUT)

baud=10000000

s=SPI(2,bits=16,baudrate=baud,mosi=mosi_pin,miso=miso_pin,sck=sck_pin,cs=cs_pin)
#s=SPI(2,bits=16,baudrate=baud)

num=400
bias=15.0
max=65535.0
divisor=1.0

b=list()
a=bytearray()
for i in range(num):
a=bytearray()
v=int(max/divisor*e**(-i/bias))
#print(v)
a.append(v>>8)
a.append(v&0x00ff)
b.append(a)

while True:
for i in b: g=s.write(i)

[/code]
Last edited by brave_ulysses on Fri Apr 20, 2018 2:41 am, edited 1 time in total.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: faster spi transfers - cs control

Post by pythoncoder » Thu Apr 19, 2018 6:44 am

Have you tried writing out the whole buffer?

Code: Select all

s.write(b)
Peter Hinch
Index to my micropython libraries.

User avatar
brave_ulysses
Posts: 3
Joined: Wed Apr 18, 2018 2:06 pm

Re: faster spi transfers - cs control

Post by brave_ulysses » Fri Apr 20, 2018 11:41 am

thanks for the suggestion, peter

no luck


[code]
>>> s.write(b)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: object with buffer protocol required
>>> b
[bytearray(b'\xff\xff'), bytearray(b'\xef|'), bytearray(b'\xe0\n'), bytearray(b'\xd1\x97')
[/code]

User avatar
brave_ulysses
Posts: 3
Joined: Wed Apr 18, 2018 2:06 pm

Re: faster spi transfers - cs control

Post by brave_ulysses » Fri Apr 20, 2018 11:48 am

hi peter,

writing the list did not work. if a bytearray object is written, the cs line behaviour is not what the dac requires (16 bit of data is latched on cs low->high transition)

thanks again,

clay

Post Reply