-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ST7920 on Raspberry Pi (HW SPI/WiringPi) #457
Comments
Both procedures are incomplete. |
no further comment, closing... |
Apologies for not being able to get back at you regarding this issue. Good news, I FINALLY managed to make everything work (both hardware and software SPI implementations) and I would like to share my findings here. TLDR; For the complete solution/demo, I have uploaded the cpp project here Couple of issues I have encountered:
The SPI HW communication of the raspberry pi was not working (Confirmed through test between RPI and Arduino slave) After reviewing the gpio status via the gpio tool, I realized that the MOSI, CLOCK and CS pins were set to OUT instead of ALT0. Solution: By explicitly setting the pin modes to ALT0 during initialization, I was able to establish proper SPI HW communication. The wiring pi spi library does not set this during initialization so you have to do it yourself. pinModeAlt(u8g2_rpi_hal.mosi, 0b100);
pinModeAlt(u8g2_rpi_hal.clk, 0b100);
pinModeAlt(u8g2_rpi_hal.cs, 0b100);
Even after fixing the SPI HW issue and copying the example from the port guide , replaced the arduino SPI methods with it's Wiring Pi equivalent, I was still unable to make it work (no response/activity from the display). I then stumbled into a comment of your code found in 'u8x8_byte_arduino_hw_spi': U8x8lib.cpp: u8x8_byte_arduino_hw_spi
This comment led me to investigate the inner workings of the Wiring Pi SPI library. From the developer's website, I found that the 'wiringPiSPIDataRW' also overwrites the data in the buffer in the same manner of what the comment above described and It uses ioctl system calls for full-duplex SPI transfer operations. *int wiringPiSPIDataRW (int channel, unsigned char *data, int len) :
I also found out from the linux kernel docs that Chip Select is automatically set/unset for full-duplex operations.
Unfortunately, the Wiring Pi SPI library does not provide any other methods of transfer and is only limited to full-duplex transfer operations, so I ended up writing my own spi library which supports block transfers for half-duplex operations with the intention to have u8g2 regain control of the Chip Select pin. With this, after replacing the wiring pi methods I was able to make everything work. |
Wow, thanks a lot for your detailed feedback. |
Also thanks for the updates to https://github.com/olikraus/u8g2/wiki/Porting-to-new-MCU-platform |
Need help making this library work for my RPI. I'm having issues drawing a simple "Hello World" string but nothing is being shown on the display. Am I missing an implementation in the code below?
Pin Config
Test Code:
HAL - SPI
HAL - GPIO:
The text was updated successfully, but these errors were encountered: