Autodidact Ambitions 11 – Super Serial

by | Jul 9, 2024 | LifeSkills, Pastimes, Technology | 124 comments

My investigations into why the clock won’t keep time await new parts, so I’m going to take a detour while I wait.

In part 10, I mentioned that one of my ideas revolved around using a premade Real-Time Clock module to drive the timekeeping. Every RTC on the market, whether it’s a single chip or a small expansion board, uses some form of serial communication to provide the main device with data. Since all of them contain full calendaring information including months and years, alternatives to serial communications are not viable. There are a shedload of ways to handle it, but I’m only going to talk about two of them – Serial Periferal Interface (SPI) and Inter-Integrated Circuit (I2C). Both date from the early 1980s and are widely supported standards. SPI came out of Motorola, while I2C was introduced by Phillips Semiconductor, but are manufacturer agnostic standards.

Both are Master/Slave setups ultimately interested in trading data between the microcontroller/microprocessor and whatever periferal device its trying to access and transfer one bit at a time per data wire. Neither is strictly better, which is why both have persisted for over four decades. Each has its own strengths and weaknesses. I read up on the details in anticipation of having to implement them myself. I knew enough to be confident in getting an SPI compliant code written, but had to look for I2C examples. When I found them, I discovered that the MSP430 series implements a number of serial protocols at a very low level, including both SPI and I2C, so I don’t have to write either. However, having learned the basics of how these protocols work, I had a bunch of ideas. Since the MSP430s can be used as either a master or slave device in either of those protocols, I can expand upon the modular idea from the Pluggable MSP to simply building periferal modules outright and not having to manage everything from a single microcontroller.

But that’s for the future. Today, I’m going to discuss the protocols.

I’m going to start with SPI, because it was the first I got my head around. The first obvious difference between SPI and I2C is that SPI uses at least four wires, while I2C uses exactly two. Two of the SPI wires are for signalling, and two for data. The signalling wires are Chip Select and the Clock signal. Like with the clock signals we used for shift registers, the clock tells the periferal when data is to be exchanged. The chip select line indicates to the periferal that it should respond. Because the chip select line is only ever high or low, this is where the ‘at least’ four lines comes in. Each SPI periferal needs its own chip select signal. However, that doesn’t mean we’ll be eating up another valuable pin for each SPI device we want to add. Even if we just stick to things already covered in these articles, we can stack shift registers to control an arbitrary number of chip select lines. It’s crude, and I’ve been reading about multiplexers and demultiplexers, which have some more fun (and faster) options for controlling more lines. Ultimately you won’t need more than six total pins to talk to an arbitrary number of periferals. Whatever funky addressing schema you can dream up will do you.

So what does that leave? The two data lines. These are known as the MOSI and MISO lines. Or Master Out/Slave In and Master In/Slave Out. The names really do say it all. Each wire carries data in one direction, driven by the clock signal to determine when the next bit is sent.

The MISO and MOSI lines do not typically line up like this.

The SPI protocol defines how to read the signalling and the data bits but does not dictate the content of the data. The periferal manufacturers can decide how to handle that. For example, one device I have is a thermocouple driver. Basically, the logic end of a thermometer. When you trigger its chip select and start sending a clock signal, it ignores the MOSI line and sends a data packet on the MISO line which consists of the temperature on the probe, the controller’s temperature, and any error flags it has. It will only send one of these per activation, and always sends that format. It is just a thermometer, it’s got one function. I’ve also read up on a FRAM chip that uses SPI. It requires you send it a command, then an address. After the address, it will either listen for bits to write to that address, or start sending bits read from that address. It will keep incrementing its address as you keep sending clock signals, allowing for an arbitrarily long read or write. Those Real-Time Clocks which use SPI are somewhere in between, with fixed packet sizes but requiring commands and addresses so that it knows what you want to do between setting the time, setting alarms, or reading some element from it.

I2C is starkly different from SPI in that is only ever uses two wires, with most of the signalling going on the data wire. It still uses a clock signal on one of those wires, to keep the master and slave working in tandem. Since you don’t have the luxury of dedicated wires for additional signals, the data packets on an I2C bus are bracketted by start and stop indicators which are created by the relative timing of the data and clock lines going to particular levels. These start and stop signals fell into the “I’m going to need a reference” sort of deal where I would have to look up the details every time it matters. But, once a start signal is indicated, you now have the attention of every slave device on the bus – how do we indicate who we’re talking to? The first byte of data sent from the master after the start contains an address. This address value indicates which periferal we are trying to reach.

