Shop OBEX P1 Docs P2 Docs Learn Events
Passing variables between Objects — Parallax Forums

Passing variables between Objects

Good day all on the forum.

I've got a problem swapping (on the fly) what pins are assigned for SDA and SCL in I2C PASM Driver v1.80d.spin written by Chris Gadd. The PCB has two I2C buses but I need to use only one instance of the I2C PASM driver (no more cogs!) !
So, instead of having to stop/start the cog with new values each time I have to change the BUS, I wanted to add the function to update the the variables SCL_mask and SDA_mask in the object from the main spin cog.
Firstly, is it possible and secondly ..... how?

Any help would be much appreciated

Rob

Comments

  • JonnyMacJonnyMac Posts: 8,927
    edited 2022-02-09 17:14

    It's possible, and the how is really up to you. Consider creating a dual-port driver so you can pass the SCL1/SDA1 and SCL2/SDA2 pins to the cog from the start() method. You'd need to add a method to tell the cog which set of pins to use. You'd also want a high-level method so you could double-check which pins are in use.

    Another question: Do you really need a PASM driver? If you can tolerate the speed of Spin with your I2C transactions, it would a bit easier to write a Spin-only driver. You might want to do that, anyway, to test the concept.

  • You could try my i2c driver (attached). It doesn't use additional cogs, but it's not blisteringly fast, since the I/O is done in Spin.

    -Phil

  • Thanks guys

    I appreciate your suggestions and will try all of them. I'm also trying to just modify Chris Gadd's object as it's common to all the products in the company but if needs be it'll be a different object.

    Thanks again

    Rob

  • Give this a shot, all methods are the same as before, but with a bus parameter tacked on to the end.

  • Thanks Chris

    I've only just checked the thread, for some reason I wasn't notified there was a post.

    I appreciate your help and the code looks great. I'll be checking it out as soon as I get back at work.

    Rob

Sign In or Register to comment.