bbcmicrobit / micropython

Port of MicroPython for the BBC micro:bit
https://microbit-micropython.readthedocs.io
Other
595 stars 287 forks source link

where is pin 16 data on version 2 microbits #773

Closed rhubarbdog closed 1 year ago

rhubarbdog commented 1 year ago

i have written a DHT11 thermometer class for version 2 microbits. it contains a dictionary of pin to bit id for example pin 0 uses bit 2. To create this dictionary I use a program in assembly to grab the memory at 0x5000510 and return it as an integer and print the binary with this program

def asm_read_digital():

    mov(r1, 0x50)       # r1=0x50                                               
    lsl(r1, r1, 16)     # r1=0x500000                                           
    add(r1, 0x05)       # r1=0x500005                                           
    lsl(r1, r1, 8)
    add(r1, 0x10)       # r1=0x50000510 -- this points to GPIO read digita      
    ldr(r0, [r1,0] )    # move memory@r1 to r2 

def binary(value):

    if value<0:
    print(1,end=""
        value=value+(1<<31)
    else:
        print(0,end="")

    check=1<<30
    while check>0:
        if value>=check:
            print(1, end="")
            value=value-check
    else:
            print(0, end="")

        check = check // 2

pin16.read_digital()
binary(asm_read_digital())

when i try to find the bit that corresponds to pin16 nothing. i can only conclude that the bit for pin16 is in another machine word because print(pin16.read_digital()) yeilds the correct result

microbit-carlos commented 1 year ago

The pinout can be found in: https://tech.microbit.org/hardware/edgeconnector/#pins-and-signals

P16 in the edge connector is P0.16 in V2, so it's not in a different port (pins starting with P1.xx).

microbit-carlos commented 1 year ago

My bad, there is an issue in the tech side and the V1 and V2 tables were reversed when I was looking at it:

So the edge connector pin16 is in fact in port 1, as it is the chip pin P1.02.

microbit-carlos commented 1 year ago

Btw, looking at the datasheet for the nRF52833 (the MCU in the micro:bit V2), the IN register for pin port P0 is at address 0x5000_0510 (base address 0x5000_0000 + 0x510 offset), and for port P1 should be 0x5000_0810 (base address 0x5000_0300 + 0x510 offset).

image

And as the https://tech.microbit.org/hardware/edgeconnector/#pins-and-signals table shows, there are a few pins on port P1.

I'll close this as resolved, but feel free to ask any other questions you might have, just make sure to open the issues specific to micro:bit V2 in https://github.com/microbit-foundation/micropython-microbit-v2/.

Thanks!