Other people draw nicer diagrams than I could
I think it leaves out a few steps.

While the addressing on a logical level allows for quite a few connected devices, you will run into one practical hurdle. The address number of a periferal is set by the manufacturer, and is often impossible to change. So you can’t use more than one periferal of the same type from the same manufacturer. They would simply all answer and cause chaos on the data line. After the address byte, the periferal with that address sends a single bit back along the same data line to acknowledge that it is there and listening. The master then sends a command byte, which is followed by another acknowledgement by the slave. After the command, who is talking in what order depends on the type of periferal and what command the master gave. Each byte gets acknowledged until the master goes ‘stop’.

While I2C cuts down on the hardware complexity by getting rid of the need to manage chip select signals and only ever using two wires, it does so by increasing the complexity of the data protocol and imposing some limitations. SPI is full duplex, meaning both master and slave can be sending data at the same time. Each line is also unidirectional, so you never get the issue where more than one device is trying to drive the line at the same time.

What you want to use is all about trade offs. Since each has its benefits and drawbacks, they’ve comfortably coexisted for almost as long as personal computing has been around.

The RTC modules I ordered use I2C. After all, how many clocks do you need? Hopefully next time, I’ll get to share what my daughterboard designs managed to achieve.

About The Author

UnCivilServant

UnCivilServant

A premature curmudgeon and IT drone at a government agency with a well known dislike of many things popular among the Commentariat. Also fails at shilling Books

