Skip to content
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

SSD 1306 Oled not working properly with HW SPI and Teensy 4.0 #56

Closed
Guzu1987 opened this issue Feb 11, 2020 · 9 comments
Closed

SSD 1306 Oled not working properly with HW SPI and Teensy 4.0 #56

Guzu1987 opened this issue Feb 11, 2020 · 9 comments

Comments

@Guzu1987
Copy link

Guzu1987 commented Feb 11, 2020

I have an 2.42 inch Oled display wired to the Hardware SPI port of the Teensy 4.0.
SCK 13
MOSI 11
CS 10
DC 8
RST 9

When I use the Adafruit SSD1306 only the top 8 pixels of the oled work. The rest is noise.
With the u8g2 library horizontal lines appear on the oled no matter what I do.
The lines are every 8th pixel (7 pixels between the lines).

IMG_0799

The oled works fine with an Arduino Nano with both libraries.

The only library which seems to work fine with the Teensy 4.0 is the Sparkfun HyperDisplay library. But this one is VERY slow.

After much trial and error (which can be followed here) I think this is a hardware SPI Issue with the Teensy code. (If I use the Software SPI functions with the same or different pins in the u8g2 library everything works fine, just slower.)

I tired to upload the code with lower Teensy microprocessor speed (down to 24MHz chosen from the Arduino IDE) but this had no effect on the horizontal lines.

This and this is the oled I use and this is some documentation regarding the driver.

Could there be an issue with the SPI software written for the Teensy 4.0?

I would really appreciate any help in solving this issue. Thank you very much.

@PaulStoffregen
Copy link
Owner

@Guzu1987
Copy link
Author

I solved the problem with help from the PJRC forums.
I changed the spi_mode to 3 in the u8g2 library cpp files. It turns out that this particular oled uses this spi_mode.
So the problem was not with the SPI library, for the Teensy but with my knowledge of the oled and code :)
Here is the thread that helped me.

Thank you very much.

@olikraus
Copy link

I personally think that modes 0 and 3 are swapped. There was a similar issue with the ESP8266 boards (esp8266/Arduino#2416).

The SPI modes had been defined long back for the Arduino AVR boards and all other boards should behave in the same way.

The byte 0x053 is written in all four SPI modes: From left to right mode 0, 1, 2 and 3 on an Arduino Uno:
https://cloud.githubusercontent.com/assets/1084992/17836380/888eda42-6790-11e6-9e1a-e9e9d0672269.png

It would probably simple to crosscheck this with Teensy 4.0.

I personally would keep this open until it is verified, that the SPI modes behave in the same way.

@Guzu1987 Guzu1987 reopened this Feb 11, 2020
@PaulStoffregen
Copy link
Owner

PaulStoffregen commented Feb 12, 2020

I ran a quick test with this code:

#include <SPI.h>

void setup() {
  pinMode(10, OUTPUT);
  SPI.begin();
}

void loop() {
  SPI.beginTransaction(SPISettings(4000000, MSBFIRST, SPI_MODE3));
  digitalWrite(10, LOW);
  SPI.transfer(0x5A);
  digitalWrite(10, HIGH);
  SPI.endTransaction();
  delay(1);
}

On Arduino:
mod3_uno

On Teensy 4.0:
mod3_t4

The waveforms are correct. I'm considering this issue closed & fully resolved.

@olikraus
Copy link

@PaulStoffregen thanks for the quick response. Mode 3 indeed looks correct. However it actually is Mode 0 which had caused the problem. I wonder how the Teensy 4.0 picture would look like for mode 0.

BTW: Amazing little board. Good Work.

@PaulStoffregen
Copy link
Owner

Please run the test program and capture the waveforms. If there is a problem with the waveforms, show me that you have done the test.

I have many other projects needing my time, and many other people to help on the forum, so I'm considering this matter resolved. I'm not going to put any more dev time into it, unless you can show waveforms which demonstrate a problem.

@olikraus
Copy link

Understand, same time problem here.
Moreover: I do not own a Teensy 4.0.
@Guzu1987 : Are you able to capture the waveform?

@Guzu1987
Copy link
Author

I am sorry but I don't have an oscilloscope. I only have one of these:
It has only 1 channel. If you think that I could measure something that would help you, just let me know. I think here are the specs of the DSO150 I have.
https://jyetech.com/dso-150-shell-oscilloscope/

IMG_0821

@olikraus
Copy link

Nice device, but we need to check clk vs data, so two channels are required.

Ok, let's consider this as solved...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants