Shop OBEX P1 Docs P2 Docs Learn Events
SPI that supports smart pins and SS — Parallax Forums

SPI that supports smart pins and SS

ke4pjwke4pjw Posts: 1,065
edited 2023-03-14 03:26 in PASM2/Spin2 (P2)

Are there any SPI receive drivers (slave) that support smartpins and SS? (That are Spin2/PASM)

Comments

  • evanhevanh Posts: 15,126
    edited 2023-03-14 06:32

    A slave software driver?

    I've been helping with such a feature in another topic but it's using C wrapper and really only a couple of example routines, not a self-contained driver object, so far - https://forums.parallax.com/discussion/173927/multimode-spi-implementation-spin2-pasm/p1

    We could work on making it a Spin2 object if you want.

  • Ah, OK. Yeah I couldn't find any off the shelf code. I was hoping to show off a P2 webcam Wednesday, but I don't think I have the free time to write an SPI slave. :)

  • evanhevanh Posts: 15,126

    Yeah, the SS (CS) timing is the tricky part for sure. Proper masters devices can and do have very small timing between SS edge and the data/clock starting. It's a non issue for slave hardware but software has to be super primed to handle that without also collecting spurious clocks prior to SS changing.

    It should be quite easy to adapt my code to just output a block of hubRAM as a circular buffer. I presume that's about all you'll need?

  • larryvclarryvc Posts: 42
    edited 2023-03-14 08:06

    I translated spi_shiftout_short.c into spin2. Not sure if it is completely correct, but here it is.

  • evanhevanh Posts: 15,126
    edited 2023-03-14 09:28

    Nice. I'm doing the object version now.

    EDIT: And found another bug left over from my foray with the 32-bit shifter. I'd left the smartpin misconfigured with wrong X value. :(

  • evanhevanh Posts: 15,126

    BTW: The implementation currently doesn't accept any SPI command at all. It just spews data the moment it's selected and clocked.

  • Thanks for everyone's response! What I need is to be able to have the P2 receive from a device that is providing clock, data and ss. Luckily, there is a 2nd async serial channel where control and command is happening. The P2 sends a series of commands over that channel and the actual data is sent back across via the SPI bus from the camera. The camera is a VC0706 based board that I got at RadioShack about 10 years ago.

  • evanhevanh Posts: 15,126
    edited 2023-03-14 21:51

    I have the spi_shift_in.c as well. I'll rework that tonight.
    Found https://cdn-shop.adafruit.com/datasheets/VC0706protocol.pdf and https://cdn-shop.adafruit.com/datasheets/VC0706+Digital+Video+Processor+Datasheet.pdf were top hits.

    The datasheet has the timings. Looks like it supports being the slave as well ... In cmode 1 ??? That's odd. I suspect it's gonna need some testing no matter what approach is used.

  • Well, I can't figure out how to set the camera into SPI slave mode, however, I did figure out how to send the image via the control channel at 115200bps. It takes 5 seconds, LOL.

  • Sometimes you go to war with the interface you got, not the one you want :)

  • evanhevanh Posts: 15,126
    edited 2023-03-19 10:37

    Here we go. Took me a while to get any testing done.

    Still not really any API. You can see in the tester() code how I just monitor the SS pin to trigger the data dump.

  • evanhevanh Posts: 15,126
    edited 2023-03-19 12:17

    And slave shift out version.

    I've included a screenshot showing it's response time to the simulated spurious clock before SS lowers. The shift-out (Orange trace) is changing from bit7 to bit6 of the first byte and then being reset back to bit7 when the software detects SS hasn't gone low yet. Bear in mind that this example is operating at 4 MHz sysclock.

    Green trace is SS from master.
    Blue trace is clock from master.
    Pink trace is data from master (MOSI). Uses same data sequence as the slave for comparison.

Sign In or Register to comment.