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

Using u8g2 and SPI #794

Closed
XNinety9 opened this issue Jan 23, 2019 · 9 comments
Closed

Using u8g2 and SPI #794

XNinety9 opened this issue Jan 23, 2019 · 9 comments

Comments

@XNinety9
Copy link

Hi.

I'm using a ST7920 SPI display, coupled with 8 MCP41010 SPI potentiometers.

When I use u8g2 do draw on my display only, everything's fine.
When I set my potentiometers using SPI, it's ok too.

But when I try to do both, u8g2 can't draw anymore.

Is there a way to place an ST7920 and the MCP41010 on the same SPI line and make them work altogether using u8g2 (for the display) and regular SPI functions for the MCPs?

Thanks a lot for your help.

@AnHardt
Copy link

AnHardt commented Jan 24, 2019

The latest ST7920 datasheet page 26 second paragraph, tells us CE is broken, don't use it with together with other devices on the bus.

Mostly only a garbed display is observed, but depending on what is send to the other devices worse thing can happen.

Safest is to ether use a separate spi-bus for the ST7920 or use some AND-gates to keep SCLK and SI quite when CE is not selected.

@XNinety9
Copy link
Author

What do you mean by "CE is broken"?

And BTW, here is a piece of code to illustrate:

#include <Arduino.h>
#include <U8g2lib.h>

#include <SPI.h>


U8G2_ST7920_128X64_F_SW_SPI u8g2(U8G2_R0, /* clock=*/ 52, /* data=*/ 51, /* CS=*/ 30, /* reset=*/ U8X8_PIN_NONE);
const int potsCSPins[] = {41, 40, 43, 42, 45, 44, 46, 47};

void setup(void) {
  Serial.begin(9600);
  SPI.begin();
  
  for(int i=0; i<8; i++) {
    pinMode(potsCSPins[i], OUTPUT);
    digitalWrite(potsCSPins[i], HIGH); 
    Serial.print("Setting pot " + String(i) + " to 128");
    setPot(potsCSPins[i], 128); 
    Serial.println(" Done!");
  }
  u8g2.begin();
}

void loop(void) {
  u8g2.clearBuffer();					// clear the internal memory
  u8g2.setFont(u8g2_font_ncenB08_tr);	// choose a suitable font
  u8g2.drawStr(0,10,"Hello World!");	// write something to the internal memory
  u8g2.sendBuffer();					// transfer internal memory to the display
  delay(1000);  
}

void setPot(uint8_t cspin, uint8_t value) {
  digitalWrite(cspin, LOW);
  SPI.transfer(B00010001);
  SPI.transfer(value);  
  digitalWrite(cspin, HIGH);
}

@AnHardt
Copy link

AnHardt commented Jan 24, 2019

The datasheet describes a, compared to other SPI devices, very different (broken) behavior of the controllers CE pin. In former versions of the datasheet a normal behavior was described. (Errata)

@XNinety9
Copy link
Author

And there is no way to patch this behavior in the code?

@AnHardt
Copy link

AnHardt commented Jan 24, 2019

Maybe - the day we can fix a flat tire with a firmware update.

@XNinety9
Copy link
Author

See #767, exactly the same issue.

@AnHardt
Copy link

AnHardt commented Jan 24, 2019

Hardware reset, reinitialize, reprint could work. Never tried. Up to now reprint was enough.

@XNinety9
Copy link
Author

Found the solution in #767. Using HW SPI in beta 2.25.2 solves the issue.

The constructor:

U8G2_ST7920_128X64_F_HW_SPI u8g2(U8G2_R0, 30, U8X8_PIN_NONE);

@olikraus
Copy link
Owner

I like "self-solving" issues. :-)

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