Autodidact Ambitions 15 – Getting Back on Track

by | Aug 13, 2024 | Education, Pastimes, Technology | 83 comments

Puzzling over why the new chip wasn’t registering button presses derailed me for three weeks. I ran a bunch of tests to narrow down whether I used a bad button, had bad electrical connections, or just bad code. Ultimately, those tests all said it should be working. This is where my successes I listed in Part 13 come into play. Because my launchpad adapter was working correctly, I was able to use the debugging hardware on the launchpad and run the code in debug mode from my PC. What’s the big deal? One word – Breakpoints.

A breakpoint is a spot where the code will stop executing so you can examine the state of variables, and take manual control of advancing the logic to the next steps. How does this help me figure out why the button isn’t working? Well, the button is supposed to trigger an interrupt and run a short snippet of code that only triggers on a button press. By putting a breakpoint inside the interrupt, I know exactly when the chip registers an input on the pin I’m using.

After the button presses failed to trip the breakpoint, I did something crazy – I wired one of the output pins that had been lighting up LEDs to the input pin. Actually, it wasn’t so crazy. It gave me a reliable signal to make sure the chip was registering inputs. And it was. But the buttons when wired directly to LEDs worked just fine. So… it has to be a noisy signal. The chip sees an electricla mess on the input line and doesn’t register the kind of rising edge/falling edge signal that triggers an interrupt. We dealt with this issue all the way back in Part 9. I figured I should filter the button press through a hardware debouncing circuit and see what happens. Since I already had two wired up on the clock main board, I wired the clock into my breadboard contraption jumping three pins from the socket where the microcontroller was supposed to go.

All this for a button press

With a debounced button input, things worked the way my code was supposed to. Since my basic blinkenlights were working, I could turn my attention to the real time clock. Before I started looking at code, I did have to address a hardware issue. When I discovered that the MSP430 series could handle I2C at a low level, I hadn’t dug in as deep as I needed to. I acted as though you could use any two arbitrary pins. So I wired the pins from the RTC pin header to Pins 12 and 13 where the clock crystal would have gone, seeing some poetry in the assignment. But the only legal pairs were pins 4 and 5 or pins 16 and 17. Since 4 and 5 fell within the “Port 1” set of pins, I opted to bodge to 16 and 17. Mostly because it means later on I can just lift whole sections of the existing clock code, which uses Port 1 extensively. On the new chip, pins 16 and 17 are up in Port 4, where I haven’t had cause to wander so far.

I’ve been procrastinating doing another one of these, since new issues keep showing up.

Now, I need some data. The simplest solution is to make use of the square wave output pin on the RTC module at a rate of 1Hz to drive the existing clock code. The default is not 1Hz. I could do math on the 32KHz or feed it to the timers, but we already did that. This stage we’re looking at I2C, so I need to send a command to the RTC to set the frequency to 1Hz. According to my nots on I2C I need an address for the device. The datasheet says 0x68 – Check. I need the register identity to write to, and the value which will set it to that mode. Datasheet says… “Here’s how you download our Arduino Library”.

*Bleep* you, Adafruit.

But, somewhere in that Arduino library has to be the information I really need. C++ libraries are just text files. So I did a manual download, unzipped it, and started picking through their code. I found the code that sets the frequency.

void RTC_PCF8523::writeSqwPinMode(Pcf8523SqwPinMode mode) {
  write_register(PCF8523_CLKOUTCONTROL, mode << 3);
}

But how does that help, it just repeats what I already said I needed. Well, the names mean I can start doing Ctrl-F searches for the rest of the data. I found these:

#define PCF8523_CLKOUTCONTROL 0x0F
enum Pcf8523SqwPinMode {
  PCF8523_OFF = 7,             /**< Off */
  PCF8523_SquareWave1HZ = 6,   /**< 1Hz square wave */
  PCF8523_SquareWave32HZ = 5,  /**< 32Hz square wave */
  PCF8523_SquareWave1kHz = 4,  /**< 1kHz square wave */
  PCF8523_SquareWave4kHz = 3,  /**< 4kHz square wave */
  PCF8523_SquareWave8kHz = 2,  /**< 8kHz square wave */
  PCF8523_SquareWave16kHz = 1, /**< 16kHz square wave */
  PCF8523_SquareWave32kHz = 0  /**< 32kHz square wave */
};

For a few minutes I blanked out on what “mode << 3” meant. Despite using the << operator myself in other code. It does a bitwise shift three spaces to the left. After digging out the identity of the actual chip on the RTC module I found the datasheet for that. It had all of the registers and what the bits in them mean. Register 0x0F was Tmr_CLKOUT_ctrl and bits 3-5 were the ones which control the mode. Which explains the three bit shift on the mode. The other bits do stuff, but we want them set to 0.

