C-Block Components for SPI, I2C? Baby Steps

[ Sorry in advance for the long read ]

I’m thinking that having some basic SPI/I2C C-Block components might be handy. Stick some custom code in, set some configuration stuff, and – tada – you could drive SPI slave devices or simulate responses to SPI master devices. (All of that, of course, presumes that there’s a proper component from a vendor to “talk to.”)

Anyway, it’s more complicated than it sounds. I backed up to simple serial buffer components as a first step. The first, a “proof of concept” serial output component (SerialOut), is available on my Github repo here.

If you think this is worthwhile, feel free to encourage me. (As Dave Plummer says, “I’m mostly in this for the subs and likes.”)


Sample output for 0x88, 0x11, 0x55, 0xaa, 0xde, 0xad, 0xbe, 0xef, 0x00:



Looking forward to an example on how to use it in a VERY SIMPLE circuit. Maybe it could be paired up with a simple logic gate (buffer/inverter). Don’t suppose it will be REALLY useful until we can use this with a microcontroller in QSPICE.

Good work Rob!
Changing the SPI frequency was quite easy, because it is already defined as parameter.
The SPI works well. I added the supply as VSUP parameter, so it can be used on any logic voltage level. That was easy, I didn’t need to recompile the DLL.
My wish for the next revision is a FILE parameter, so the data can be defined in an external file and you don’t need to recompile the DLL for changed data content.
By retiming the VSEN I checked, if the SPI works also for 16 bit. That doesn’t work, you just get the data byte and then 8 bit times a zero.

Hi, nuwix. Thanks for the feedback.

The component was a proof of concept and hard-coded for 8 bits. I’m working on a proper generic SPI master/slave implementation. Hopefully it will be ready in a day or two – if I don’t keep thinking of “better ways” to implement them. Keep an eye on this thread for updates.


OK, I promised SPI master & slave components but it has taken longer than anticipated. Here is a preview of unfinished components on the Dev branch: https://github.com/robdunn4/QSpice/tree/Dev/SPI_Temp.

The code/schematics at this point implement a master device which drives two slave devices: An ADC to sample voltage and a DAC to output that voltage. The top level schematic:

The I/O:

Much left to do – code cleanup and refactoring, documentation, etc. – but I didn’t want to leave interested parties hanging. Let me know if the link doesn’t work or if I failed to upload needed bits.



The QSpice SPI master/slave components are now hopefully much improved. (I’m now calling this stuff “SpiIO” because, well, we have to call it something.)

The new documentation, C-Block sources, schematics, and demo files are now available on the main branch of my GitHub QSpice repo in the SpiIO folder. The high-level developer overview PDF is here.

Let me know what you think, questions, problems, etc.



I recently shared a voltage-controlled potentiometer symbol/sub-circuit (in the Miscellany folder here and thought it might be interesting to add a SPI slave pot to the SpiIO component/framework.

It was shockingly easy and required no changes to existing C-Block DLL code.

While we now have a SPI pot slave device, the important point is that the SpiIO stuff is useful as an easy-to-use framework for easily implementing SPI devices.

Anyway, the SPI potentiometer component is available on my GitHub repo in the SpiIO folder.