💦 CREATE AND FUCK YOUR OWN AI CUMSLUT 🔥 TRY NOW ♥
Create AI Cumsluts 💦
August 31, 2021

SPI: The serial peripheral interface

I've gotten a few requests for videos about different communication protocols, so here's a video about a communication protocol! SPI is one of the simplest IC-to-IC protocols. I explain the protocol and show it in action between the 6502 computer and a temperature sensor.

As always, thanks for your support and let me know if you see any errors or confusing bits in the video.

Thanks,

-Ben

SPI: The serial peripheral interface (YouTube)

Comments (27)

P
Pascal Voet · October 10, 2023

A pity when you but the 6502 kit with the reference you can follow along on Youtube but with missing code it becomes a bit difficult

J
Jun-jie Liao · March 1, 2022

@Ben I could not find the source code of this program in https://eater.net/6502. Could you share it ? Thanks!

r
rehsd · September 24, 2021

Ben, will you be sharing your 6502 assembly code for the temperature calculations? I have my 6502 pulling raw data from the sensor and will next need to convert that raw data into something more friendly. :) Thanks!

K
Keith O · November 16, 2021

I'd love to see the code as well. I transcribed what I saw on the video, but that didn't include the conversions and fetching the calibration values. Fascinating project!

D
Darren Warner · September 5, 2021

I’ve just been working with SPI as it’s usually faster than I2C. It would helpful to spend an extra minute going into the 4 modes of SPI (it seems most modern devices support 00, at least). I still have to wrap my head around this when looking at traces. I also find my scope doesn’t always decode properly even though the device is fine - especially with noisy signals.

A
Augusto Righetto · September 5, 2021

You've got the best balance between teaching a hard topic using "simple" tools (that oscilloscope is a very nice toy). Thanks for another amazing video. During the video you've mention that a shift register could be used. Can you expand a little bit more on that?

V
Vinay G · September 4, 2021

Thank you for the excellent video.

G
George Smart M1GEO · September 3, 2021

Nice work. Just a note to add that you often see the chip select (/CS) referred to as slave select (/SS). Keep up the awesome work!

J
Jakob Dannesboe · September 2, 2021

You are amazing

R
Ryan Helinski · September 2, 2021

I am sure you will add some final comments about how one could make a third version using a shift register. I know of one YouTuber who makes shift register modules on breadboards.

S
Sean · September 1, 2021

The volume seems a bit lower than other videos.

T
Tim Walkowski · September 1, 2021

I may have missed it, but I didn't see how you came up with the bit positions for the MISO, MOSI, etc. in your code example. I am referring to DDRA for PORT A at Reset: 16:20. Specifically, why is MISO at bit 6? is it simply because that's how you connected the pins to the 6522 or is there another reason?

B
Ben Eater · September 2, 2021

I didn't explain it, but MISO is at bit 6 because in the spi_transceive subroutine, I use the "bit" instruction which (in relevant part) sets the overflow flag based on the contents of bit 6 of the accumulator. I then use a "bvc" (branch if overflow clear) instruction to control whether we shift a 1 or a 0 into the receive buffer. Additionally, putting SCK is at bit 0 lets me do "inc PORTA" and "dec PORTA" to toggle the clock line. It didn't matter where I put CS and MOSI.

O
Oren Hazi · September 1, 2021

Would adding a comment about CIPO/COPI be more likely to result in an angry internet mob than not mentioning it at all? Maybe I spend too much time on electronics twitter, but it seems like a catch 22. For what it's worth, I already have two dev boards with CIPO/COPI labeling, and both SparkFun and Adafruit seem to be on board. Yay more fragmentation.

J
Jeremy · September 4, 2021

It seems like it would be good to address the topic even if a few react negatively to the new terms. I have also seen the terms "Main" used instead of "Master" and "Secondary" used instead of "Slave" to keep acronyms as-is.

P
Pim van Pelt · September 1, 2021

LGTM! A small nit - at 28:56 you mention an octet as "between each set of 8 bytes".

B
Ben Eater · September 2, 2021

Ugh.. For some reason I can never get that right. Bit. Byte. You know what I mean :)

M
Mark Day · September 1, 2021

Around 25:14, I was a bit confused that you had to send a register address again. How did it know that byte was a register address, and not data to be stored (with auto increment of the address, like reading the sensor data later). Looking at the data sheet, it says multi-byte writes have to alternate address and data, while multi-byte reads auto-increment the address. I don't know if this is worth pointing out in the video or in the description. Minor nit: when highlight code in your editor (for example at 25:57) it's nearly impossible to read the highlighted text. You let the code stay on screen, so we can read it after it gets unhighlighted. Also: that must be a 65C02 (since you're using STZ, TSB, TRB instructions). Brings back memories. :-)

R
Ryan Helinski · August 31, 2021

Excellent! SPI and I2C are still in heavy use in electronics. I have also been wondering how a PS/2 mouse works and why the whole PC crashes when you unplug a PS/2 keyboard.

E
Evan Thayer · August 31, 2021

Super interesting topic, well explained as usual. I’d love to recreate some of these experiments on my own bench, but I’ve got an inexpensive siglent SDS1202X-E scope that doesn’t decode. What’s the best way to analyze circuits like this outside of a major scope upgrade?

r
rehsd · September 1, 2021

While it's $200 USD, the Digilent Digital Discovery logic analyzer offers protocol analysis. It supports SPI, I²C, UART, CAN, and AVR. https://digilent.com/shop/digital-discovery-portable-usb-logic-analyzer-and-digital-pattern-generator/ I'll be using my Digilent for SPI analysis as I get into this. My Siglent scope also has SPI decode built into it, so I'll try that out, too. Lots for me to learn... :)

r
rehsd · August 31, 2021

Awesome! Perfect timing, as I am just digging into SPI now. :)

r
rhc · August 31, 2021

Very cool! At around 19 min, it might be slightly easier to understand if you have the program and the logic level drawing on the screen at the same time, side-by-side. It's also a shame that we don't get the temperature converted into Celsius for completeness, even if you don't linger on the conversion code -- but I guess looking at the C code, you don't really want to bang that out in assembly.

B
Ben Eater · September 2, 2021

Good feedback on cutting back and forth. In hindsight it also would have been much easier to edit if they were both on the screen at the same time. I'll see about changing it. And I might be able to get the temperature conversion working before I post the video, but no promises. I'm no assembly expert, so it's definitely a pain. Good to know that if I do get it working, it's worth throwing in even without much explanation.

B
Brady Burnsides · August 31, 2021

Exciting! I'd love to see you do more with this. An SD card reader would be great. That's something I want to implement in my homebrew for mass storage.

E
Elekes Karoly · August 31, 2021

Thanks Ben! Always exited when you bring something new to the 6502 computer.

A
Auctoris · August 31, 2021

Ooh. Exciting. This is something I’ve been hoping for! Will take a look when I get chance later on! Thanks Ben!