-
Notifications
You must be signed in to change notification settings - Fork 249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Questions about I2C slave #379
Comments
The Circle I2C slave driver is simple polling driver. The I2C slave peripheral in the Raspberry Pi supports interrupts, but this is not used here. When more bytes are requested than are actually sent by the master, the received bytes are returned immediately in the buffer with the byte count returned by |
Thanks Rene, that's useful info. Hopefully polling will be enough for now. |
Did this work for you or do we need an interrupt driven I2C slave? |
Hey Rene, I haven't had a chance to look at it properly yet (I've been stuck trying to get a DPI LCD display panel working). If it's not too hard to implement I'd almost certainly use it. My main concern about polling it is I'll be running an OpenGL render loop too which I think throttles the loop to the frame rate - not sure if that'd be fast enough for polling i2c. Brad |
Hi Brad, OK, let me know, when polling I2C is not fast enough. Rene |
Hi Rene, I'm finally getting around to integrating this with my OpenGL render loop and have hit a blocking issue - it seems CI2CSlave::Read() blocks if nothing has been received. I've tried just reading a single byte and it doesn't return until the first byte is received. How do I poll and just read what's available and return immediately if there's nothing? Brad |
fwiw, not sure if this correct but I got this working by replacing the first while loop in CI2CSlave::Read with this:
|
Hi Brad, yes, you are right, it blocks and there is no way out with the current implementation. Please give me two days for an update, which is also in sync with sample/16-i2cping. Rene |
Thanks Rene. No rush as I can work with my temp hack until you get it sorted. |
* Comment for Doxygen * Add note on General Call Address 0 (#383)
I added a timeout parameter to |
Awesome, thanks Rene. I'll check it out but might be a few days... I've got some other high priority work that's popped up but hope to get back to this soon. |
Thanks Brad for info. No problem. |
Hi Rene, I'm back working on my bare metal Pi project again and I'm having issues with I2C - receiving corrupted packets and occasional lock ups. Some questions:
Anything that can be done to make this more reliable would be much appreciated (at the end of the day I need something rock solid). Brad |
Hi Brad, it should be possible to extend the I2C slave receiver with an IRQ mode. The hardware spec. (pg. 160) mentions a RXINTR, but because I never used it so far, it requires some experimenting. There is also an overrun error interrupt (OEINTR), which could be monitored. There is a BRK (break current operation) bit in the Control register, which according to the spec. stops the current operation and clears the FIFOs. I'm not fully aware of your use case. Can you please give me more info about how you want to use the I2C slave, so that I can prepare a test program and define the class interface. Thanks, Rene |
Emailed you. |
For reference, here's a good description of i2c lockup, prevention and recovery: |
So that it is not lost, attached there is a slightly modified sample/16-i2cping/slave, which contains a I2C slave driver in the files i2cslaveirq.*. The I2C receiver in this driver is IRQ driven and should not "loose" bytes any more. The receiver is always on after |
While porting the I2C master driver for the Raspberry Pi 5, I discovered this. How it seems, the I2C bus recover must be done by the I2C master, which is implemented here for Linux. The slave cannot do this. |
Thanks Rene.. Unfortunately I've had to put my project on hold for the moment due to other commitments but this will be useful when I get back to it. |
No problem Brad. Understood. |
Hello, |
Thanks @sebastienNEC! I think, @toptensoftware needs an I2C slave on the Raspberry Pi and runs the master on an other type of board. But perhaps your work can be used to add an IRQ-driven I2C master to Circle. What do you think has to be added/changed on your driver to prepare it for that purpose? |
Not much needs changed I would think, just a bit of sanity-check on your side :-)
Also, I might have been a bit lax with the checks on the Status register in CI2CMasterIRQ::InterruptHandler(). I am only checking the 3 more important indicator bits but one should probably have a look at other status bits. |
Oh, one important extra limitation: due to the asynchronous nature, it's possible/realistic that users could make a second call to CI2CMasterIRQ::StartWriteRead() while a first transaction is not done yet. For example when using this class for two different I2C slaves. |
I can of course do these modifications if you'd like, or feel free to do them on your side as part of checking the code if you prefer :) |
It would be a great help, if you would do the necessary modifications. It's also easier for you to do it, because it's your driver and you are familiar with it. So yes, please do! |
Will do ! One question: the driver shares quite a bit of code with the regular CI2CMaster class. Is it ok to inherit from that class, in order not to duplicate code ? What's the general policy in circle ? |
Thanks! I would think OOP here: If the IRQ-driven I2C master "is a" I2C-polling-master (which is the class |
Ok I've implemented the changes above, I think it's cleaner now. |
Thank you! This looks good. I will test it this evening. |
I wrote a simple test program using your driver, which sends some bytes to a I2C device and receives some bytes then. I tested it with a BMP180 air pressure sensor and it works well. I will add your driver soon to the develop branch. Thank you for this contribution! |
Nice, hope it will be useful to somebody else ! |
I think so. It's merged to develop. |
Where can I find some more information about how i2c slave works? For example:
The text was updated successfully, but these errors were encountered: