We’ll make two one-line changes to a program that works, and capture each resulting I2C transaction with the AD2. Both yield a blank display, but they look nothing like each other on the AD2.
To tell the two apart we’ll use the AD2’s logic-analyzer mode, which decodes I2C for us. It shows the address, the R/W bit, the ACK and the data as values rather than edges, which is a much faster way to answer “is this device answering at all?” when you are debugging.
Logic mode reads the AD2’s digital channels, not its scope channels, so before we use it we’ll need to rewire. Three more leads go onto the bus: DIO0 to SDA, DIO1 to SCL and a ground lead to ground (Figure 10.3.34). The scope leads can stay where they are. Figure 10.3.35 and Figure 10.3.36 are the setup in Waveforms.
Figure10.3.34.The AD2’s digital channels are the larger flying-lead bundle (left, plugged into the AD2), and the pinout sheet (right) says which lead is which: the digital leads are numbered (lead 0 is DIO0, lead 1 is DIO1), and the ground leads carry the ⏚ symbol. Three leads go onto the bus: DIO0 (pink, lead 0 on the sheet) to the SDA row, DIO1 (green, lead 1) to the SCL row, and a ground lead (black) to ground. (The sheet is drawn for the ADALM2000, a related Analog Devices instrument. The digital numbering, colors and grounds are the same; only the trigger pins are named differently.)
Figure10.3.35.Getting the two signals on screen in Waveforms’ logic mode. The AD2’s digital channels, the larger flying-lead bundle, go DIO0 (pink) to SDA, DIO1 (green) to SCL and black to ground. Six steps: add DIO0 and DIO1 as signals, set the time base to 20 µs per division, click to make DIO0 falling the trigger, take a single sweep, use the cursors to measure the clock period, and drag the view so the start bit is at the left.
Figure10.3.36.Then the decoder itself, three more steps: add an I2C bus with DIO1 as clock and DIO0 as data, set DIO0 falling as the trigger again, and take another sweep if the old trace disappears. The decoded row reads the transaction out directly: h70 WR, its ACK, the data byte, and its ACK. The decoder splits the byte for you: h70 is the 7-bit address and WR the R/W bit, together the 0xE0 you read by hand yesterday. (The data byte in this screenshot is hBE, because it was captured with a different value in the program; yours will differ.)
The AD2 also has a logic-analyzer mode that decodes I2C for us: it shows the address, the R/W bit, the ACK and the data as values rather than edges. It reads the AD2’s digital channels, the larger flying-lead bundle, so we’ll need to rewire first:
The digital leads are numbered on the sheet (lead 0 is DIO0, lead 1 is DIO1), and the ground leads carry the ⏚ symbol.
Logic mode, not oscilloscope mode: add DIO0 and DIO1, time base 20 µs/div, DIO0 falling as the trigger, single sweep.
Then add an I2C bus (DIO1 as clock, DIO0 as data) and the edges become values: h70 WR, ACK, the data byte, ACK. The decoder splits the byte for you: h70 is the 7-bit address and WR the R/W bit, together the 0xE0 you read by hand yesterday. (The data byte here is hBE, captured with a different value in the program.)
Figure10.3.40.One I2C transaction that got no answer, captured in logic mode with SCL on DIO1 (green) and SDA on DIO0 (pink). The decoder reads h60 WR (the 7-bit address 0x60 and a write), then NACK: on the ninth clock pulse SDA stays HIGH, because no device on this bus has address 0x60. Then Stop. Nine clock pulses in all against the eighteen of Figure 10.1.16, and then the bus is idle. The Waveforms settings used for the capture are in the toolbar at the top.
Put the AD2 on SDA and SCL in logic analyzer mode with the I2C decoder on, as set up above (Figure 10.3.36). Work on a copy of helloDisplay.c so that your project stays intact. After you flash each change, you may need to briefly disconnect power from the display, so that it shows the result of the code you just flashed.
Put the address back to 0x70. Now comment out the first of the three command writes, the one that turns the oscillator on, and predict what you will see on the display and on the trace. Then flash it and capture.
Done early? Leave the oscillator command commented out and add it back at the end of the three, after the display-on and brightness commands. What does the display do, and what does that tell you about the HT16K33?
Flashing code resets only the STM32C031C6, not necessarily the display, unless your new program correctly rewrites the display memory and its settings.
If it does not, the display keeps its RAM and its settings (such as whether its oscillator is on) and goes on showing them for as long as it has power.
Flashing code resets only the STM32C031C6, not necessarily the display, unless your new program correctly rewrites the display memory and its settings. If it does not, the display keeps its RAM and its settings (such as whether its oscillator is on) and goes on showing them for as long as it has power, so without the power cycle you may be looking at the last thing that reached the display rather than the result of the code you just flashed.
The wrong address. With 0x60 the program runs as it did at 0x70, four transactions a second, and every one of them looks like Figure 10.3.40. That is because of how the library handles a NACK: RM0490 §23.4.9 is explicit that on a NACK “the TXIS flag is not set”, so a wait on TXIS alone would never end. i2c1_byteWrite() waits on TXIS or NACKF, whichever comes up first, and writes the data byte only if it was TXIS. The same paragraph of the manual goes on to say that after a NACK “a STOP condition is automatically sent”, which is why the capture looks tidy, and the library waits for that STOP before it returns. Because i2c1_byteWrite() returns void, the rest of the program has no way to find out that nobody answered, so the only symptom is the blank display. A more advanced library would return a value that indicates the type of failure that has occurred. Subsection 10.4.9 has the detail.
The missing oscillator command. The display is blank, the same blank as a wrong address, the same blank as a wire that fell out. The trace is perfect: every transaction is there, every address byte is 0xE0, every ninth pulse comes back LOW because the HT16K33 is powered, listening, and acknowledging every single byte you send it. It simply is not driving anything: the oscillator, as in Part 8b.
Even with a correct address the device can still do nothing (as you noticed with the missing oscillator-on command). In this case the AD2 only answers “did my bytes arrive?” but it cannot answer “were they the right bytes to send?” That question is a datasheet question and needs to be looked up in the command table. Carefully choosing your debugging method - AD2 versus datasheet in this case - rather than reaching for whichever tool is nearest, will make your debugging much smoother.
Recall that there are two blocking while() loops in i2c1_byteWrite(): with an incorrect address, the first loop exits on a NACKF (the TXIS flag is not set). Following a NACKF, a STOP condition is automatically sent, which causes the second loop to exit.
Because i2c1_byteWrite() returns void, the rest of the program has no way to find out that nobody answered, so the only symptom is the blank display. A more advanced library would return a value that indicates the type of failure that has occurred.
Even with a correct address the device can still do nothing (as you noticed with the missing oscillator-on command). In this case the AD2 only answers “did my bytes arrive?” but it cannot answer “were they the right bytes to send?” That question is a datasheet question and needs to be looked up in the command table. Carefully choosing your debugging method - AD2 versus datasheet in this case - rather than reaching for whichever tool is nearest, will make your debugging much smoother.