I tried to make it work but can't figure it out.
On the RP2040 datasheet stipulates that it is simply to set the GPIO has CLOCK GPIN, outinvert , and use one of the gpclk generators.
chapter 2.15.2.4 (page 185)
My RC network is 1M ohm and 1nF.
I'm using GPIO 20 and 21.
The scope toggle both Pin high and everything stay high after. no clock.
This is my code
Code: Select all
from machine import Pin,mem32
import time
IO_BANK0_BASE = 0x40014000
CLOCKS_BASE = 0x40008000
PADS_BANK0_BASE = 0x4001C000
CLK_GPOUT0_CTRL = 0
CLK_GPOUT1_CTRL = 0xc
CLK_GPOUT2_CTRL = 0x18
CLK_GPOUT3_CTRL = 0x24
atomicXOR = 0x1000
atomicRW = 0
atomicOR = 0x2000
atomicNOR = 0x3000
def setPinFuncSel(pin, funcsel, InvertOut=False):
pin_addr = 4 + pin *8
#reset funcsel
mem32[IO_BANK0_BASE | pin_addr | atomicNOR]= (0x1f | (0x3<<8))
#set funcsel
if InvertOut:
mem32[IO_BANK0_BASE | pin_addr | atomicOR]= (funcsel | (0x1<<8))
else:
mem32[IO_BANK0_BASE | pin_addr | atomicOR]= funcsel
def getPinFuncSel(pin):
pin_addr = 4 + pin *8
print("pin_addr :",hex(pin_addr))
return mem32[IO_BANK0_BASE | pin_addr]
def setPad(pin, value):
machine.mem32[PADS_BANK0_BASE | (4+ (4 * pin))] = value
def getPad(pin):
return machine.mem32[PADS_BANK0_BASE | (4+ (4 * pin))]
#pin20 to OUT , Pin21 to IN
pin20 = Pin(20,Pin.IN)
pin21 = Pin(21,Pin.OUT)
#change Pin20 and pin21 function
# do I need schmitt trigger?
setPad(20,0x40)
setPad(21,0x40)
setPinFuncSel(20,8)
setPinFuncSel(21,8,True)
# set relaxation oscillator
CLK_GPOUT_CTRL = CLK_GPOUT0_CTRL
#disable
mem32[CLOCKS_BASE|CLK_GPOUT_CTRL|atomicNOR] = 1<<11
#set clksrcpin0
mem32[CLOCKS_BASE|CLK_GPOUT_CTRL|atomicNOR] = (0xF << 5)
mem32[CLOCKS_BASE|CLK_GPOUT_CTRL|atomicOR] = (0x1 << 5)
#enable clocks
mem32[CLOCKS_BASE|CLK_GPOUT_CTRL|atomicOR] = 1<<11
while True:
time.sleep_ms(10)