124 Comments

  1. UnCivilServant

    I’m running low on these queued up – I have to get something working on the most recent hardware.

    • Ownbestenemy

      Does the hardware look like this?

      • Sensei

        That’s a winner. Love the label on the IC.

      • UnCivilServant

        No, that’s far too orderly.

      • OBJ FRANKELSON

        The 3L capacitor made me chortle.

  2. Fourscore

    It ain’t the Time Division I learned about 65 years ago. Sort of looks the same when it’s graphed out but and no modulation.

    Thanks USC, for reminding me how far behind the curve I really am.

    • UnCivilServant

      These are newer protocols from the 1980s.

    • trshmnstr

      The modern stuff (QAM) is fascinating.

  3. Gustave Lytton

    From the ded thred. Been watching inspection videos on YouTube. It’s is… shocking.

      • Tundra

        I can’t watch any more. Horrifying.

        The new code thing where you can’t put outlets on the side of the kitchen island is fucking stupid.

      • UnCivilServant

        Where are you supposed to put the outlets for the stand mixer? On top of the island where spills will get fluids into the outlet?

      • Tundra

        Yep. Or some kind of two tier island. It’s just getting ridiculous.

        And further, as Gustave’s link shows it makes no difference because the builders get it wrong anyway.

        I’m still shaking my head about the low voltage bundle routed around the joist. Unreal.

      • slumbrew

        Just notch out the joist. Problem solved.

        /derp

      • Gustave Lytton

        Just build a chase around it.

        /not really sarc

        The NEC is out of control. The 3 year cycle ensures and demands that changes be made to justify the cycle. From the licensing perspective

        Year 1 – changes announced/discovered in new code but not yet adopted or in CE classes
        Year 2 – new code adopted, code update classes released. God help you if you work in two separate states/code juridctions
        Year 3 – new code used
        And then repeat. Basically 1-2 years at most of everyone mostly being on the same page.

      • slumbrew

        I assume they’ll build around it vs. re-pulling the bundle. So it’ll look like shit but be functional.

      • OBJ FRANKELSON

        My BIL just showed me a picture where the plumbers cut a hole for two 3 or 4 inch sewerlines through the main load bearing beam. Staggeringly dumb things like that happen all the time.

    • UnCivilServant

      The math to adjust for time zone is cheaper and easier to implement than running and synchronizing twenty-four RTC modules.

  4. Yusef drives a Kia

    Multiplexing solves the need for excess wiring, I have ran light shows with as few as 5 wires, synced to music as well

      • Yusef drives a Kia

        1 line per array, I had several doing different things

    • UnCivilServant

      More seriously, I was looking at demultiplexers for the chip select line for the SPI devices.

  5. The Late P Brooks

    What about too low for too long?

    Federal Reserve Chair Jerome Powell on Tuesday expressed concern that holding interest rates too high for too long could jeopardize economic growth.

    As long as government spending is completely unconstrained, GDP will keep going up.

    • The Artist Formerly Known as Lackadaisical

      ‘growth’

    • The Last American Hero

      If you haven’t seen Touching the Void, do so. If it didn’t include testimonies from the actual climbers, you’d say Hollywood pushed the suspension of disbelief too far.

      • Yusef drives a Kia

        Into thin air
        Everest the hard way
        Many more, I always wanted a 6k meter peak. Annapurna comes to mind

  6. Ownbestenemy

    Ah…timing and clocks. Fun fact, most of the radar processing systems I work(ed) on operated on a 2.67 MHz clock

    • UnCivilServant

      This clock has been taking too long to get working properly.

    • UnCivilServant

      The problem is Ted’s Fish Fry isn’t that good. I don’t know how they stay in business.

      • Not Adahn

        Money laundering and/or political favors, if they’ve made it for 75 years.

    • kinnath

      Sounds like a threat to me.

    • The Other Kevin

      I have said it before and I’ll say it again. Biden and/or his team are absolutely terrible at politics.

      • Ownbestenemy

        Its the team for sure. Given the photo floating around of his speechwriters, I am guessing the campaign is staffed with 20 something year olds.

      • Nephilium

        Ownbestenemy:

        They’re so invested in “fighting the man” they don’t realize they are the fucking man at this point.

      • kinnath

        They believe this photo is an intimidating way to turn the tables on the Let’s Go Brandon crowd. They’re not looking to recruit new voters to their side. They are feeding their own echo chamber.

        And they completely fail to recognize that this just confirms the beliefs of the MAGA crowd that Biden’s team is both stupid and dangerous.

      • EvilSheldon

        The left, even up into the rulership positions, is populated largely with emotionally immature pseudo-adults who throw tantrums when they don’t get what they want. This is another tantrum.

      • Ownbestenemy

        @Nephilium – So 90s Pop Punk Rockers?

      • Nephilium

        OBE:

        I’m happily settled into my role as the man. There’s a reason that the Descendents Suburban Home is such a great song.

      • Tundra

        I definitely hear that song differently as an old man. They are coming here in November. I think I’ll take my daughter.

      • R C Dean

        I don’t think they are “fighting the man” so much as they are “fighting the orange man*”.

        *who is bad, very bad

      • Timeloose

        Who is stupid enough to be excited by the Dark Brandon meme? Someone too young to recognize what a Nazi rally or a thousand recreations in modern media looks like?

        Go watch what a real Fascist or Totalitarian dictator rally looks like. One that has A/V messages crafted to make you feel like the person is all powerful. Then ask your self why they would want to promote that message to you for this president?

    • The Artist Formerly Known as Lackadaisical

      I can’t believe they’re really leaning into that dark Brandon thing.

      It’s literally a way to call him evil.

      • rhywun

        Their base: “And?”

    • The Other Kevin

      I have no interest in Big Mike’s banana.

      • Not Adahn

        Yes, but $17 is less than downtown!

  7. PieInTheSky

    the goddamn tik tok culture war is getting to me. A young woman hiking in the mountains in Romania was attacked and killed today by a brown bear and the first thing I thought about was the stupid man vs bear thing.

    Funny enough there was a man hiking a couple hundred meters behind her who saw the attack and reported it.

    • PieInTheSky

      the comments are split between the bear should be hunted and it is not the bear’s fault, it was in its enviroment and briwn bears do not attack unprovoked. There have been plenty of attacks though recently. There has been like a 7 year moratorium on hunting which increased the population, coupled with bear coming near humans looking for food.

      there was a comment saying the man should have tried to fight the bear to save the woman.

      Romania has about two thirds of the E.U. bear population.

      • Not Adahn

        I could really use a rug for the bedroom. Got a source for that?

      • Not Adahn

        Alternative joke: I thought Greeks and Turks were more bear-y than Romanians.

      • UnCivilServant

        Crazy Hamid’s Grounded Rugs?

      • UnCivilServant

        The Aegeans are Werewolves, all descended from Lycaon.

        It is known.

      • EvilSheldon

        If it’s not the bear’s fault, who’s fault is it? (Don’t answer that, I reached my quota for stupidity today before lunchtime.)

        Y’all have some pretty mountains, though.

      • ZWAK came for the two-fisted tentacle-fighting, stayed for the crushing existential nihilism.

        Not the bears fault? So, are you saying there otter be a law?

      • Timeloose

        Was the woman wearing a short skirt made out of honey and trout?

      • kinnath

        Are you implying she had a honeypot?

      • Suthenboy

        All wrong questions.
        Right question: Was the woman armed? I think I know the answer.

      • kinnath

        Like watching your mother-in-law wrestle with bear — entertaining even if you don’t care who wins.

      • Not Adahn

        “After we know our numbers exactly, we can talk about the long-term strategy,” Fechet said. “We will have to remove the excess number of bears by one way or another.”

        Deport them?

      • PieInTheSky

        Deport them to Ukraine to fight in the war against the Russian bears. Russian have the numbers though more than 100k

      • Sean

        You need better signage.

        “No bear attack zones”

      • Nephilium

        Sean:

        So they have a right to regulate bear arms?

      • Sensei

        Just pass a law designating certain areas “bear free zones”.

      • ZWAK came for the two-fisted tentacle-fighting, stayed for the crushing existential nihilism.
      • The Artist Formerly Known as Lackadaisical

        @NA

        Its time for other EU countries to take their fair share of bears. Anyone who fishes is racist against browns.

    • PieInTheSky

      Update the bear has been shot by the rangers that went to try to recover the body, who were armed. the victim was apparently 19 female.

      Shit like this is why I would not hike alone.

      • Timeloose

        I’m going to Alaska next week to hike and sightsee in the Denali Nat. Park. I hope to see but not experience brown bears in the wild. The black bears in my neck of the woods are nowhere near as aggressive or large.

      • Gender Traitor

        And be sure to hike with someone who runs more slowly than you.

      • EvilSheldon

        Not hiking alone kind of defeats the whole purpose of hiking.

        That said, don’t be stupid about it. Buy and use an emergency locator beacon, leave a copy of your itinerary with someone, and have necessary emergency equipment with you.

      • Timeloose

        Thanks GT and Tundra. Maybe Animal will let me borrow a 10mm for the week. My guide is supposed to carrying bear spray, I hope a rifle as well. I will not be able to bring my own as it is at the bottom of a lakeriverpond in Schnecksville.

      • Tundra

        Not hiking alone kind of defeats the whole purpose of hiking.

        Unless it’s one of those things that keeps your family tight, however.

        I dig hiking with my wife. We have very different interests, but both love getting out into the mountains. The kids, too. Grown and gone but still like to do our summer hiking trip with us.

        But I agree – there is something groovy about a solo hike. No way I would do it in Grizzly country, though.

      • Tundra

        My guide is supposed to carrying bear spray

        Get some for everyone in the group. I’m pretty sure I’ve rented it before, since obviously you can’t fly with it.

        I’m really jealous. We’re at like 25 NPs but haven’t made it to AK yet.

      • Nephilium

        EvilSheldon:

        I do that even when I’m just going for a bike ride around the neighborhood. I let the girlfriend know when I’m heading out, when I’m heading back, if I changed route, and the like.

      • Yusef drives a Kia

        I’ll hike with you, I’m faster….

      • Timeloose

        I’ll see what I can do with buying spray when we get there. I’ll be there with my wife and MIL as well as about 5 others in our group. I also want to bring a multitool and some other handy stuff in my checked bag. I don’t like not having tools.

      • Timeloose

        I picked up a new pair of hiking boots from Oboz. They appear to make quality water proof stuff that is in the sweet spot of affordability and quality.

        https://obozfootwear.com/en-us

      • Tundra

        Good stuff.

        I’m a fan of Darn Tough wool socks, too. Even with waterproof shoes.

    • ZWAK came for the two-fisted tentacle-fighting, stayed for the crushing existential nihilism.

      When it absolutely, positively, has to be spied on overnight.

    • EvilSheldon

      I’ve set up accounts at UPS and FedEx just so I can have my shit delivered to the local independent Mailboxes, Etc. knock-off. Very convenient, secure, and keeps the undesirables away from my apartment.

    • UnCivilServant

      Who Isn’t spying on you?

    • Not Adahn

      Speaking of FedEx and lists, my new holster arrives tomorrow!

  8. kinnath

    Awesome

    https://nypost.com/2024/07/09/us-news/supreme-court-justice-sotomayors-bodyguard-shoots-would-be-carjacker-outside-her-home/

    Supreme Court Justice Sotomayor’s bodyguards shoot would-be carjacker outside her home

    Two deputy US Marshals shot a would-be carjacker who pulled a gun on him while they were guarding Supreme Court Justice Sonia Sotomayor’s home in Washington, DC, authorities said.

    The marshals were parked outside Sotomayor’s home in northwest DC on July 5 when Kentrell Flowers, 18, allegedly walked up to one of their cars around 1:15 a.m. and pointed a gun one of the federal agents, the US Marshals Service told The Post.

    Nice neighborhood.

    • Sean

      Stay away from the comments.

      • kinnath

        Now, I feel compelled to go read them.

      • Timeloose

        Looked like a mix of stupidity about gun control and people supporting 2nd amendment rights. By the way, what kind of attachment is that under the barrel, a laser or flashlight? Looks like a POS.

    • Brochettaward

      Why the fuck does Sotomoayor have an armed guard of US Marshalls outside her home 24/7?

      Not to mention the old cliche. She’s the cunt who wants to take your right to defend yourself but surrounds herself with armed men.

      • Tonio

        USMS Judicial Security Division does their thing. But 24×7 protection generally is only when they’re travelling, or there is an elevated threat level.

    • Not Adahn

      One of the federal agents drew his weapon and fired several shots at the suspect, with the second officer also firing his weapon at Flowers.

      Flowers, of Southeast DC, was arrested and treated at a local hospital for non-life-threatening injuries, officials said.

      Bad feds!

    • OBJ FRANKELSON

      Who will give me odds on if she has the self-awareness to see why making people easier to victimize by disarming them might be a bad thing?

      • kinnath

        not
        gonna
        happen

      • UnCivilServant

        Won’t even cross her mind.

      • Suthenboy

        Making people easier to be victimized is the whole point of gun control. It’s a win-win for them. they cant resist govt thuggery and high crime keeps the people demoralized and beaten down.

        Make no mistake – gun controllers have malicious intent. If they did not and had sound arguments they would not lie EVERY SINGLE TIME they open their mouths.

  9. The Late P Brooks

    One of the federal agents drew his weapon and fired several shots at the suspect, with the second officer also firing his weapon at Flowers.

    Flowers, of Southeast DC, was arrested and treated at a local hospital for non-life-threatening injuries, officials said.

    Qualified professionals.

  10. The Late P Brooks

    Did they go door to door to check for collateral damage?

  11. Tonio

    Inquiries are being made about the lack of links.

    • kinnath

      lack of links

      pit of despair

      • SDF-7

        Don’t even think of trying to escape.

    • KK, Plump & Unfiltered

      Passive voice is being used 😂

      • Tonio

        You know me all too well, chiquita.

    • KK, Plump & Unfiltered

      I have something juicy for OMWC, too. Not that he reads the site.

      • rudimentary teats formerly known as pistoffnick (370HSSV)

        Red meat?

      • The Artist Formerly Known as Lackadaisical

        I heard he likes veal.

  12. Suthenboy

    Bears and hikers: If you hike in bear country the necessary equipment includes this – https://www.smith-wesson.com/product/model-69

    If you are unarmed and get eaten…well, sorry to hear that. Really not all that different than the loons that jump in bear enclosures at the zoo to pet the bear and apologize for global warming.

    • The Artist Formerly Known as Lackadaisical

      Eh, I’ve done it. If I died then it would have been my own fault, no big deal and not anyone else’s business.

  13. The Late P Brooks

    Passive voice is being used

    Balls were dropped.

    • kinnath

      Deadlines were missed

  14. Evan from Evansville

    “For example, one device I have is a thermocouple driver.” Damn. I’d be tempted to start every first impression with that. I wouldn’t, because reality, but I’d *long* to.

    It’s embarrassing and refreshing to read this. I understand the words, and have a vague sense of some of the basics (read: monstrously little), and put together, *literally* none of this makes sense. I wouldn’t be able to describe “What I’m reading” to someone if they asked. On the plus side, I do enjoy knowing how folks’ brains all work differently.