^5 SMBus with the R-Pi

A project log for RPUpi - a shield for tool-chain at network edge

Connects a Raspberry Pi to a serial multi-drop bus.

ronald.sutherlandronald.sutherland 06/17/2019 at 18:200 Comments

First: on ^4 I should have connected the SPI nSS to R-Pi's CE00 pin (oops).

I have been working on the Remote FW for this board, splitting the hulk into smaller parts so they can fit in my brain. Also adding I2C commands that control the bus manager, and trying out the SMBus interface... and then it happened. I did not have a clue what was going on, and it has taken far to long to understand. In short, the R-Pi zero has a problem with clock-stretching.

After finally understanding the problem and getting past the sinking feeling, I had an idea.

Interleaving between two buffers (A and B) within the twi ISR used by SMBus interface. And without much testing yet, it seems to have done the trick.

The buffer used by the ISR is swapped after passing it to the user (e.g., with receive callback function). The user receive function runs within the ISR context, but now it can be concise (e.g., save the pointer and byte count). Then all the work can be done outside of ISR context since the buffer is no longer in the risk of being changed, at least until a subsequent receive event when it will be swapped back into service.

The quick receive event seems to be tolerated by the R-Pi's clock, but more testing is needed. The handle_smbus function is run in the main loop if there are SMBus bytes available.