kellerkindt / pcd8544

Apache License 2.0
6 stars 8 forks source link

Rate limit bitbanging in write_bit() for fast boards, or use SPI #9

Closed basdusee closed 2 years ago

basdusee commented 2 years ago

Hi, thanks for the beautiful library.

There is an interesting problem using your library on a Raspberry Pico wich has the rp2040 chip. This pcd8544 library doesn't give any output to the screen on this chip/board.

I think it is because of the speed of the rp2040, but I'm not really sure. The chip does 125mHz clock speed and has SIO (Single cycle IO) on its GPIO's. write_bit() doesn't have any rate limiting. I didn't measure it but with only three pin changes (din high or low, then clk high, then clk low), it might be that the rp2040 is bombarding the pcd8544 with an 125/3=41MBit/s, and the pcd8544 can only digest 4Mbit/s max.

Looking at the code of the Micropython guys and Rust code from a githubber named Dancek, it's also possible to use an SPI clocked at 2Mbit, with plarity=0 and phase=0. It replaces CLK and DIN for an SPI interface. This is what I did and got it working on the rp2040, but rate limiting the write_bit() function to <4MBit/s somehow could work just fine also, I think.

To be honest, I'm not completely sure if the speed is the problem, never measured it with an oscilloscope or something, but changing to a rate controlled SPI got stuff working.

basdusee commented 2 years ago

Never mind, duplicate with closed issue https://github.com/kellerkindt/pcd8544/issues/4 I haven't figured out a way to do it with raw gpio either, tried delays with NOPs, (cortex::asm::NOP), but it didn't work. Probably the compiler just optimizes the NOP away or something.

Sorry to bother you, will check closed issues better next time.

basdusee commented 2 years ago

To whom it might concern, I ended up forking the andreyk0 fork of this repo (https://github.com/andreyk0/pcd8544). He created a nice solution with a bitbang SPI implementation which can be used as a drop in replacement for the STM32 boards, and changing the overall connection to the PCD8544 to SPI. This code should be in this repo via a PR from github user hmvp, but this somehow got reverted or lost. andreyk0's PR was closed before merging, because the hmvp one contained all the SPI bitbang stuff.

What happened to https://github.com/kellerkindt/pcd8544/pull/7? It seems like the whole version 0.2.0 is just gone from this repo.

I put some working platform-examples in my own fork for reference, for Bluepill and Raspberry Pi Pico: https://github.com/basdusee/pcd8544