olikraus / u8g2

U8glib library for monochrome displays, version 2
Other
5.03k stars 1.04k forks source link

Multiple screen SW SPI #579

Closed mdmdelmotte closed 6 years ago

mdmdelmotte commented 6 years ago

Hello guys,

i m running succesfully 3 OLED 128*128 (ssd1327) with U8g2 SW SPI. When i plug the fourth they all print random stuff. (i switched the fourth to remove a possible defect screen, but still the same) i have separated CS & Reset line for each.

i thought it was related to too much current drawn so i put a bigger Vcc instead of the USB but still the same.

Any idea ?

Thanks.

olikraus commented 6 years ago

hmmm... no idea, but maybe also too less information to say something.

mdmdelmotte commented 6 years ago

:-) unfortnately there is not a lot more to say :-)

It's running on an arduino mega and code is something like :

#define OLED_MOSI   2
#define OLED_CLK   3
#define OLED_DC    6
#define OLED_CS_1    5
#define OLED_CS_2    8
#define OLED_CS_3    6
#define OLED_CS_4    11
#define OLED_RESET_1 4
#define OLED_RESET_2 9
#define OLED_RESET_3 7
#define OLED_RESET_4 12

U8G2_SSD1327_MIDAS_128X128_F_4W_SW_SPI display(U8G2_R2, /* clock=*/ OLED_CLK, /* data=*/ OLED_MOSI, /* cs=*/ OLED_CS_1, /* dc=*/ OLED_DC, /* reset=*/ OLED_RESET_1);
U8G2_SSD1327_MIDAS_128X128_F_4W_SW_SPI display2(U8G2_R2, /* clock=*/ OLED_CLK, /* data=*/ OLED_MOSI, /* cs=*/ OLED_CS_2, /* dc=*/ OLED_DC, /* reset=*/ OLED_RESET_2);
U8G2_SSD1327_MIDAS_128X128_F_4W_SW_SPI display3(U8G2_R2, /* clock=*/ OLED_CLK, /* data=*/ OLED_MOSI, /* cs=*/ OLED_CS_3, /* dc=*/ OLED_DC, /* reset=*/ OLED_RESET_3);
U8G2_SSD1327_MIDAS_128X128_F_4W_SW_SPI display4(U8G2_R2, /* clock=*/ OLED_CLK, /* data=*/ OLED_MOSI, /* cs=*/ OLED_CS_4, /* dc=*/ OLED_DC, /* reset=*/ OLED_RESET_4);

then in my loop, i have :+1:

  display1.clearBuffer();
  display1.print("AAAAA");  
  display1.sendBuffer();
  display1.clearBuffer();

  display2.clearBuffer();
  display2.print("BBBBB");  
  display2.sendBuffer();
  display2.clearBuffer();

  display3.clearBuffer();
  display3.print("CCCCC");  
  display3.sendBuffer();
  display3.clearBuffer();

  display4.clearBuffer();
  display4.print("DDDDD");  
  display4.sendBuffer();
  display4.clearBuffer();

if i run the complete code but without the last screen connected it works like a charm on the 3 screens If i connect everything of the fourth screen except Din it does not work anymore. So acocrding to me it's not related to code.

i also checked mapping of CS and Reset of the last screen, it's wired correctly.

did you succeed on your side to use more than 3 small oled displays ?

Regards.

JamesGKent commented 6 years ago

the last post here: http://www.microchip.com/forums/m148739.aspx talks about noise that only becomes a problem with larger numbers of slaves, not had this myself, but you could try the advice given there to add terminating resistors, such as a 47 ohm

olikraus commented 6 years ago

... added code tags...

I never connected more than two devices.

Not a problem, I just wanted to say that all four displays will share the same memory, so display2.clearBuffer() is the same as display3.clearBuffer()

In the code display1 is not declared, instead it is called display (without 1), but i do not think that this is your problem.

mdmdelmotte commented 6 years ago

hello guys,

just wanted to give a feedback.

@olikraus Yeah sorry i modified the code a little bit to show it here, but of course it compiles ;)

@JamesGKent . Thks james i think my issue is related to this. Indeed i created a second SPI for the fourth display and it worked like a charm. I mean 4 new separated lines (MOSI,MISO,...) for this last screen. So it's pure electrical. i will try the EOL resistor.

Thanks for your help, btw it was my very first message on a forum after 20 years of working in IT !

JamesGKent commented 6 years ago

@mdmdelmotte from an EMC perspective (my day job) the best approach would be to put terminating resistors at the end of each line, rather than at the beginning, so for instance a 330 ohm on the sck and mosi of each display rather than one lower value resistor on the masters pins, however for a small number of devices such as your current use case a single res each on your sck and mosi lines should suffice. what I suspect is happening is that because the inputs to the displays are high impedance and the transmission line is low impedance, high data rates cause a reflection when they hit the slave device, this in turn creates noise on the line and garbles the data. by putting resistors in the circuit at the end of the line you eliminate the impedance transition and remove the reflection. by putting the resistors at the start instead you don't eliminate the reflection but instead clamp it through the resistor drastically reducing the spikes it causes.

you should find (if my suspicion is correct) that reducing the SPI speed would also remove the problem (if it can be reduced far enough) however that's a poor solution when driving 4 displays due to the large amount of data involved....

olikraus commented 6 years ago

can we close this?