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:
# 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 low
import time
from rp2 import StateMachine, PIO, asm_pio
from 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 Pin
Pin(15, Pin.IN)# CLK Input Pin
Pin(14, Pin.IN)# DATA Input Pin
sm0 = 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 pulse
time.sleep(0.2)
sm0.active(1) # start FSM
time.sleep(1) # Give FSM time to do the shifting
print("Number of words in rx", sm0.rx_fifo())
sm0.active(0) # stop FSM
print("Number of words in rx", sm0.rx_fifo())
LA Capture of complete data req/output cycle:
![Image]()
Zoom in put data stream:
![Image]()
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:
# 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 low
import time
from rp2 import StateMachine, PIO, asm_pio
from 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 Pin
Pin(15, Pin.IN)# CLK Input Pin
Pin(14, Pin.IN)# DATA Input Pin
sm0 = 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 pulse
time.sleep(0.2)
sm0.active(1) # start FSM
time.sleep(1) # Give FSM time to do the shifting
print("Number of words in rx", sm0.rx_fifo())
sm0.active(0) # stop FSM
print("Number of words in rx", sm0.rx_fifo())
LA Capture of complete data req/output cycle:

Zoom in put data stream:

Statistics: Posted by longshooter — Fri Jan 24, 2025 10:33 pm