Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 4535

Beginners • Help with using PICO 2 PIO/FSM to input serial data

$
0
0
Hi,

First time using any RP device and my first post.

I'm unable to input an 8-bit serial data stream from a gauge through PIO/FSM. I hope the code below is self explanatory. Quite sure I'm not "getting" something correct after reading and reading the PICO/SDK/Data sheets docs and looking at countless examples.

Protocol is simple:
1 Drive a REQ pin low for at least 60ms to request data from the gauge
2 Gauge returns a clock stream of 52 clocks
3 Gauge begins to output data on the 28th clock, sample on low going edge of clock

I'm trying to input the first 8 bits of the serial stream which should be 0x55.

I'm expecting the program to report that there is a word in the rx_fifo after executing "push()" from to the but it always reports zero words. I'm not sure what I'm doing wrong. Help greatly appreciated.

Thank you

My MicroPython code:

Code:

[color=#40BF00]# Program to read data from a depth gauge upon request# 3 Pins required#REQ Output pin from PICO to request data from the gauge#CLK Input pin from the gauge#DATA Input pin to caputure the output data from the gauge## Each data bit from the gauge is "valid" on clock low so sample on CLK lowimport timefrom rp2 import StateMachine, PIO, asm_piofrom machine import Pin  @rp2.asm_pio(out_init=rp2.PIO.OUT_LOW)def mitclkin():     pull()# Pull data for REQ pulse timing        set(isr,0)# zero isr    set(x,31)    label("loop")#generate low going pulse    out(pins, 1)  [31]    jmp(x_dec, "loop")        set(x,27) # Wait for first clock high instance then count 27 clocks which is where the data begins    label("preamble")    wait(1, gpio, 15)    wait(0, gpio, 15)    jmp(x_dec, "preamble")    set(x,7)   # Clock in the next 8 data bits when clock is low    label("bitloop")    wait(1, gpio, 15)    wait(0, gpio, 15)    in_(pins,1)  # shift 1 bit of data from the GPIO pin to the ISR    jmp(x_dec, "bitloop")    push()         # Moves data in the ISR to the rx_fifo Pin(0, Pin.OUT)# REQ Output PinPin(15, Pin.IN)# CLK Input PinPin(14, Pin.IN)# DATA Input Pinsm0 = rp2.StateMachine(0, mitclkin, freq=16000, out_base=Pin(0), in_shiftdir=PIO.SHIFT_RIGHT, in_base=Pin(14))sm0.put(0x7ffffffe)# Value for REQ pulsetime.sleep(0.2)sm0.active(1) # start FSMtime.sleep(1) # Give FSM time to do the shiftingprint("Number of words in rx", sm0.rx_fifo())sm0.active(0)  # stop FSMprint("Number of words in rx", sm0.rx_fifo())[/color]
LA Capture of complete data req/output cycle:
Image

Zoom in put data stream:
Image
gauge zoom in.png

guauge zoom out.png

Statistics: Posted by longshooter — Fri Jan 24, 2025 10:33 pm — Replies 2 — Views 39



Viewing all articles
Browse latest Browse all 4535

Trending Articles