Shop OBEX P1 Docs P2 Docs Learn Events
Synchronous Shift In with External Clock - Is there a SIMPLE example? — Parallax Forums

Synchronous Shift In with External Clock - Is there a SIMPLE example?

Hi,
to interface P2 with a HM01B0 camera with 1bit interface, I need to shift in from a serial line with an external clock frequency PCLKO of 24MHz. P2 is running at 200MHz. Data has to be written to a buffer in HUB.

https://www.uctronics.com/download/Datasheet/HM01B0-MWA-image-sensor-datasheet.pdf
The whole procedure to receive a picture can be seen here as a PIO program for Pico, starting from line 148:
https://github.com/ArmDeveloperEcosystem/hm01b0-library-for-pico/blob/main/src/hm01b0.c

I don't think, that I have a chance to do this shifting bit-banging??? Right? Or do I? That would be something like:

wait for HSYNC LO
wait for HSYNC HI
Repeat for all pixels/4:
  Repeat 32 times:
    wait for CLK HI
    wait for CLK LO
    read DATAPIN
    shift DATA
  wrfast DATA to HUB 

So my question is, if there is a really SIMPLE example for the %11101 = synchronous serial receive smart mode?

Thanks very much for some hints!
Christof

Comments

  • AJLAJL Posts: 528

    Hi Christof,

    While I don’t pretend to be an expert on the Pico’s PIO, after reviewing the code and the data sheet it looks to me like you are setting up to read on the wrong clock edge.

    I don’t have time to analyze the PIO program fully at the moment, but I think it is possible to produce the simple example you are looking for.

  • JonnyMacJonnyMac Posts: 9,673

    Give this a try -- seems to work.

    In this demo I start up a background Spin2 cog and use smart pin sync_tx to simulate sending one 32-bit value (see screenshot from LA). used a set of jumpers on my Eval board to route signals.

    Note: the sync_rx function defaults to LSBFIRST so you may have to reverse your data bits before saving to the hub.

  • @JonnyMac said:
    Give this a try -- seems to work.

    In this demo I start up a background Spin2 cog and use smart pin sync_tx to simulate sending one 32-bit value (see screenshot from LA). used a set of jumpers on my Eval board to route signals.

    Note: the sync_rx function defaults to LSBFIRST so you may have to reverse your data bits before saving to the hub.

    Thank you very much!!!
    Christof

  • @AJL said:
    Hi Christof,

    While I don’t pretend to be an expert on the Pico’s PIO, after reviewing the code and the data sheet it looks to me like you are setting up to read on the wrong clock edge.

    That's odd: If I look at the diagram, I posted, it seems right to latch with falling edge. But the PIO code is different. Perhaps there is enough delay in the PIO?

  • smartpins do have some delay, i think 2 or 3 clock ticks. so that won't explain it
    polarity of the clock pin might be reversed
    or falling edge might be enabled
    see
    https://p2docs.github.io/pin.html#p-sync-rx

  • AJLAJL Posts: 528

    The image sensor data sheet shows the data transition happening while the clock is low, so reading should occur on the rising edge while the data is stable. I don’t know where you got the diagram that you posted.

Sign In or Register to comment.