I would just like to point out how god damn clean and user friendly the datasheet of the BME280 is. Timing diagrams annotated with the bit-indices, comprehensible english, a clickable table of contents, using vector graphics for every graphical element. I wish every datasheet was this well made.
I used this little sensor (via I2C though) in my projects, it is quite reliable and precise. I agree, the manual is just beautiful from the software developer's point of view (hopefully, from electronic engineer's one too). They describe whatever you need and you want to know about this sensor in details. A perfect example how it should be done properly.
I am working with the AD7771 ADC from analog devices, using the SPI interface. I wish the datasheet was 10% as friendly as the BME280 datasheet is.... Not only regarding the SPI protocol but explaining properly what certain registers do.
@@sashimanu How??? The average current-consumption while measuring at 1Hz is less than 4uA. Max consumption is ~1mA, so it should be literally impossible to heat this thing up if used right. It is a temperature sensor too after all, it isn't allowed to heat itself up by DESIGN. You either got a fake, your wiring is wrong or your GPIOs are set up wrong. Are you disconnecting VDD, but keep the SPI/CS lines powered? (could cause backfeeding through the ESD-diodes) Are you using it at above 3.6 volt?
@@stoatrepublic Very COoL.. :O) "The Norfolk dialect, also known as Broad Norfolk, is a dialect spoken in the county of Norfolk in England which sits within the broader East Anglian English. While less widely and purely spoken than in its heyday, the dialect and vocabulary can still be heard across the county, with some variations?. Wikipedia
@J Hemphill Very COoL.. :O) "You're not wrong" --Sweet Brown -- "Ain't Nobody Got time For That" -- "I got bronchitis ain’t nobody got time for that. Ain’t nobody got time for that Ain’t nobody got time for that Ain’t nobody got time, ain’t nobody got time Ain’t nobody got time for that Well, I woke up to get me a cold pop Then I thought somebody was BBQing (BBQing) (BBQing) I said, “Oh, lord Jesus it’s a fire!” Then I ran out, I didn’t grab no shoes or nothing Jesus I ran for my life Ain’t nobody got time for that Ain’t nobody got time for that Ain’t nobody got time, ain’t nobody got time Ain’t nobody got time for that Ain’t nobody got time for that Ain’t nobody got time for that Ain’t nobody got time, ain’t nobody got time Ain’t nobody got time for that I said, “Oh, lord Jesus it’s a fire.” I said, “Oh, lord Jesus it’s a fire.” I said, “Oh, lord Jesus it’s a fire.” Jesus, Jesus, Jesus, it’s a fire. Ain’t nobody got time for that Ain’t nobody got time for that Ain’t nobody got time, ain’t nobody got time Ain’t nobody got time for that Ain’t nobody got time for that Ain’t nobody got time, ain’t nobody got time Ain’t nobody got time for that" Cheers JH (good one BTW, which is more than I can say for them' lyrics:)
I'm an electrical engineering student and I've gotta say you've single-handedly reminded me why I chose my major and revitalized my love for electronics.
When I was at school I had no interest in grades or classes whatsoever. It was only until my friend taught me how to solder which was when my interest took off
I am 80, but your explanation was clear, concise and intellectually satisfying. Congatulations on a superb piece of teaching that I will remember as a classic explanation.
It's rare to see a Ben Eater video where I am very familiar with what he is showcasing. I've written multiple drivers using different HALs for the shown sensor.
Hi. In your HAL were this SPI sensor's temp/pressure registers memory mapped or IO mapped somehow (possibly via an SPI controller) that you could simple read/write to obtain the temp/pressure data? I'm trying to understand how a 'modern' processor on a motherboard talks to SPI chip (like SPI flash memory containing the BIOS). Surely you didn't 'bit bang' like Ben did here inside your driver code?
The biggest plus with Ben Eater's videos is that he has given free access to the murkiest and deeply obfuscated engineering procedures and workflows for the common people. Even if we don't fully grasp them, we know that these notoriously complex workings happening right before our eyes can be tamed with time and effort. No other contributor I have experienced has gone this far, this easily.
brings back EE undergrad memories. the toughest ones, microcontroller lab, assembly, LDA-ing and STA-ing bit by bit just like that. Protocols I forgot, addresses I still remember, funny failure stories... 🤓😅
I used SPI in my final project for university. We had a microcontroller controlling a series of LED displays. The controller sent the display a byte of data using SPI which the display read as an ASCII character and displayed. The interesting thing is we had the display setup so that whenever they received data they would output their old data and then we daisy-chained displays so each one sent the last character it received onto the next. That way we could control a whole bunch of LED displays with just the one chip select line. The end display would wrap around back to the controller. We used that to allow the controller to figure out how many displays were connected. it would send out zeros for a while to clear out whatever data was in the displays and then send all ones and count how many sends it took to get the ones back. However sends it took was the number of displays attached. While implementing that counting logic I made a mistake in my looping bounds. The counter variable was only a single byte and I told it to loop until that byte was 256 which of course never happened. Made a very interesting strobe effect though. As the displays were constantly being interrupted to transmit and receive data.
Just remember this is exactly how engineering really goes. You just follow the datasheet it works the first time perfectly, and you feel rewarded at the end.
@@harryjohnson615 Actually sometimes it does and when it does it feels so good. I remeber once we had four day weekend (Easter) to set up a new facility. New system & computers, user accounts etc. We got it running on monday morning and the first test was success. We had 5 men team where I was the one controlling the workflow and checking on the server side that each computer on the network was responding properly. Last thing was to fire the script that made those user accounts and check that they were set up correctly. They were and we were off to celebrate. Had private sauna with food and drink courtesy by the company management. Actually I think I slept four hours during those four days. We postponed the celebration to tuesday and got both tuesday and wednesday off. We also got mighty hefty one time compensation for that work. Felt pretty good.
Ben you are an absolute institution. I'm a chemist, and closet electrical engineer / low level software engineer and your content is so precisely the right level for my brain it's ridiculous. I mean, I'm a complete amateur and such but your pace, tone and rigour with which you go through the detail is sublime. Hats off to you sir. Not that I wear a hat
Literally the only firmware programming I ever did was to write an I2C implementation that could control the LEDs and read the temperature sensor on a network (interconnect) card. We had the prototype cards without the ASIC on them and I ended up bit-banging a parallel port on a desktop PC to implement a (very slow) I2C. The company (Quadrics) went bust a few months later and I never actually got to see my code running from the ASIC, and that was the end of my glorious firmware programming career.
@@Vanders456 I'm working as intern with designation as embedded firmware developer. I have heard the pay isn't that good. Why did you shifted from firmware to sre and how did you do that?
We might also mention that devices vary about whether MSb or LSb is sent/received first. If all 8 outputs of the decoder is used, you will also need to devote one more pin to selecting/deselecting the decoder; otherwise, one of the eight devices will always be selected. If output 7 is not used, then writing 111 to the decoder will deselect all used devices, however.
@@modmen. The chip knows the byte is complete only after it is de-selected... You could still select another chip without transferring any data, but some chips don't respond well to that.
the production value that goes into these videos is pretty insane tbh, it must take a shitton of effort to line up the voice overs, the edits and the script to work how you're doing it. It's all very minimal but ohhhhh so precise and delicate, which kinda fits who you are as a figure on youtube. Kudos to you, Ben, for the work you're putting into the production of these videos
I learned 100 times more during his computer build THAN I did getting my BS in Electrical Engineering Technology. His free video explained why in just a few minutes where school just said what. Had to edit my reply because Mr. English Professor called out a misspelling. My misspellings are proportional to how much I've had to drink....
I had trouble with an SPI chip once.... I never considered that I was maybe using the wrong clock mode.... thanks for the tip! I always do SPI on microcontrollers with a built in SPI port.... very interesting seeing you "go old school" and implementing the interface with bit-banging.... showing us how it REALLY WORKS.
I don't know why, this seems like an extremely dry topic and yet you manage to explain it well and simple enough and interesting at the same time. Fascinating. Kudos!
I've spent the last couple weeks working on getting an SPI SD card reader working.. this is perfect! Thanks! In my research and attempts to get an SD card reader working, I've found that SPI not being completely standard has some issues. As you said in your video the clock, DI and DO lines are common bus lines and CS is individual to the device. Some types of devices do things that are kind of odd. For example when you initialize an SD card reader you send at least 74 clock pulses with CS held high to get it into SPI mode. I'm no expert but I don't think that's a good idea when you want to have multiple devices on the same bus, devices should only respond to anything when their select line is low. It's low risk in this case (if the card reader is on the SPI bus you want it to be in SPI mode) but it just doesn't seem right that an SPI device can be influenced when their CS line is high.
That brought back memories. i used to lecture on 6502, 68xx, 68HC11 etc. I retired 21 years ago last week. I now play with ESP8266/32 to stay out of trouble!
Was literally trying to figure out this whole SPI thing yesterday during a microcontroller lab I’m enrolled in at school. The professor wasn’t very helpful in explaining it and this guy answers most of my questions in the first 5 minutes. THANK YOU GOD KING BEN 👑👑👑
This feels like arcane knowledge. Crazy to think how much I don't know or understand about devices that are essential to my well-being. Amazing video, as always!
It is really educational that you go through how to interpret the data sheets/manuals! I’ve learned a lot about how computers work and coding watching your videos and it makes me interested in learning more ☺️
Have seen a few of your videos so far and they are precise and highly educational without the usual smalltalk and infomercial "noise". Also, I'm not into posting comments but, I must commend you for your effort and clarity. Not only are you an excellent engineer, but you are also an excellent teacher, which is very rare. Thanks and keep up the good work.
Tip, you can also use SPI for very simple circuits. E.g. feeding a shift register ic (74hc595 maybe) with SPI output is an easy and cheap way to control LEDs. What more, it can be daisy chained so the only limit is the SPI bus speed or the ic frequency.
74HC595 and 74HC165 can operate upto 31MHz max at 4.5V or 36MHz at 6V according to Ti. So it's quite suprisingly fast given that Atmega328p's SPI can go only upto half of clock Speed, typically 8MHz on Arduino Uno or 10MHz if 20MHz crystal is used instead
@@prathamkalgutkar7538 it's not super surprising, where would they get the rest of the speed from? you get a cycle to set up the data with clock low, then a cycle of reading the data with clock high
wow.. every explanation video i watch, there are always these little questions pops in my head and sadly almost everyone leave behind those questions and leaves me clueless about what i have learn... sir you go into every single detail and the same time adding more knowledge and that to me is impressive. i wish i can learn from you someday.. sir you are an exceptional teacher i never had...thank you
Ben, thanks for a very clear and informative video on the SPI protocol. I was interested to see you working with the Motorola 6502. This reminded me of an upgrade project at Cutler Hammer, Fenton ,Michigan in 1978 when I had to convert a static CRT display of machine tool data to a dynamic one, updating the various events and parameters on the screen as and when they occurred, No SPI in those days just RS232c! The programming of the machine code was handled by a cross assembler on a DEC pdp11! Computers and microcontrollers have come a long way since then. Never-the-less, it is good to see the Motorola machine code again and see it being used with modern devices and protocols. Much appreciated!
Working as an embedded engineer I absolutely love your videos. I always get ideas from them. Also I'm always reminded to read the freaked manual! Happy coding 😁
Thank you for all your videos. I thought that the world of integrated circuits and boards was dead and gone. You take me back to the early 1980's when I started programming on a 8088 and my VIC 20's 6502 and then the late 80's when I taught the Z80 family to high schoolers. You are doing a brilliant job.
Thank you very much! I use micro-controllers using libraries that abstract using the devices over SPI. This helps me better understand what is going on underneath all of the abstraction.
You are much better at explaining the SPI protocol than I would be. I have never programmed in assembly, but managed to get stuff working programming in C. I basically did the same thing (bit-banging) and made a library for it. I don't know if it's the "proper" way to do it or the most "elegant", but it's worked for me. I2C is another very simple protocol (actually most serial interfaces that I have worked with have been relatively simple).
You are amazing, as an electrical engineering student myself I can't thank you enough for what you have done for the community. Keep up the good work, I learned a lot from this video alone!
Please keep making videos like this. You are the reason why I understand this computer thing more deeply if not I don't know what I'm learning. Thank you! Ben.
Great video. I learned microcontrollers back in the 1980s with a Heathkit 6800 course. I’m glad to see you’re getting down to assembly language level. I’ve been playing around with the Raspberry Pi PICO in MicroPython. That’s a lot easier, but it’s harder to understand what’s going on when I’m just using a library that someone else made up.
Which is faster/more efficient for large amounts of data? SPI or I2C? If im using SPI can i just increase clock speed to increase performance (to a point)?
@@karlm9584 to add a little more info: I2C can technically run at a few different speeds. Generally, it runs at 100 or 400 kbit/sec, 100 is the base spec but most things I know of support 400, though a few modifications and support can clock it up to 1.7 or 3.4 Mbit/sec with the master device actively driving the clock line, but those two also include some slight protocol changes to make sure you don't get into a situation where a slave is pulling SCL low as a master is driving it high. SPI can technically clock as fast as whatever device you're addressing can take (or whatever the capacitance on your line dictates). If you're using SPI, you can increase SCL to whatever the datasheet for the peripheral device says it can respond to. If you're transferring large amounts of data, I2C also has acknowledgements as part of the protocol, where every byte needs to be acknowledged as received and/or correctly interpreted. I2C is also *always* a two-wire bus, regardless of the peripheral count, whereas SPI is 3+n, where n is the count. SPI, lacking any protocol, can technically just be used as a stripped down serial connection, and just blurt out a bunch of bits, at whatever speed, and it's up to you to write the protocol to make sure the data was read correctly.
I had a pretty good lecturer... But this lesson was better than what I got. Excellent example of communicating and teaching - lecturers and tutors take note!
These videos are really great. Im currently studying wjec A-level electronics in UK, you'd be suprised by how little resources are available to revise from. Some of these videos have been super helpful!
I spent the last month trying to get a handle on SPI, and a week later this video comes out explaining it better than any other resource I've found....
I've also used the BME280 - it is a great chip. I was really impressed that the pressure sensor could tell the difference in altitude between my desk and the floor.
Thank you for this video. I really like the way you are showing stuff, in such a depth that is very good to understand and includes all necessary details to fully understand it.
Sitting here with the parts to make a USB Host interface to a 6502 computer using a component with an SPI interface. Then I stumble on this channel, and find a video on the SPI interface on a 6502 computer, and the same channel has a video on the USB protocol. Convenient.
Another fantastic video! You truly are a great teacher. Would love to learn about i2c ... What's better/worse than SPI, speed, addressing, coding, etc.
I'm going to say something a bit controversial: this is probably one of the most personally useful videos to me. I've seen many Arduino videos about SPI, but no one has gone into this much detail and gone this much into the specification. This is so well made, SPI is now so clear to me, thank you so much for this.
Thank you for all your incredible videos. By the way I would love to see a video on IR communication. Specifically the hardware design for how signals are generated and decoded. Anyone else interested?
I know this is more of an intro tutorial, but there are many devices that require CS to toggle before they will respond. This is so devices can be daisy chained. eg device1 SDO -> device2 SDI … etc. Then all the commands are concatenated and sent as a long data stream with one CS, then all the concatenated responses are received with a second CS. Trading off less hardware (I/O pins) for more software. Very useful for very dense designs with multiple peripheral devices
I'd really like to see a series of videos of adding an ACIA serial interface to the computer. The EEPROM could implement a simple bootloader that loads a program via serial into RAM, then executes it. As a bonus, this would remove the need to constantly pull the EEPROM out, reprogram it, then put it back into the breadboard.
Years ago I wrote a loader for the 8051 like that. It was easy to just follow the Intel spec for hex files that popped out of the cross assembler and just passed that as text to the processor serially. Gave it a go command and off it went.
The 6522 VIA has built in shift register where you can load a value and have it clock it out, together with a clock, automatically. And similarly you can shift in automatically and generate an IRQ on completion. So you could for example, use it to shift out the address, switch mode and then read in the next bytes all in your existing hardware.
i hope he makes more videos on serial communication protocols. I am just a CS student but these kind of videos help me appreciate the holy electronics engineers that engineered these core technologies so that simpletons like me can console log "Hello, world" without ever having to deal with bare-metal stuff.
Seeing this kind of videos is like going into the cockpit of an Airbus 380 with a bunch of controllers and switches. But it's very satisfying to see low level that construct a very simple signal from sensors like BME280
Just yesterday I decided to learn the details of SPI and did some research, and then today, my computer tells me you have the video I want to see! Perfect timing. :)
You seem to have an incredibly good command of low level stuff, which is a very rare skill in an era where everything is abstracted away through super high level programming languages.
As a informatics Student i have zu say, that your Videos replace most of my lectures 😂 they are so good explained and informativ, mostly better than my Professor
These videos of yours, and not only this, are such information gold 💪🏻 Thanks for sharing your knowledge on difficult and complicated things with the world!
I2S is pretty much identical to SPI, except that the Chip Select line is called Word Select because it indicated whether the audio data sent is for the left or the right channel. And the serial clock needs to be a precise multiple of the sample rate. Otherwise, it's just a regular SPI.
I actually happened to have at least one BME280, which is a barometric/temperature/humidity sensor to replace BME180. It is pretty amazing how they keep fitting all this circuitry in such a small package and still provide a decent accuracy of measurements.
3 ปีที่แล้ว
What a delightful video. Nothing like a plain simple SPI masterclass from Ben to chill out.
SPI is SO NICE for low-risk real time stuff. its not very robust in terms of fault tolerance or redundancy, but if you don't need that stuff, then SPI is awesome. its a fresh breeze compared to working with more annoying things like CAN bus, RS-232, RS-422 or especially RS-488. i'll die happy if i never have to hunt down another RS-488 to USB converter. You should up the complexity of your little computer by a million percent and fully implement a 1553 interface with full redundancy (both buses) lol
A watched all your videos, i think its the best serie of videos about computer science and electronics on TH-cam , should everyone watch it. Actually i am from Morocco and i get so much inspiration of you and of your way on explication. Love you Mr ben, I have few questions because i want to build a 16 bit computer on breadboard as a challenge, so where i can buy all this logic gates and electronics components? I am studing in high school of technology in Morocco, and 2022 will be my second year at this school I am studing electronics and automatic stuff and industrial engineering, so where i can continue My studies. Finally, thanks a lot for every information you share ❤️❤️
Pausing at 10:30 to say that on a complex SPI bus I usually use CS as a selector for a bus-connected SIPO which controls the CS input on the devices. Each peripheral has its CS input attached to a gate or gates (depending on whether the device is active low or high) where the gates input from the master CS and the relevant pin on the shift register. To select a peripheral I drive CS low and then output the bit sequence which corresponds to the desired state, then drive CS high and carry on. The decoder idea is good and straightforward if you have the pins for it, but the SIPO actually effectively increases the number of pins available rather than consuming any which aren't already in use by SPI, which is good for working with limited pins on the controller, like with an atTiny or etc.
Hi Ben, two comments to your great video: 1. please use another color for your editor next time. If you marked something please do not use white color on white color. 2. Even if you are using 6502 code, please also explain some of the more „odd“ opcodes like „stz“. Thanks and make more of theses fantastic videos!!!!!
I would just like to point out how god damn clean and user friendly the datasheet of the BME280 is. Timing diagrams annotated with the bit-indices, comprehensible english, a clickable table of contents, using vector graphics for every graphical element. I wish every datasheet was this well made.
"Comprehensible English" had to chuckle at that one!
I used this little sensor (via I2C though) in my projects, it is quite reliable and precise. I agree, the manual is just beautiful from the software developer's point of view (hopefully, from electronic engineer's one too). They describe whatever you need and you want to know about this sensor in details. A perfect example how it should be done properly.
I am working with the AD7771 ADC from analog devices, using the SPI interface. I wish the datasheet was 10% as friendly as the BME280 datasheet is.... Not only regarding the SPI protocol but explaining properly what certain registers do.
The pdf’s all fine and readable, but the damn BME thing heats itself up quite significantly, unlike the el cheapo chinesium DHT sensors.
@@sashimanu How??? The average current-consumption while measuring at 1Hz is less than 4uA. Max consumption is ~1mA, so it should be literally impossible to heat this thing up if used right. It is a temperature sensor too after all, it isn't allowed to heat itself up by DESIGN. You either got a fake, your wiring is wrong or your GPIOs are set up wrong. Are you disconnecting VDD, but keep the SPI/CS lines powered? (could cause backfeeding through the ESD-diodes) Are you using it at above 3.6 volt?
"More valuable than a thousand days of diligent study is one day with a great teacher."
--Japanese Proverb
"Your not wrong."
- Norfolk saying...
@@stoatrepublic Very COoL.. :O)
"The Norfolk dialect, also known as Broad Norfolk, is a dialect spoken in the county of Norfolk in England which sits within the broader East Anglian English. While less widely and purely spoken than in its heyday, the dialect and vocabulary can still be heard across the county, with some variations?. Wikipedia
@@ovalwingnut I'm Norfolk through'n'through, broadcast across the Norfolk Broads everyday and drive a tractor/lawn mower.
@J Hemphill Very COoL.. :O)
"You're not wrong"
--Sweet Brown
-- "Ain't Nobody Got time For That" --
"I got bronchitis
ain’t nobody got time for that.
Ain’t nobody got time for that
Ain’t nobody got time for that
Ain’t nobody got time,
ain’t nobody got time
Ain’t nobody got time for that
Well, I woke up to get me a cold pop
Then I thought somebody was
BBQing
(BBQing)
(BBQing)
I said, “Oh, lord Jesus it’s a fire!”
Then I ran out,
I didn’t grab
no shoes or nothing Jesus
I ran for my life
Ain’t nobody got time for that
Ain’t nobody got time for that
Ain’t nobody got time,
ain’t nobody got time
Ain’t nobody got time for that
Ain’t nobody got time for that
Ain’t nobody got time for that
Ain’t nobody got time,
ain’t nobody got time
Ain’t nobody got time for that
I said, “Oh, lord Jesus it’s a fire.”
I said, “Oh, lord Jesus it’s a fire.”
I said, “Oh, lord Jesus it’s a fire.”
Jesus, Jesus, Jesus, it’s a fire.
Ain’t nobody got time for that
Ain’t nobody got time for that
Ain’t nobody got time,
ain’t nobody got time
Ain’t nobody got time for that
Ain’t nobody got time for that
Ain’t nobody got time,
ain’t nobody got time
Ain’t nobody got time for that"
Cheers JH (good one BTW, which is more than I can say for them' lyrics:)
I disagree with this saying
I'm an electrical engineering student and I've gotta say you've single-handedly reminded me why I chose my major and revitalized my love for electronics.
I'm also a student and feel the same way. School can be rather demotivating, while content like this is inspiring and motivating.
When I was at school I had no interest in grades or classes whatsoever. It was only until my friend taught me how to solder which was when my interest took off
Can i ask, is he doing more of electrical/electronics or computer engineering?
These are genuinely my sentiments as well
I'm just a hobbyist but agree, Ben's videos are always like that.
I am 80, but your explanation was clear, concise and intellectually satisfying. Congatulations on a superb piece of teaching that I will remember as a classic explanation.
May I ask you what your career was in, Sir?
It's rare to see a Ben Eater video where I am very familiar with what he is showcasing. I've written multiple drivers using different HALs for the shown sensor.
Good job bro
Plus there. Working with SPI-like interfaces at work.
The HAL9000 is the best, but sometimes a little bit homicidal.
@@sdspivey 😁
Hi. In your HAL were this SPI sensor's temp/pressure registers memory mapped or IO mapped somehow (possibly via an SPI controller) that you could simple read/write to obtain the temp/pressure data? I'm trying to understand how a 'modern' processor on a motherboard talks to SPI chip (like SPI flash memory containing the BIOS). Surely you didn't 'bit bang' like Ben did here inside your driver code?
Gosh I needed an SPI class soooo bad, it came in the best timing ever
No pun intended
That's because Ben controls the clock.
@@renakunisaki Click... Click... Click...
@@smooooth_ All puns should be intended. 😉
The biggest plus with Ben Eater's videos is that he has given free access to the murkiest and deeply obfuscated engineering procedures and workflows for the common people. Even if we don't fully grasp them, we know that these notoriously complex workings happening right before our eyes can be tamed with time and effort. No other contributor I have experienced has gone this far, this easily.
brings back EE undergrad memories. the toughest ones, microcontroller lab, assembly, LDA-ing and STA-ing bit by bit just like that. Protocols I forgot, addresses I still remember, funny failure stories... 🤓😅
I used SPI in my final project for university. We had a microcontroller controlling a series of LED displays. The controller sent the display a byte of data using SPI which the display read as an ASCII character and displayed. The interesting thing is we had the display setup so that whenever they received data they would output their old data and then we daisy-chained displays so each one sent the last character it received onto the next. That way we could control a whole bunch of LED displays with just the one chip select line. The end display would wrap around back to the controller. We used that to allow the controller to figure out how many displays were connected. it would send out zeros for a while to clear out whatever data was in the displays and then send all ones and count how many sends it took to get the ones back. However sends it took was the number of displays attached.
While implementing that counting logic I made a mistake in my looping bounds. The counter variable was only a single byte and I told it to loop until that byte was 256 which of course never happened. Made a very interesting strobe effect though. As the displays were constantly being interrupted to transmit and receive data.
That's super cool! Thanks for the break-down. I'm going to order some bread boards to run some projects a friend told me about
Just remember this is exactly how engineering really goes. You just follow the datasheet it works the first time perfectly, and you feel rewarded at the end.
Yeah only it doesn't work first time
STEM students felt that one
@@harryjohnson615 Actually sometimes it does and when it does it feels so good.
I remeber once we had four day weekend (Easter) to set up a new facility. New system & computers, user accounts etc. We got it running on monday morning and the first test was success. We had 5 men team where I was the one controlling the workflow and checking on the server side that each computer on the network was responding properly. Last thing was to fire the script that made those user accounts and check that they were set up correctly. They were and we were off to celebrate. Had private sauna with food and drink courtesy by the company management. Actually I think I slept four hours during those four days. We postponed the celebration to tuesday and got both tuesday and wednesday off. We also got mighty hefty one time compensation for that work. Felt pretty good.
Electronics/computer engineering is definitely a career for people who like to read the manual.
Ben you are an absolute institution. I'm a chemist, and closet electrical engineer / low level software engineer and your content is so precisely the right level for my brain it's ridiculous. I mean, I'm a complete amateur and such but your pace, tone and rigour with which you go through the detail is sublime. Hats off to you sir. Not that I wear a hat
Literally the only firmware programming I ever did was to write an I2C implementation that could control the LEDs and read the temperature sensor on a network (interconnect) card. We had the prototype cards without the ASIC on them and I ended up bit-banging a parallel port on a desktop PC to implement a (very slow) I2C.
The company (Quadrics) went bust a few months later and I never actually got to see my code running from the ASIC, and that was the end of my glorious firmware programming career.
what are you doing now? have you left the firmware programinng?
@@nikhilwardrobe Oh yeah, that was an aberration. These days am an SRE, which suits me fine.
@@Vanders456 I'm working as intern with designation as embedded firmware developer. I have heard the pay isn't that good. Why did you shifted from firmware to sre and how did you do that?
I was just telling my wife how the USB interface videos were fascinating and fun, this just adds to it. Thanks!
We might also mention that devices vary about whether MSb or LSb is sent/received first. If all 8 outputs of the decoder is used, you will also need to devote one more pin to selecting/deselecting the decoder; otherwise, one of the eight devices will always be selected. If output 7 is not used, then writing 111 to the decoder will deselect all used devices, however.
I'm falling to find a reason that it's a bad thing that one will always be selected. If the device needs the clock to start a conversation anyway?
@@modmen. The chip knows the byte is complete only after it is de-selected... You could still select another chip without transferring any data, but some chips don't respond well to that.
Was having some issues with SPI on a sensor for a project I'm currently working on. This video is perfect timing. 👍
the production value that goes into these videos is pretty insane tbh, it must take a shitton of effort to line up the voice overs, the edits and the script to work how you're doing it. It's all very minimal but ohhhhh so precise and delicate, which kinda fits who you are as a figure on youtube. Kudos to you, Ben, for the work you're putting into the production of these videos
This dude is better than a college education and he's free.
Sounds like a good reason to join his Patreon!
I learned 100 times more during his computer build THAN I did getting my BS in Electrical Engineering Technology. His free video explained why in just a few minutes where school just said what.
Had to edit my reply because Mr. English Professor called out a misspelling. My misspellings are proportional to how much I've had to drink....
Certainly more practical
@@rymaples Need to work on your English though... *than
@@nathanrice3890 My dude this is a TH-cam comment, NOT YOUR THESIS!
I had trouble with an SPI chip once.... I never considered that I was maybe using the wrong clock mode.... thanks for the tip!
I always do SPI on microcontrollers with a built in SPI port.... very interesting seeing you "go old school" and implementing the interface with bit-banging.... showing us how it REALLY WORKS.
This was great! Would love follow-up videos on I²C and maybe UART
If only Bosch were as good at keeping their sensors in stock as they are at writing data sheets for their products...
To be very fair, it has been a pretty hard year for everyone. But yeah, we want hardware!
I don't know why, this seems like an extremely dry topic and yet you manage to explain it well and simple enough and interesting at the same time. Fascinating. Kudos!
I've spent the last couple weeks working on getting an SPI SD card reader working.. this is perfect! Thanks!
In my research and attempts to get an SD card reader working, I've found that SPI not being completely standard has some issues. As you said in your video the clock, DI and DO lines are common bus lines and CS is individual to the device. Some types of devices do things that are kind of odd. For example when you initialize an SD card reader you send at least 74 clock pulses with CS held high to get it into SPI mode. I'm no expert but I don't think that's a good idea when you want to have multiple devices on the same bus, devices should only respond to anything when their select line is low. It's low risk in this case (if the card reader is on the SPI bus you want it to be in SPI mode) but it just doesn't seem right that an SPI device can be influenced when their CS line is high.
SD cards are insane.
I love the way you explain things, I feel now so confident at school and really feel the hunger to see all old vids too, they are just amazing!
That brought back memories. i used to lecture on 6502, 68xx, 68HC11 etc. I retired 21 years ago last week. I now play with ESP8266/32 to stay out of trouble!
Ben you're an incredible engineer. You're inspiring an entire generation towards EE or CE
After only 6 minutes, I feel like I already learned so much
Love these explanations! Pretty amazing how responsive that little sensor is.
Was literally trying to figure out this whole SPI thing yesterday during a microcontroller lab I’m enrolled in at school. The professor wasn’t very helpful in explaining it and this guy answers most of my questions in the first 5 minutes. THANK YOU GOD KING BEN 👑👑👑
You got an absolutely gorgeous and powerful Oscilloscope there!!
Yes, I'm drooling for that one also. :)
This feels like arcane knowledge. Crazy to think how much I don't know or understand about devices that are essential to my well-being. Amazing video, as always!
I'm just a laymann and I've gotta say you've single-handedly reinforced me why I love (and study) electronics/computer science myself.
I am currently in high school but can easily understand each and every bit of your video, amazing to see how clear are your concepts!!!!
I’m not quite sure why, but just seeing this video pop up bought a welcome wave of happiness. Thankyou!
This video summarize 100 hours of lectures, this is really what I’m looking for! very good job. Thumbs up 👍
Great Presentation. For newbie, this gave clear insight about SPI protocol to understand the physical connections of the SPI interface. Thank you.
It is really educational that you go through how to interpret the data sheets/manuals! I’ve learned a lot about how computers work and coding watching your videos and it makes me interested in learning more ☺️
Have seen a few of your videos so far and they are precise and highly educational without the usual smalltalk and infomercial "noise". Also, I'm not into posting comments but, I must commend you for your effort and clarity. Not only are you an excellent engineer, but you are also an excellent teacher, which is very rare. Thanks and keep up the good work.
Thanks Ben, you made my project simpler, TMS9900 that now can use SPI directly without a glue chip. Saved 100 hrs of investigation.
Tip, you can also use SPI for very simple circuits. E.g. feeding a shift register ic (74hc595 maybe) with SPI output is an easy and cheap way to control LEDs. What more, it can be daisy chained so the only limit is the SPI bus speed or the ic frequency.
I use a 595 as a bus controller for SPI, lol.
74HC595 and 74HC165 can operate upto 31MHz max at 4.5V or 36MHz at 6V according to Ti. So it's quite suprisingly fast given that Atmega328p's SPI can go only upto half of clock Speed, typically 8MHz on Arduino Uno or 10MHz if 20MHz crystal is used instead
@@prathamkalgutkar7538 it's not super surprising, where would they get the rest of the speed from? you get a cycle to set up the data with clock low, then a cycle of reading the data with clock high
wow.. every explanation video i watch, there are always these little questions pops in my head and sadly almost everyone leave behind those questions and leaves me clueless about what i have learn... sir you go into every single detail and the same time adding more knowledge and that to me is impressive. i wish i can learn from you someday.. sir you are an exceptional teacher i never had...thank you
Ben, thanks for a very clear and informative video on the SPI protocol. I was interested to see you working with the Motorola 6502. This reminded me of an upgrade project at Cutler Hammer, Fenton ,Michigan in 1978 when I had to convert a static CRT display of machine tool data to a dynamic one, updating the various events and parameters on the screen as and when they occurred, No SPI in those days just RS232c! The programming of the machine code was handled by a cross assembler on a DEC pdp11! Computers and microcontrollers have come a long way since then. Never-the-less, it is good to see the Motorola machine code again and see it being used with modern devices and protocols. Much appreciated!
This is really awesome! @42 years old, i learned a lot with this man... you're really good...
Working as an embedded engineer I absolutely love your videos. I always get ideas from them. Also I'm always reminded to read the freaked manual! Happy coding 😁
Thank you for all your videos.
I thought that the world of integrated circuits and boards was dead and gone.
You take me back to the early 1980's when I started programming on a 8088 and my VIC 20's 6502 and then the late 80's when I taught the Z80 family to high schoolers.
You are doing a brilliant job.
Thank you very much! I use micro-controllers using libraries that abstract using the devices over SPI. This helps me better understand what is going on underneath all of the abstraction.
This has been the best hands-on explanation I’ve seen of SPI, period. Please do one on I2C and UART!
These protocol videos are fantastic. It is all very visual and the lack of jargon makes it super accessible.
Never missed a single lecture from ben.. he has immense indepth knowledge.. thanx fr giving
You are much better at explaining the SPI protocol than I would be. I have never programmed in assembly, but managed to get stuff working programming in C. I basically did the same thing (bit-banging) and made a library for it. I don't know if it's the "proper" way to do it or the most "elegant", but it's worked for me.
I2C is another very simple protocol (actually most serial interfaces that I have worked with have been relatively simple).
You are amazing, as an electrical engineering student myself I can't thank you enough for what you have done for the community. Keep up the good work, I learned a lot from this video alone!
Please keep making videos like this. You are the reason why I understand this computer thing more deeply if not I don't know what I'm learning. Thank you! Ben.
Great video. I learned microcontrollers back in the 1980s with a Heathkit 6800 course. I’m glad to see you’re getting down to assembly language level. I’ve been playing around with the Raspberry Pi PICO in MicroPython. That’s a lot easier, but it’s harder to understand what’s going on when I’m just using a library that someone else made up.
Thank you for all these amazing videos. Please consider covering I2C and RS-232 to TTL converters as well!
Which is faster/more efficient for large amounts of data? SPI or I2C?
If im using SPI can i just increase clock speed to increase performance (to a point)?
@@karlm9584 SPI is inherently faster. I2C uses pullup resistors while SPI has push/pull drivers using transistors, not resistors.
@@darer13 thanks!
@@karlm9584 to add a little more info: I2C can technically run at a few different speeds. Generally, it runs at 100 or 400 kbit/sec, 100 is the base spec but most things I know of support 400, though a few modifications and support can clock it up to 1.7 or 3.4 Mbit/sec with the master device actively driving the clock line, but those two also include some slight protocol changes to make sure you don't get into a situation where a slave is pulling SCL low as a master is driving it high.
SPI can technically clock as fast as whatever device you're addressing can take (or whatever the capacitance on your line dictates). If you're using SPI, you can increase SCL to whatever the datasheet for the peripheral device says it can respond to.
If you're transferring large amounts of data, I2C also has acknowledgements as part of the protocol, where every byte needs to be acknowledged as received and/or correctly interpreted. I2C is also *always* a two-wire bus, regardless of the peripheral count, whereas SPI is 3+n, where n is the count.
SPI, lacking any protocol, can technically just be used as a stripped down serial connection, and just blurt out a bunch of bits, at whatever speed, and it's up to you to write the protocol to make sure the data was read correctly.
I had a pretty good lecturer... But this lesson was better than what I got.
Excellent example of communicating and teaching - lecturers and tutors take note!
These videos are really great. Im currently studying wjec A-level electronics in UK, you'd be suprised by how little resources are available to revise from. Some of these videos have been super helpful!
I spent the last month trying to get a handle on SPI, and a week later this video comes out explaining it better than any other resource I've found....
Great video. I use SPI all the time but via libraries. Nice to see it broken out. I appreciate the time and effort it takes to make a video like this.
Bro ,your explanation is so really clear to understand. Thanks a lot.
Thank you. I was lost with the spi bus but I now have a better understanding.
I've also used the BME280 - it is a great chip. I was really impressed that the pressure sensor could tell the difference in altitude between my desk and the floor.
Thank you for this video. I really like the way you are showing stuff, in such a depth that is very good to understand and includes all necessary details to fully understand it.
Sitting here with the parts to make a USB Host interface to a 6502 computer using a component with an SPI interface. Then I stumble on this channel, and find a video on the SPI interface on a 6502 computer, and the same channel has a video on the USB protocol. Convenient.
Helpful information. Thank you
Another fantastic video!
You truly are a great teacher.
Would love to learn about i2c ... What's better/worse than SPI, speed, addressing, coding, etc.
I'm going to say something a bit controversial: this is probably one of the most personally useful videos to me. I've seen many Arduino videos about SPI, but no one has gone into this much detail and gone this much into the specification. This is so well made, SPI is now so clear to me, thank you so much for this.
Thank you for all your incredible videos. By the way I would love to see a video on IR communication. Specifically the hardware design for how signals are generated and decoded. Anyone else interested?
I know this is more of an intro tutorial, but there are many devices that require CS to toggle before they will respond. This is so devices can be daisy chained. eg device1 SDO -> device2 SDI … etc. Then all the commands are concatenated and sent as a long data stream with one CS, then all the concatenated responses are received with a second CS. Trading off less hardware (I/O pins) for more software. Very useful for very dense designs with multiple peripheral devices
I'd really like to see a series of videos of adding an ACIA serial interface to the computer. The EEPROM could implement a simple bootloader that loads a program via serial into RAM, then executes it. As a bonus, this would remove the need to constantly pull the EEPROM out, reprogram it, then put it back into the breadboard.
Years ago I wrote a loader for the 8051 like that. It was easy to just follow the Intel spec for hex files that popped out of the cross assembler and just passed that as text to the processor serially. Gave it a go command and off it went.
I just wanted to say thank you, I have enjoyed your videos about computer basics in the past, and I want you to know that I have really liked them
The 6522 VIA has built in shift register where you can load a value and have it clock it out, together with a clock, automatically. And similarly you can shift in automatically and generate an IRQ on completion. So you could for example, use it to shift out the address, switch mode and then read in the next bytes all in your existing hardware.
Man that scope helped so much with my understanding of the 2 way aspect. Cheers again!
i hope he makes more videos on serial communication protocols. I am just a CS student but these kind of videos help me appreciate the holy electronics engineers that engineered these core technologies so that simpletons like me can console log "Hello, world" without ever having to deal with bare-metal stuff.
Such a great visualization of polarity and phase. And it's wonderful to see the 6502 back in action!
Seeing this kind of videos is like going into the cockpit of an Airbus 380 with a bunch of controllers and switches. But it's very satisfying to see low level that construct a very simple signal from sensors like BME280
I'm just starting to work on a project with SPI, this video couldn't have come at a better time
Ben eater is one of the greatest man of the millennium!
Just yesterday I decided to learn the details of SPI and did some research, and then today, my computer tells me you have the video I want to see! Perfect timing. :)
What a gold I found! This is it. The porno for embedded learners and junior engineers.
The best video I have ever watched on TH-cam in 2022
You seem to have an incredibly good command of low level stuff, which is a very rare skill in an era where everything is abstracted away through super high level programming languages.
Pretty neat, ive been working on a spi device for the past few weeks. And its nice to get some of the background about it.
As a informatics Student i have zu say, that your Videos replace most of my lectures 😂 they are so good explained and informativ, mostly better than my Professor
These videos of yours, and not only this, are such information gold 💪🏻 Thanks for sharing your knowledge on difficult and complicated things with the world!
I hope to see I2C and (the completely unrelated) I2S in the future, great video!
I2S is pretty much identical to SPI, except that the Chip Select line is called Word Select because it indicated whether the audio data sent is for the left or the right channel. And the serial clock needs to be a precise multiple of the sample rate. Otherwise, it's just a regular SPI.
Thank you for creating more content and sharing more knowledge.
I actually happened to have at least one BME280, which is a barometric/temperature/humidity sensor to replace BME180.
It is pretty amazing how they keep fitting all this circuitry in such a small package and still provide a decent accuracy of measurements.
What a delightful video. Nothing like a plain simple SPI masterclass from Ben to chill out.
Was just re-studying the breadboard computer, then suddenly this pops up.
Google is watching watch TH-cam.
Very deeply explained, and highly informative video! Great job Ben! 😄
Very clear presentation covering all the key points.
Ben has tought me over several videos way more than me tried get this knowledge over years
Was literally just doing some reading on SPI for uni. Amazing timing
SPI is SO NICE for low-risk real time stuff. its not very robust in terms of fault tolerance or redundancy, but if you don't need that stuff, then SPI is awesome. its a fresh breeze compared to working with more annoying things like CAN bus, RS-232, RS-422 or especially RS-488. i'll die happy if i never have to hunt down another RS-488 to USB converter.
You should up the complexity of your little computer by a million percent and fully implement a 1553 interface with full redundancy (both buses) lol
Most awesome, you correlate a lot there with the scope to prove it.
That explained SPI very well, when I was trying to learn it a few years back it took a month.
A watched all your videos, i think its the best serie of videos about computer science and electronics on TH-cam , should everyone watch it. Actually i am from Morocco and i get so much inspiration of you and of your way on explication. Love you Mr ben,
I have few questions because i want to build a 16 bit computer on breadboard as a challenge, so where i can buy all this logic gates and electronics components?
I am studing in high school of technology in Morocco, and 2022 will be my second year at this school
I am studing electronics and automatic stuff and industrial engineering, so where i can continue
My studies.
Finally, thanks a lot for every information you share ❤️❤️
Great video!
Side note: I recommend updating the firmware in your 121GW multimeter. The latest download is 2.04.
I can't thank you enough for this incredibly informative and well produced video. You did a great job to help decrypt the datasheet for me.
Pausing at 10:30 to say that on a complex SPI bus I usually use CS as a selector for a bus-connected SIPO which controls the CS input on the devices. Each peripheral has its CS input attached to a gate or gates (depending on whether the device is active low or high) where the gates input from the master CS and the relevant pin on the shift register. To select a peripheral I drive CS low and then output the bit sequence which corresponds to the desired state, then drive CS high and carry on.
The decoder idea is good and straightforward if you have the pins for it, but the SIPO actually effectively increases the number of pins available rather than consuming any which aren't already in use by SPI, which is good for working with limited pins on the controller, like with an atTiny or etc.
Hi Ben, two comments to your great video:
1. please use another color for your editor next time. If you marked something please do not use white color on white color.
2. Even if you are using 6502 code, please also explain some of the more „odd“ opcodes like „stz“.
Thanks and make more of theses fantastic videos!!!!!