So, we want to write 0x30 into register 0x0F on I2C address 068.

I’ve been avoiding it long enough. I need to face the Texas Instruments I2C code itself.

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

83 Comments

  1. Not Adahn

    I blanked out on what “mode << 3” meant.

    It’s the heart emoji, just more intense.

    • UnCivilServant

      Shouldn’t that be <<33?

    • Sean

      lulz

  2. Yusef drives a Kia

    10k resistor in series with button

    • UnCivilServant

      But I have two fully functional debouncing circuits right there.

      • Yusef drives a Kia

        Hindsight?
        Looks like fun no matter, I enjoy the series despite my snark
        Cheers!

  3. The Other Kevin

    Nice work debugging the buttons. You are learning, grasshopper.

  4. Sensei

    Is there a simulator available for this thing? Not that that will solve every issue. Just curious.

      • Sensei

        The board that’s actually running your code.

      • UnCivilServant

        I’m afraid not.

        The code is running on the chip in the middle of the board in the second picture.

        The launchpad is only a debugger and UART driver, the simulator for the launchpad similates the side that has been disconnected from this device. Everything else is custom hardware.

  5. WTF

    STEVE SMITH DEBUG HARDWARE!! AND BY DEBUG MEAN….

    • UnCivilServant

      remove insects without engaging in any euphemistic activities?

      • R.J.

        NO! THAT NO FUN!
        MEAN USE HARDWARE TO PENETRATE SOFTWARE UNTIL STEVE SMITH NEED CIGARETTE!

  6. Suthenboy

    Please excuse my dragging over from the ded thread so early. I am having trouble keeping up today. This is a bit on topic as it is the heart of the reason we are all here.

    kinnath gets it from last thread in his list of progressive lies.

    The study of things:
    Real things that exist have inherent attributes (individuals)
    Some things exist in our minds in a place because of the presence of inherent attributes (a mountain)
    Some things exist in our minds only because disparate things share attributes (sets or groups)
    Some things exist only in our minds and have no inherent attributes, only those we assign to them (institutions)

    To argue that a real thing with inherent attributes (individuals) should be sacrificed to serve a thing that does not exist (government) that ostensibly exists to serve the ends of another thing that does not exist (society) is irrational and evil. Why would create things in our minds that do not exist? The concept of a mountain we created because it helps people. Why would we create concepts that exist only in our minds if it does not help us? If governments do not serve the interests of individuals then why have them?

    For reasons I cannot understand the metaphor “gotta crack a few eggs to make an omelette” sounds almost like an acceptance of reality and appeals to people. Trouble is that I see a shit-ton of broken shells but I have yet to see an omelette.

    https://www.youtube.com/watch?v=tFkG6PIsTEs

    • Not Adahn

      UCS’s point of a form being a noun is correct (which is why you absolutely can step into the same river twice). The problem is that “society” as a model of emergent behavior is only descriptive or at best semi-predictive. But it gets treated as if it has prescriptive functions as well, which hoo boy.

    • The Other Kevin

      “Why would we create concepts that exist only in our minds if it does not help us?”

      As you said, there are fictions that do help us. For example, we (mostly) agree that pieces of paper represent something of value and so we have cash. But only SOME of us believe governments serve the interests of individuals, and therein lies the problem.

      • Nephilium

        /resists putting up the Hogfather quote again

        In general, people want/need something bigger than themselves to believe in. The problem is thinking that just because you want something, it exists the way you imagine it.

      • kinnath

        agree that pieces of paper represent something of value

        Not since 1964.

      • kinnath

        resists putting up the Hogfather quote

        bring it on!

  7. Not Adahn

    Hmmm. Looks like my NEXUS card is arriving today. My coupons for the P322 and the 97B are both still working their way though the system however.

      • Not Adahn

        Even were it so, it fits in a wallet, so that’s too small to have real fun with.

      • slumbrew

        You Nexus, huh? I design your eyes.

  8. WTF

    Well, this is good: 2nd Circuit Rules Lawful Gun Ownership Doesn’t Justify a Warrantless Search

    “No one will ever mistake the Second Circuit Court of Appeals for a gun-friendly bunch of jurists. So that should be a good indicator of just how egregious the violation of one man’s rights was that they have slapped down a cop for conducting a warrantless search of his car simply because he had a concealed carry permit and a gun. A three-judge panel also ruled that the cop in question isn’t entitled to qualified immunity because he so egregiously chose to violate the civil rights of someone without any discernible probable cause.”

    • UnCivilServant

      I saw that ruling, I’m surprised that they actually appear to have gotten it correct.

      • WTF

        The best part is no qualified immunity because of the obvious civil rights violation.

      • Not Adahn

        Soukaneh subsequently sued Andrzejewski

        *waves American flag*

    • EvilSheldon

      Nice news for a mediocre week.

    • Sean

      Odds that fucker still has a job carrying a gun?

      • Gustave Lytton

        And is being represented by the city in the personal trial because it arose out of his employment?

  9. The Late P Brooks

    Hieroglyphics in, hieroglyphics out.

    • UnCivilServant

      *Connects Rosetta Stone*

      Now it’s all Greek to me… 🙁

  10. The Late P Brooks

    So, anyway…

    Having finally found the carefully concealed (presumably) defective relay, I ordered a new one. While waiting for it to arrive, I mostly put the dash back together. I also pulled the cover off the old relay. There are a couple of solder joints which look not-so-good, including one with a hairline crack through it, between two pins. The sort of thing which might intermittently affect continuity under the right conditions.

    The new relay has arrived, so now I can put it all back together. I will relocate the relay. There is no way I’m going through the battle required to get it back into that hole. Then we’ll see if I can get a few thousand more miles out of it.

    • Sensei

      Click on! Click on!

  11. The Late P Brooks

    It could be worse

    Ford and Mazda have issued do-not-drive warnings covering more than 457,000 vehicles that contain recalled Takata airbags.

    According to a release posted on the National Highway Traffic Safety Administration’s website, Ford’s warning covers 374,290 model year 2004-2014 vehicles comprising a range of models that were part of previous recall campaigns. It also includes Lincoln and Mercury vehicles.

    Mazda’s warning covers 82,893 previously recalled model year 2003-2015 vehicles.

    NHTSA urges owners of the vehicles to not drive them until a repair is completed and the defective airbag is replaced.

    At least my car’s not trying to kill me.

      • Gustave Lytton

        Killing occupants isn’t a challenge to regulators’ authoritay.

    • Sean

      So much for that “pre-covid cars are better” thing.

    • R C Dean

      The thing is, if airbags were optional, I wouldn’t have them at all. I’ve been in one serious accident, in a pre-airbag Honda Civic (for you kids, the early 90s Honda Civics were compact cars, when that meant, pretty fucking small). I had my seatbelt on, not hurt at all. Near head-on collision at combined speed of at least 90 mph (black ice). Not even sore the next day. Everybody in the other car walked away, too.

      I had a parking lot accident in a GMC truck. Popped the airbag, which cut up my face – the only injury I’ve ever suffered in a a vehicle. I firmly believe based on this n of 2 that if you use the damn seatbelt, the airbag is a net negative.

      • Sensei

        It’s why all the race cars have them!

        However, passenger cars don’t have 4 or 5 point harnesses. I’ve been told submarining is a real issue in 4 point setups and they are best avoided.

      • Yusef drives a Kia

        Dale Earnhardt Sr. agrees

  12. The Late P Brooks

    To date, NHTSA says 27 people in the U.S. have been killed by a defective Takata airbag that exploded, while at least 400 people in the U.S. reportedly have been injured by them.

    It’s a good thing the government decided to make airbags mandatory.

    • R C Dean

      The thing is, even airbags working properly can cause (minor) injuries.

      • Pine_Tree

        What I’m occasionally concerned about is OLD ones. Like, I’m often driving around in a ’95 Ram pickup with the original airbag. Mrs. Tree is usually in a 20-year-old van. It sometimes crosses my mind that we should look into that risk, but have so far gotten distracted on other stuff.

  13. Ownbestenemy

    Nice work UCS. Really have enjoyed you sharing your journey with this project.

    • UnCivilServant

      There will be a bit of a hiatus when the clock starts working as I’m going on vacation.

      • SDF-7

        Enjoy being off the clock.

      • Sensei

        It was time.

      • Sean

        Good thing you warned us, wouldn’t want anyone to be alarmed.

      • R C Dean

        Any plans to pick up your forging work again?

      • UnCivilServant

        I want to but I still haven’t set up a suitable space to actually do it.

    • R C Dean

      If I were imposing a new Constitution, one of the things it would include is a lifetime ban on family members of elected officials holding elected office.

      • Nephilium

        Can we extend that to claiming the title to an office that the person is no longer in?

    • ron73440

      We should stop pretending and just issue patents of nobility to our betters.*

      *only if they are uniparty members of course

  14. The Late P Brooks

    intimidation

    The United Auto Workers (UAW) said Tuesday that it filed federal labor charges alleging former President Trump and Elon Musk attempted to “intimidate and threaten” workers during their Monday evening interview on the social platform X.

    “I mean, I look at what you do,” Trump told Musk. “You walk in, you say, ‘You want to quit?’ They go on strike, I won’t mention the name of the company, but they go on strike, and you say, ‘That’s OK, you’re all gone. You’re all gone. So, every one of you is gone.’”

    Federal law protects workers who go on strike from being fired, and it is illegal to threaten to do so, the UAW argued.

    “When we say Donald Trump is a scab, this is what we mean. When we say Trump stands against everything our union stands for, this is what we mean,” UAW President Shawn Fain said.

    Trump has sparred publicly with Fain and the UAW, which endorsed Vice President Harris last month for the upcoming presidential election.

    Following allegations of unfair labor practices, Musk’s SpaceX has directly challenged the constitutionality of the National Labor Relations Board in a move experts warned could hobble the agency charged with investigating allegations brought by employees, unions and employers.

    Hate speech and terroristic threats.

    • R C Dean

      Oh, FFS. I would say this will get laughed out of court because Trump didn’t direct his remark at the employees of any company. It shouldn’t even be actionable if he did do so, as long as it wasn’t a company he controlled. But the UAW knows where the friendly judges are, so . . . .

      • The Other Kevin

        New York here we come!

      • Gustave Lytton

        And if it isn’t, how is Fain’s statement also not a violation?

    • Suthenboy

      Fuck the UAW. They lost the high ground as did the govt when they got themselves exempt from laws that apply to every one else.

  15. The Late P Brooks

    “The record is clear. Donald Trump is all talk, but Kamala Harris has delivered for autoworkers,” Fain said in a video posted Monday by the UAW.

    Seriously?

    • OBJ FRANKELSON

      Apparently, the Dems still think they have the working class vote cornered.

      Who is going to tell them that it isn’t 1991 anymore?

    • Drake

      Delivered what? Seriously – will the UAW guys have any idea what is means?

      • Sean

        Delivered what?

        Record high inflation. Sluggish auto sales. Mass layoffs in the auto industry.

    • Suthenboy

      …and Waltz hits a hole in one every time when he plays golf. After delivering for the autoworkers Harris will volunteer to deliver babies at the local charity hospital.
      Neither one of them sleep you know. They have boundless energy. While we mere mortal serfs sleep they are going like a house a’fire saving lost dogs and solving the most perplexing scientific riddles.

  16. R.J.

    OK, I am preparing to move into a new stately R.J. manor. Signed contracts, now I just sold my beloved Creature from the Black Lagoon pinball to put towards costs. It went to a good home.

  17. The Late P Brooks

    Oh, FFS. I would say this will get laughed out of court because Trump didn’t direct his remark at the employees of any company. It shouldn’t even be actionable if he did do so, as long as it wasn’t a company he controlled. But the UAW knows where the friendly judges are, so . . . .

    I assumed they were going to the NLRB, which is likely to be highly sympathetic. As for an enforcement mechanism- who knows? Maybe they can issue a ruling prohibiting Trump and Musk from having control of any business entity with employees.

  18. UnCivilServant

    *Phew*

    😌

    Got through the performance goals meetings I think all my people are on the same page.

    The people part of managing is hard

    • Mojeaux

      I would not want to manage people. I’m shit at setting out expectations with concrete explanations. Was there a common denominator problem that had to be fixed?

      • UnCivilServant

        One of my guys is solid. The other needs to work on communication clarity (ugh, not easy to guide someone through) and is lacking initiative, so I’m going to have to keep a closer eye on whether that one is actually working.

      • UnCivilServant

        I got lucky early on in that so many of my people could just be pointed at a problem, given some instruction on tech and/or expectation and let loose on it.

      • Mojeaux

        Oh, I thought you had said you had several PIPs to hand out.

      • UnCivilServant

        We’re not to the PIP stage. This is regularly scheduled Performance Evaluation stuff.

      • Not Adahn

        Is the intern that hands out your PIPs your PIP-boy?

      • UnCivilServant

        Oh, no, you can’t just do that off the cuff.

      • Mojeaux

        Oh, I always hated those. “Tell me what you think you brought to the team above and beyond…” “Um, I have no opportunity to go above and beyond. I show up on time and I do my job.”

      • Nephilium

        Mojeaux:

        For me it’s, “The customer is still happy, and paying for my role, right?”

      • UnCivilServant

        Thankfully this is the setting standards and goals for the coming year stage. Plus, I’d hate to go through those kinds of nonsense from the manager end. So I’d never influct that upon my people.