Update on Forth RP2040 I2C Driver Project

I am still working on the I2C driver project during my lunch breaks, to utilize the built-in circuitry for I2C communication on my Rpi Pico, for Mecrisp Stellaris Forth. The code (WIP) is available on Codeberg:


In the process, I wrote diagnostic words to display...

- the GPIO function settings (from the GPIO_CTRL register)

- the GPIO pad settings

- the settings in the I2C0 control register

And I wrote words to configure the GPIO pins appropriately, and to set the speed mode for I2C0. Now I am working on a word to selected master or slave mode. At the present, I am focusing just on I2C0, the first I2C module the RP2040, although there is also an I2C1 available. I keep the diagnostic words compiled into flash, so they are always available after a reset, and then I just load the I2C driver code into RAM for testing and troubleshooting.

As I've mentioned, (Mecrisp Stellaris) Forth makes for a pleasant microcontroller development experience, because you get a very interactive experience, while still being able to write directly to all the mapped memory, including all the memory-mapped registers. I find Forth code to be straightfoward to troubleshoot, because most of the time you can just layout the words on a piece of paper (or text editor) along-side notes tracking the stack effects, and you have a pretty clear view of what is going on. Also, since the syntax is so simple, you can just run all the words a word-at-a-time in the interpreter while checking the stack, except of course that you have to handle manually the effect of compile-only words like conditionals.

I got hung up for quite-a-while troubleshooting the word which sets the the I2C speed — my code seemed to be having no effect on the register. In the end I figured out that it was not actually my code, but rather something I didn't understand in the microcontroller itself. Per the datasheet, you can set the RP2040 to standard, fast, or high speed I2C mode. However, if you look at the fine print, there is some kind of configuration setting (hardwired? burned?) into the chip (or the microcontroller board...?) such that it has a MAX_SPEED_MODE, which apparently on my Pico is set to fast speed mode. If you try to set the register to a higher speed setting, the hardware will automatically set it back down to the highest speed actually supported. So, I was trying to set it to high speed mode, but I was only seeing fast mode, so it looked like nothing was happening.

Anyway, it has been fun working on this, though sometimes I wish could just focus on this one project and get it done in a day or two, rather than having to spread it out among a few dozen lunch breaks.

Proxied content from gemini://gem.librehacker.com/gemlog/tech/20220727-0.gmi

Gemini request details:

Original URL
Status code
Proxied by

Be advised that no attempt was made to verify the remote SSL certificate.