You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, I would like to modify the MicroPython code, but I have no idea how to modify it so that it runs like this.
First of all, after pressing KEY 1 and immediately releasing it, the following data is executed:
Vdd(1)
time.sleep(0.1)
cs(0)
spi_write_data_1()
spi_write_data_4()
spi_write_data_5()
spi_write_data_3()
spi_write_data_2()
cs(1)
time.sleep(0.008)
Then, if you press KEY2 at first and release it immediately, the following data will be executed:
cs(0)
spi_write_data_6()
cs(1)
Then, if you press KEY2 a second time and release it immediately, this data is executed: cs(0) spi_write_data_6() cs(1)
cs(0)
spi_write_data_7()
cs(1)
No. 2 and 3 can be repeated all the way through
Finally, if KEY1 is pressed and released immediately, this data is executed:
after No. 5 is executed, it returns to No. 1 and can be repeated indefinitely. 7.
the contents of try/except leads to infinite loop with growing memory usage #1 through Improve memory stats #5 are the first iteration. I want to fix it so that before and after KEY1 is pressed for the last time, no code is executed when KEY2 is pressed. In other words, data is output only when KEY1 is pressed first and KEY2 is pressed immediately after that.
I will upload the waveform diagram analyzed by Logic Analyzer. Please refer to it.
As shown in the picture,
Channels 0 represent Vdd.
Channel 7 represents KEY1 and channel 8 represents KEY2.
The two parts circled in white in the figure are loops (repetitions) after the code is executed.
The area circled in green is the signal that is generated outside of this cycle (repetition) when button 2 is pressed and immediately released.
I want to eliminate the signal generated from the area circled in green (the same as the area circled in blue)
Here are the codes that I wrote below:
from machine import Pin, SPI
import time
try:
while True:
if KEY1.value() == 0:
time.sleep_ms(10)
if KEY1.value() == 0:
reverseGPIO()
while KEY1.value() == 0:
time.sleep_ms(10)
if KEY2.value() == 0:
state = not state
if state:
cs(0)
spi_write_data_6()
cs(1)
else:
cs(0)
spi_write_data_7()
cs(1)
while KEY2.value() == 0:
time.sleep_ms(10)
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Hello, I would like to modify the MicroPython code, but I have no idea how to modify it so that it runs like this.
First of all, after pressing KEY 1 and immediately releasing it, the following data is executed:
Vdd(1)
time.sleep(0.1)
cs(0)
spi_write_data_1()
spi_write_data_4()
spi_write_data_5()
spi_write_data_3()
spi_write_data_2()
cs(1)
time.sleep(0.008)
Then, if you press KEY2 at first and release it immediately, the following data will be executed:
cs(0)
spi_write_data_6()
cs(1)
Then, if you press KEY2 a second time and release it immediately, this data is executed: cs(0) spi_write_data_6() cs(1)
cs(0)
spi_write_data_7()
cs(1)
No. 2 and 3 can be repeated all the way through
Finally, if KEY1 is pressed and released immediately, this data is executed:
cs(0)
spi_write_data_1()
spi_write_data_2()
spi_write_data_8()
spi_write_data_4()
spi_write_data_5()
cs(1)
Vdd.value(0)
time.sleep(0.1)
I will upload the waveform diagram analyzed by Logic Analyzer. Please refer to it.
As shown in the picture,
Here are the codes that I wrote below:
from machine import Pin, SPI
import time
KEY1 = Pin(0, Pin.IN, Pin.PULL_UP)
KEY2 = Pin(15, Pin.IN, Pin.PULL_UP)
Vdd = Pin(2, mode=Pin.OUT, value=0)
spi = SPI(0, baudrate=7500000, polarity=0, phase=0, bits=8, firstbit=SPI.MSB, sck=Pin(6), mosi=Pin(7))
cs = Pin(1, mode=Pin.OUT, value=0)
cs(1)
Vdd(0)
state = False
def spi_write_data_1():
spi.write(bytes([0x01]))
def spi_write_data_2():
spi.write(bytes([0x02]))
def spi_write_data_3():
spi.write(bytes([0x03]))
def spi_write_data_4():
spi.write(bytes([0x04]))
def spi_write_data_5():
spi.write(bytes([0x05]))
def spi_write_data_6():
spi.write(bytes([0x06]))
def spi_write_data_7():
spi.write(bytes([0x07]))
def spi_write_data_8():
spi.write(bytes([0x08]))
def reverseGPIO():
if Vdd.value() == 1:
cs(0)
spi_write_data_1()
spi_write_data_2()
spi_write_data_8()
spi_write_data_4()
spi_write_data_5()
cs(1)
time.sleep(0.008)
try:
while True:
if KEY1.value() == 0:
time.sleep_ms(10)
if KEY1.value() == 0:
reverseGPIO()
except:
pass
Beta Was this translation helpful? Give feedback.
All reactions