Shop OBEX P1 Docs P2 Docs Learn Events
We have light!! P1 I2C driver questions and PASM — Parallax Forums

We have light!! P1 I2C driver questions and PASM

I've been working on my own P1 I2C driver based on JonnyMac's I2C demos for P2. I'm attempting to drive14 segment LEDs using a HT16K33 in an adafruit feather. And finally tonight, we have light! lol

In P2, JonnyMac called a method which included PASM code (see below). Is there a way to do something equivalent in P1 where I can call different PASM subroutines? Based on the command or data I'm writing with the HT16K33, I need flexibility to write a different number of bytes.

Can I have multiple DAT structures with a different ORG followed by a number? I've only ever seen P1 code with 1 DAT PASM code. I've attached my P1 driver.

Thanks,

JonnyMac's driver for I2C write in P2

pub write(i2cbyte) : ackbit | scl, sda, tix, bits

'' Write byte to I2C bus
'' -- leaves SCL low

  longmove(@scl, @sclpin, 3)                                    ' copy pins & timing

  org
                shl       i2cbyte, #24                          ' align i2cbyte.[7] to i2cbyte.[31]

.wr_byte        mov       bits, #8                              ' output 8 bits, msbfirst
.wb0            shl       i2cbyte, #1                   wc      ' msb --> c
                drvc      sda                                   ' c -- sda
                waitx     tix                                   ' let sda settle
                drvh      scl                                   ' scl high
                testp     scl                           wc      ' check for clock stretch
    if_nc       jmp       #$-2
                waitx     tix
                waitx     tix
                drvl      scl                                   ' scl low
                waitx     tix
                djnz      bits, #.wb0

.get_ack        drvh      sda                                   ' pull-up sda
                waitx     tix
                drvh      scl                                   ' scl high
                testp     scl                           wc      ' check for clock stretch
    if_nc       jmp       #$-2
                waitx     tix
                testp     sda                           wc      ' sample sda (ack bit)
                muxc      ackbit, #1                            ' update return value
                waitx     tix
                drvl      scl                                   ' scl low
                waitx     tix
                waitx     tix
  end

HT16K33 has different length for a COMMAND and READ/WRITE.

Comments

  • Would it help to start with the JonnyMac's P1 versions?

    See attached (from GitHub).

  • LudisLudis Posts: 69
    edited 2021-03-02 02:26

    yes very much. Thank you.

    I started on the path of SPIN code. Then decided to go PASM because I had a brain fart looking at the spec and was thinking SPIN was too slow. I even remember JonnyMac saying that SPIN is NOT too slow in the live forum, so I should have thought about it more at the time. While writing the PASM code I realized that the HT16K33 clock speed is a maximum of 400 kHz and not a minimum. So I figured SPIN might be the answer to my PASM road block. I will try that next! Onward!

  • I2C uses a clock, hence can run at any speed -- up to a point. I have used my I2C Spin code in numerous commercial products. I wrote the "fast" code to expedite reloading the EEPROM from SD card for the laser tag product.

    I've attached my Spin1 code for that display in case you want to have a look.

  • thanks, Jon! yes I will definitely review your files as I get stuck and as a comparison to what I come up with. Working on the SPIN driver now.

    I see what you mean about using the clock as the reference and the speed can vary. Interesting!

    On the P1, it is also interesting how to drive the pins for the SDA/SCL with the pull up resisters (Input direction to pull the line high or Output/Low to pull the line low. I'm glad to see you are doing the same thing. All good stuff!

    Moving forward...

Sign In or Register to comment.