Close

PWM audio and High-speed I2C

A project log for DIAVOX Cellphone

Turning an old diavox phone into a cellphone. No smart stuff, just a telephone. Pick up the handset and dial just like the old days.

anders-helgessonAnders Helgesson 02/10/2025 at 21:130 Comments

I've changed my mind about using PWM audio, since I already have the DAC set up I'm going to try to use PIO to get a high-speed I2C interface for the DAC. I found two interesting PIO I2C implementations the pio-i2c-hs which is a High-speed I2C PIO implementation in C and the i2c-pio crate which implements the I2C hal using the RP2040 PIO peripheral.

Since the rust implmentation lacks documentation and examples how to use it. I'm not even sure if it can be set to use high-speed I2C. I'm going to use the PIO program from pio-i2c-hs and port the C code.

In the documentation for the pio-i2c-hs it mentions that to reduce jitter the rp2040 should be clocked at a multiple of 8*3.4 MHz = 27.2 MHz, and suggests to set the clock at 136000. I'm going to set it to 108800 underclocking the rp2040 instead. I have no heavy stuff going on so it should be fine.

I'm guessing that porting this to rust, the best way would be to make a new crate, then I could share it, and even use it for other projects.
I have no idea how to do that, how write tests and so on. It's a new Learning opportunity! The PIO program itself would be licensed under BSD-3 clause, I guess the rest of the rust code I could MIT license.

I have 4 free pins if I look at my pinout in the project treesheet.

Not sure if I need all the ones assigned to the modem so I'll use the first 2 pins I guess.

Now this is probably going to take some time but It's probably worth it. I could always fallback to PWM audio, SPI DAC or a wild thought, use PIO to SPWM two tones and mix these to make a DTMF tone.

Discussions