Hello Pythoncoder, thanks for the hints. I tried to integrate that fpr my code, but something is strange. I have a piece of code that works:
Code: Select all
import pyb, stm
from uctypes import addressof
@micropython.viper
def tft_cmd_data(self, cmd: int, data: ptr8, size: int):
gpioa = ptr8(stm.GPIOA + stm.GPIO_ODR)
gpiob = ptr16(stm.GPIOB + stm.GPIO_BSRRL)
gpioa[0] = cmd # set data on port A
gpiob[1] = D_C | WR # set C/D and WR low
gpiob[0] = D_C | WR # set C/D and WR high
for i in range(size):
gpioa[0] = data[i] # set data on port A
gpiob[1] = WR # set WR low. C/D still high
gpiob[0] = WR # set WR high again
That piece works, I see four write pulses, and the right data. In an attempt to omit the third argument of the function, I tried this
Code: Select all
import pyb, stm
from uctypes import addressof
@micropython.viper
def tft_cmd_data2(self, cmd: int, data):
gpioa = ptr8(stm.GPIOA + stm.GPIO_ODR)
gpiob = ptr16(stm.GPIOB + stm.GPIO_BSRRL)
gpioa[0] = cmd # set data on port A
gpiob[1] = D_C | WR # set C/D and WR low
gpiob[0] = D_C | WR # set C/D and WR high
data_ptr = ptr8(addressof(data))
ld = int(len(data))
print(len(data), ld)
for i in range(ld):
gpioa[0] = data_ptr[i] # set data on port A
gpiob[1] = WR # set WR low. C/D still high
gpiob[0] = WR # set WR high again
The size of data is three, and that is what was printed, but the loop seems not to be executed. I see a single write pulse only.
Do you have any clue what's happening? Not that this is important, since the first variant works. But calls to the second variant would be more robust (bytes constant, not length to be supplied = one error-option less).