-
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
U8G2 with STM32 and 12864B LCD over SPI Displaying Random Pixels #840
Comments
looks like no data is transfered. |
Hello, thanks for the quick response olikraus. So I've added the remainding delay messages (from the porting guide) to my C-code. (Attached) After all this the display shows the same random pixels. But then, after checking the datasheet of the LCD to decode some of the messages sent on start, I noticed that the bytes should not be sent in 8 bit packets, but rather in 24 bit ones. I don't know if this may be the cause of my error, as I am always sending packets in 8 bits, not 24. Regards, New u8g_stm32_port.c |
Can you check the CS signal line also? It should change after some bytes of data and also there must be a delay between the last bit of the last byte and the level change of CS Looking at your picture: It looks like high level is 3 Volt only. This is too less for the ST7920 which is a very old 5V IC. |
ok, at least one thing what is missing are the post cs and pre cs wait times: |
Additionally I suggest to set the CS level to a proper default: https://github.com/olikraus/u8g2/blob/master/csrc/u8x8_byte.c#L141 |
the other question also is: Did you apply the correct SPI mode? The ST7920 is a little bit sensitive for this. |
So I've corrected the CS pre and post timing, added the defauklt state of the CS and corrected the SPI mode. Apparently the SPI mode of the ST7920 is 3, so I had to tweak my SPI settings a bit. Now I am at a point where after calling my draw routine in display.c (unedited since last attachment) where usually a string should be drawn, the display is completely blank. (no random pixels, I can see it update to a blank screen after init). I know that the display routine is run because of the output in the serial debug console. |
Which setup did you use? How does your code look like? |
This is my hardware setup: LCD (12864B) connected: SCLK, MOSI and CS are connected to the STM32 via a voltage translator (3V3 to 5V0, 74LVC4245APW) which has been tested and considered in working condition. The contrast of the display is controlled with an onboard (on the LCD module PCB) potentiometer, and is tuned correctly. (See image in original post, the pixels can be seen) The STM32 is set up using CubeMX software, which generates the code and configures the HAL library of the STM32. As a debugger, a STLINKV2 is used. The version of u8g2 was pulled from this GitHub repo on 17th of March 2019. Here's the code:
All display relevant code and / or code interfacing with the u8g2 library is contained within these two files and the assertion can be made, that display_init is called in init and display_run_thread after init from a thread from main.c. Regards, |
ok, display.c looks good. What about the reset input of the display? The reset u8x8 reset message |
So the V0 input is controlled via an onboard potentiometer (its directly on the lcd, measured it and it is connected to V0)
|
Hmm I am running out of ideas. |
Yes, weird I know... |
So I think I will check out if it makes a difference, if you send 24 bit blocks or 3 8 bit blocks to the ST7920 controller. |
Just for info: This is a export of the data being sent. Basically, every time |
not sure what you mean about this. What should be the difference?
There is no other option. Arduino IDE only has a 8 Bit SPI interface, so it has to be 3x 8Bit. But this works quite well for my personal boards and displays. Let me check your log:
Indeed the first init command for the display is 0x38: https://github.com/olikraus/u8g2/blob/master/csrc/u8x8_d_st7920.c#L50 The conversion from 0x38 to the three byte sequence 0xf8 0x30 0x80 happens here: Except for the interrupting "Kernel" messages, the output sequence seems to be correct. |
I agree. Many requests here and on arduino.cc are problems related to ST7920 displays. It seems to be very sensitive regarding timing and wiring. |
So I am curious: I just checked the log again and I assume that every time 16 bytes are being transfered (so when S-10 (hex) is proceeding the data) pixel data is sent. But there is not single occurence of a non-zero byte in these 16 bytes after S-10. If my understanding is correct, doesn't this mean that the LCD displays a blank screen, because only null-bytes are sent to it? Or am I wrong? |
Yes, thats why I asked for the rest of your code. But this looks already ok:
Maybe you could draw a box (drawBox) or a line (drawLine), just to ensure, that there are no other issues. |
I've tried it with pixel sets and some rectangle graphics, but still nothing... This is the whole code: |
So you say: The display becomes blank and all the data is zero in the log file. Oh, there is a "break" statement missing before "case U8X8_MSG_BYTE_END_TRANSFER:" |
Ok, so here's whats happened: So I've missed this one break statement, and sure enough, that fixed it. But the text wasn't showing, only a rectangle... So I've looked into it and i realised that I used a symbol font, not a normal font, so one small change and now the text also works. I also found out, that the display also runs with an SPI clock of 750kHz as well as default SPI-mode. (So default and 3) I would say that the missing break statement was "ein absoluter Klassiker", if you know what I mean :) Thank you for the extensive help olikraus, It is very appreciated from my side. This issue is hereby closed. Regards, |
tja... I am happy that everything works :-) |
I get same problem |
The missing break statement was in the µC port code in The file was linked in this comment:
I see this issue linked in topics that frankly do not have anything to do with the issue at hand. The port of the u8g hw-interface was done according to the wiki docs, the issue was that I had that one break statement missing in my code, thus a unwanted switch/case fallthrough to the Also, iirc, the symbol font thing was just a RTFM for me regarding on how to properly set up & use u8g2 in the code itself. I even attached the (working) code I've used in the previous answers:
Regarding other details I would really suggest you taking a look at the libraries docs in the GitHub wiki, this issue is already 5 years old and things may have changed during this time. Cheers, |
@berndoJ thanks for your answer. I have access via cellphone only at the moment. |
Hello,
so I've followed the porting guide (https://github.com/olikraus/u8g2/wiki/Porting-to-new-MCU-platform) on how to port u8g2 to a custom MCU platform. In my case I use an STM32F072RBT7 (ARM Cortex-M0 Core) STM32-MCU.
It seems that my port of the hardware dependant functions at least kinda works, as data is pushed out over spi. (I checked it with an oscilloscope)
The problem is that after the init of the display random pixels are displayed on screen, with 32 pixel wide white / inverted areas. (see image).
I use an 12864B 128x64 graphical LCD (I think its even the same one as in the SPI example of the setup tutorial), driven over SPI (SCK, MOSI, CS, RST), which uses the ST7920 LCD-Controller. As I've succeeded in driving this exact LCD with an Arduino before, this LCD is known good.
As firmware I use FreeRTOS and STM32CubeMX, which generates the HAL libs for my STM32 device.
I don't know if it is the issue of my hw port or if something different is going on...
Image of the LCD after init:
display.c : Here the u8g2 is initialised.
display.c.txt
u8g2_stm32_hw_port.c : here are the functions used to port u8g2 to my device.
u8g2_stm32_hw_port.c.txt
Thanks in advance,
berndoJ
The text was updated successfully, but these errors were encountered: