Hardware SPI - IO from Scratch - Part 6

  Переглядів 6,290

James Sharman

James Sharman

День тому

Bit banging SPI produced some functional results but I’d like to improve my overall data transfer rate, and that means adding some hardware support. I identify 4 areas we can add some assistance to and add some circuitry for the first two. This will be followed (I hope very soon) with the second part finishing of the conversion.
I had originally planned to this all in one video but it very quickly became clear that it would be a long one. It’s sometimes difficult to estimate how long some planned work will take, fortunately this one was fairly easy to divide in two. Everything was recorded before I started editing this, you can always comment suggestions but on this occasions the next steps are already complete.
0:00 Introduction
0:33 Discussing the circuit
1:10 Defining 4 Parts
2:30 Chip Select
8:58 MISO
12:13 Checking with the scope
17:02 Clock Invert
22:09 Multi Byte read debugging
24:26 Cycle counting
25:20 Outro

КОМЕНТАРІ: 44
@weirdboyjim
@weirdboyjim Місяць тому
Join us on Discord: discord.gg/jmf6M3z7XS Follow me on Twitter: twitter.com/WeirdBoyJim Support the channel on Patreon: www.patreon.com/JamesSharman
@dusterthefirst
@dusterthefirst Місяць тому
I’m fairly certain that you must have already thought of this, but for loop unrolling it may be useful to have a macro/preprocessor step that is able to generate the unrolled loop.
@weirdboyjim
@weirdboyjim Місяць тому
I have been thinking about adding some features to the assembler for that. I have a few other places where that would make things more maintainable.
@user-vd8oy1wh4r
@user-vd8oy1wh4r Місяць тому
That is why people created compilers ))) I would actually like to see C or Basic or something else running on this
@Zer0ji
@Zer0ji Місяць тому
That's what I thought as well. Fancy macros allow using `i` inside the unrolled code, but a basic `repeat(8)` block would do wonders here
@drivers99
@drivers99 Місяць тому
@@user-vd8oy1wh4rForth is super space efficient and easy to implement while being powerful and fast
@randomfish42
@randomfish42 Місяць тому
This could be done without need to implement it in the assembler, just use a C compiler and tell it to to pre-process only (-E for gcc IIRC). If you're using Makefiles this should be an easy step to add.
@lewa_j
@lewa_j Місяць тому
Consider enabling line numbers display in your IDE. It may help viewers to keep up, especially with a lot of fast scrolling.
@weirdboyjim
@weirdboyjim Місяць тому
Hmm, I'll look into that. The next video in this series is already recorded though.
@khatharrmalkavian3306
@khatharrmalkavian3306 Місяць тому
I don't know why, but fiddling with SPI is one of my favorite things in electronics. Looking forward to the next video!
@weirdboyjim
@weirdboyjim Місяць тому
It's been rewarding! Hope the next video(s) don't disappoint!
@khatharrmalkavian3306
@khatharrmalkavian3306 Місяць тому
@@weirdboyjim You're always great, brother.
@TheEmbeddedHobbyist
@TheEmbeddedHobbyist 25 днів тому
I was going to comment on you changing some defines to a 0, which removes the readability of the code by adding magic numbers. And then just as i was going to type this comment you went back and replaced the zero's with some defined constants. well done. 🙂
@weirdboyjim
@weirdboyjim 13 днів тому
Glad I didn't disappoint (this time).
@TheEmbeddedHobbyist
@TheEmbeddedHobbyist 12 днів тому
@@weirdboyjim Never known you disappoint, provide talking points yes but disappoint no. 🙂
@chrisdickens4862
@chrisdickens4862 Місяць тому
Great video as always!
@weirdboyjim
@weirdboyjim Місяць тому
Glad you enjoyed!
@teknifix
@teknifix Місяць тому
The 595 is an interesting solution. I chose the 74ALS299. It can input and output through either parallel or serial in both directions. I'm using it with a 6522, with one port being the 8 data lines and the other controlling SCLK and CS. It also supports shifting in both directions, if necessary. The only issue is switching between SPI modes. I'm sure I can solve it but I haven't had time recently to work on it. I also use it to interface to an arduino with a small screen for debugging. 3 chips lets me read both of the address bus bytes and the data bus byte quite easily.
@weirdboyjim
@weirdboyjim Місяць тому
You'll be interested in how I do some of that in the next video. Being able to shift in both directions is not something you need for this though although a shift register with that can do both parallel in and parallel out would save a chip.
@khatharrmalkavian3306
@khatharrmalkavian3306 Місяць тому
Whoa, that's a nice register. Adding some of those to my shopping list!
@Elixz89
@Elixz89 Місяць тому
James you should look into the 74ls95. Its a parallel in/out serial in/out shift register. If you connect 2 of these together you basically got SPI done except for the clock generation. I saw that LCSC has these in DIP package. Might want to have a look into these
@weirdboyjim
@weirdboyjim Місяць тому
That's a nice part but it doesn't have tri-state outputs so you would need another chip to interface it to the main bus.
@Elixz89
@Elixz89 Місяць тому
@@weirdboyjim You could add a latch and a 245
@alexloktionoff6833
@alexloktionoff6833 Місяць тому
I'm afraid 7495 is discontinued, there is no CMOS version. I remember in previous century it was a Swiss army knife like a 7400.
@Schwuuuuup
@Schwuuuuup Місяць тому
Great video! I am very interested in constructing an hardware SPI module for my own project. Unfortunately I have to admit that the way the functionality was presented here (as a conversion from bitbanging) I was left a bit confused. My mind is not really built for cross-referencing two videos. But I totally understand that this is not a how-to-guide. Nevertheless I look forward for an future video where the circuit schematic is built for sending it to an PCB manufacturer. Maybe you can go over it once again, how the new circuit ties in with the rest of the system.
@weirdboyjim
@weirdboyjim Місяць тому
Sorry to hear you found it harder to follow. I try to show building things up step by step rather than showing a finished circuit and explaining it. I guess different people prefer different ways to work and learn.
@Schwuuuuup
@Schwuuuuup Місяць тому
@@weirdboyjim no problem at all! that was in no way a complaint. Quite the opposite, normally I love to follow the real world progress of the project. Only now when I try to pick one single aspect of it out of context it is a bit harder.
@Zer0ji
@Zer0ji Місяць тому
Very interesting :) I was wondering why you didn't write `out GPIO, b` but obviously if there's no instruction for it that won't work. Would it be possible to use a counter chip that's somehow clocked 8 times per CPU clock to do one byte's worth of SPI clock in a single CPU cycle?
@ffsireallydontcare
@ffsireallydontcare Місяць тому
I was thinking something similar, but you wouldn't want to multiply the CPU clock. Instead you'd have a second oscillator or use the master clock for an 8 cycle counter which is then triggered using a single instruction from the CPU. So Read_SPI triggers the SPI circuit to read 8 bits independently of the CPU into the 8 bit SPI latch, and you'd have a similar circuit for writing. The timing of the independent circuit will be determined by the clock speed capability of the SPI spec. If the system clock falls within the spec then everything's great, otherwise you'll need a second clock source.
@ffsireallydontcare
@ffsireallydontcare Місяць тому
Sorry I should clarify, not a single CPU instruction - that would involve adding to the instruction set. I mean an instruction from the CPU to the SPI circuit. There may be a number of CPU instructions and interactions across the bus to achieve it, but you're saving the time the CPU currently generates the bit shifting clock.
@weirdboyjim
@weirdboyjim Місяць тому
I actually discuss that very thing in the next video. Running the clock at system*8 = 32mhz would be really cool, but not all SPI devices can run that fast which would introduce a another level of complexity to the circuit.
@ffsireallydontcare
@ffsireallydontcare Місяць тому
@@weirdboyjim This is what you get for delaying your releases! ;-P
@lawrencemanning
@lawrencemanning Місяць тому
FWIW not all SPI devices will tristate their MISO pins when not selected.
@weirdboyjim
@weirdboyjim Місяць тому
All the devices I've looked at so far seem to, but I know that SPI is not a defined standard so there are many variations that all claim to be SPI.
@thisnthat3530
@thisnthat3530 Місяць тому
If you buy them on those little modules, that issue is usually fixed by the incorporation of a 74HC125
@BrainSlugs83
@BrainSlugs83 Місяць тому
Unrolling loops doesn't have to be unmaintainable! I know you wrote this assembler yourself, but look at what ca65 does for "macro assembly". There are things like a repeat directive. And even user definable macros which can feel a lot like calling functions, but without any jumps, because you're just inserting code into your ROM imagine and all the repeating and/or parameter swapping is done at assembly time. You should consider improving your custom assembler with similar macro-based functionality.
@weirdboyjim
@weirdboyjim Місяць тому
I have a hope to add a number of new features to the assembler but balancing the time spent on various parts of the build is not easy.
@jensschroder8214
@jensschroder8214 Місяць тому
When the read command comes, the clock could count 8 pulses independently.
@weirdboyjim
@weirdboyjim Місяць тому
The next video in this series deals with clock generation. I had hoped to put all 4 bits in one video but it would have been very long.
@protonjinx
@protonjinx Місяць тому
I guess it would have been handy to make each unrolled bit codeblock into a macro, so you only need to edit one
@weirdboyjim
@weirdboyjim Місяць тому
I'd like to add some extra macro support but it's not always easy to balance time spent on tools verses building etc..
@bzuidgeest
@bzuidgeest Місяць тому
I'm confused, why keep controlling the clock from code directly? Hardware spi in my mind means giving a byte to the hardware and be safe in the knowledge it will be transmitted. What clock you have will just be a "setting" in the hardware, a register. Same for reading. You only do that when the hardware signals it has a complete byte to read. Maybe i missed something in the video, but at the moment what you are going for, looks more like hardware assisted spi then actual hardware spi
@weirdboyjim
@weirdboyjim Місяць тому
The thing you missed is that I've broken the build into 4 steps and only covered the first two here. The second video will deal with the clock.
@bzuidgeest
@bzuidgeest Місяць тому
@@weirdboyjim ah yes, I got the impression from your explanation that even in the other parts the clock would stay directly software controlled. Though assisted by that control line and such for inversion. I'll just wait for the next videos then.
Hardware SPI Continued - IO from Scratch - Part 7
31:13
James Sharman
Переглядів 4,5 тис.
SPI (Bit Banging)- IO from Scratch - Part 4
30:04
James Sharman
Переглядів 9 тис.
когда одна дома // EVA mash
00:51
EVA mash
Переглядів 9 млн
Дурнєв дивиться сторіс ZОМБІ #47
53:48
Aleksey Durnev
Переглядів 698 тис.
This RISC-V cyberdeck is not for you
9:15
Jeff Geerling
Переглядів 220 тис.
Tile Data - VGA from Scratch - Part 13
1:00:34
James Sharman
Переглядів 15 тис.
Introduction to CPU Pipelining
10:29
Merlin Wellington
Переглядів 32 тис.
AMD ZEN 6 - Next-gen Chiplets & Packaging
16:37
High Yield
Переглядів 167 тис.
5 Ways To Generate A Sine Wave (Analog)
13:16
Sine Lab
Переглядів 74 тис.
Adding GPIO - IO from Scratch - Part 1
20:11
James Sharman
Переглядів 13 тис.
Why next-gen chips separate Data & Power
18:56
High Yield
Переглядів 112 тис.
Hobby Servomotors Could Be Much Better
15:11
Positive Altitude
Переглядів 37 тис.
#372 How to use the two Cores of the Pi Pico? And how fast are Interrupts?
14:25
Analogue In - IO from Scratch - Part 2
19:47
James Sharman
Переглядів 8 тис.
Нужно ли чистить ПК от пыли?
0:59
CompShop Shorts
Переглядів 106 тис.
M4 iPad Pro Impressions: Well This is Awkward
12:51
Marques Brownlee
Переглядів 4,6 млн
Лучший Смартфон До 149 Баксов!!!??? itel s24
20:25
РасПаковка ДваПаковка
Переглядів 45 тис.
Vortex Cannon vs Drone
20:44
Mark Rober
Переглядів 13 млн
Эволюция телефонов!
0:30
ТРЕНДИ ШОРТС
Переглядів 5 млн
The power button can never be pressed!!
0:57
Maker Y
Переглядів 23 млн