[ad_1]
Last 12 months for Hands On, I gutted a defunct TRS-80 Model 100. The aim was to improve its 24 kilobytes of RAM and a couple of.4-megahertz, 8-bit CPU however
hold the pocket book pc’s pretty keyboard and LCD display screen. That article was virtually solely about determining tips on how to drive its squirrely Eighties-era LCD display screen. I left the remaining, as they are saying, as an train for the reader. After all, sending a stream of information from a brand new CPU to the Arduino Mega controlling the display screen can be a trivial train, proper?
Hahahaha.
No, of us, no it was not.
IEEESpectrum’s Hands On articles present essentially linear variations of how initiatives come collectively. It may give the impression we’re terribly intelligent, which has about the identical relationship to actuality as an influencer’s curated social-media feed. So now and again I prefer to current a story steeped in failure, simply as a reminder that that is what engineering’s like generally.
To ship display screen information to the Mega, I had a selection between a number of strategies which might be supported by CircuitPython’s
show driver libraries. I wished to make use of a CircuitPython-powered microcontroller because the Model 100’s new mind as a result of there’s lots of present software program I may port over. In explicit, CircuitPython’s show libraries would vastly simplify creating graphics and textual content and would robotically replace the show. My selections had been between a parallel interface and two serial interfaces: SPI and I2C.
The parallel interface would require
at the least 12 wires. SPI was higher, being a four-wire interface. But I2C was better of all, requiring solely two wires! Additionally, there are many breakout boards that assist I2C, together with storage and sensors of all sorts. One I2C bus can, in concept, assist over 100 I2C peripherals. I2C is way slower than SPI, however the Model 100’s delightfully chunky 240-by-64-pixel show is slower nonetheless. And I’d used I2C-based peripherals many occasions earlier than in earlier initiatives. I2C was the apparent selection. But there’s a giant distinction between utilizing a peripheral created by a vendor and constructing one your self.
The Grand Central controller [bottom] supplies the brand new brains of the Tandy. Although the controller has the identical kind issue because the Arduino Mega, it has vastly extra compute energy.. A custom-built protect holds a supporting voltage-level shifter [top left] that converts the three.3- and 5-volt logic ranges utilized by the controllers appropriately.James Provost
On the circuit degree, I
2C is constructed round an “open drain” precept. When the bus is idle, or when a
1 is being transmitted, pull-up resistors maintain the traces on the voltage degree indicating a logical excessive. Connecting a line to floor pulls it low. One line transmits pulses from the central controller as a clock sign. The different line handles information, with one bit transmitted per clock cycle. Devices acknowledge when site visitors on the bus is meant for them as a result of every has a singular 7-bit handle. This handle is prepended to any block of information bytes being despatched. In concept, any clock velocity and or logic degree voltage may very well be used, so long as each the controller and peripheral settle for them.
And there was my first and, I assumed, solely downside: The microcontrollers that ran CircuitPython and had been computationally hefty sufficient for my wants ran on 3.3 volts, whereas the Arduino Mega makes use of the 5 V required to drive the LCD. An simple resolve although—I’d simply use a US $4 off-the-shelf logical degree shifter, albeit
a particular sort that’s appropriate with I2C’s open-drain setup.
Using a $40
Adafruit Grand Central board as my central controller, I related it to the Mega through the extent shifter, and put some check code on each microcontrollers. The most elementary I2C transaction doable is for the controller to ship a peripheral’s handle over the bus and get an acknowledgement again.
No response. After checking my code and wiring, I connected a logic analyzer to the bus. Out popped a stunning pulse prepare, which the analyzer software program decoded as a stream of appropriately fashioned addresses being despatched out by the Grand Central controller because it scanned for peripherals, however with no acknowledgement from the Mega.
An I2C is a comparatively low-speed bus that gives bidirectional communications between a controller and (in concept) over 100 peripherals. A knowledge and clock line are stored at a excessive voltage by pullup resistors The frequency of a clock line is managed by the controller, whereas each the management and peripheral gadgets can have an effect on the information line by connecting it to floor. A peripheral will take management of the information line solely after it has been commanded to take action by the controller to keep away from communication collisions. James Provost
I’ll skip over the following few hours of diagnostic failure, involving a lot gnashing of tooth and a useless finish involving a quirk in how the SAMD chip on the coronary heart of the Grand Central controller (and lots of others) has a hardware-accelerated I
2C interface that reportedly can’t go
slower than a clock velocity of 100 kilohertz. Eventually I connected the logic analyzer once more, and scrolling up and down by way of the decoded pulses I lastly seen that the bus scan began not at handle 0 or 1, however at 16. Now, after I’d picked an handle for the Mega in my check code, I’d seen many descriptions of I2C in tutorials that mentioned the doable vary of addresses ran from 0 to 127. When I’d checked out what appeared like a fairly complete description by Texas Instruments of how the I2C bus labored right down to {the electrical} degree, addresses had been merely described as being 7-bit—that’s, 0 to 127. So I’d picked 4, kind of at random.
But with the outcomes of my logic scan in hand, I found that,
oh, by the best way, addresses 0 to 7 are literally unusable as a result of they’re reserved for varied bus-management features. So I went again to my unique {hardware} setup, plugged in a pleasant two-digit handle, and bingo! Everything labored simply positive.
True, this headache was attributable to my very own lack of awareness of how I
2C works. The caveat that reserved addresses exist
can be present in some tutorials, in addition to extra detailed documentation from of us like Texas Instruments. But in my protection, even in the perfect tutorials it’s often fairly buried and simple to overlook. (The overwhelming majority of I2C instruction considerations the vastly extra widespread scenario the place a grown-up has constructed the peripheral and hardwired it with a wise handle.) And even then, nothing would have instructed me that CircuitPython’s heartbeat scan would begin at 16.
Oh effectively, time to press on with the improve. The relaxation must be fairly simple, although!
From Your Site Articles
Related Articles Around the Web
