LowPowerLab Forum

Hardware support => Moteino => Topic started by: Jfisher on May 19, 2014, 09:07:20 AM

Title: ST7920 GLCD SPI Issue
Post by: Jfisher on May 19, 2014, 09:07:20 AM
I'm having some issues with an ST7920 GLCD using u8glib and I think I've eliminated the u8glib library as the culprit.
The u8glib library has the option of running the GLCD on hardware SPI using the relevant pins, or in software emulated SPI, using any other pins.

My GLCD works as expected in software SPI, but not when driving the GLCD on hardware SPI. I would like to get hardware SPI working for faster GLCD refresh rates.
I've eliminated wiring as the fault, as I use the same pins in software SPI (D13-SCK & D11 MOSI) and hardware SPI mode, and it only works in software SPI.
I also tried the same code on an Arduino Duemilanove (Atmega328) as it worked flawlessly in software and hardware mode with the same pins.

The code I'm testing does not use the SPI Flash (installed on my moteino) or the RFM69, so nothing else should be talking on SPI.

The part that has me stumped is that identical wiring and code on another Atmega328 works, but doesn't on the moteino. Can anyone suggest what I can do further to investigate this?

Code:

#include "U8glib.h"


U8GLIB_ST7920_128X64 u8g(7, U8G_PIN_NONE);
// SPI Com: SCK = E = 13, MOSI = R/W = 11, CS = RS = 7


void setup(void){
  u8g.setColorIndex(1);
  Clear();
   u8g.firstPage(); 
  do{
    intro();
  }
  while(u8g.nextPage() );
  delay(1000);
}


void intro(void){
  u8g .setFont(u8g_font_04b_03);
  u8g.drawStr( 0, 10, " Hello World ");
}
void Clear(void){
  u8g .setFont(u8g_font_04b_03);
  u8g.setFontRefHeightExtendedText();
  u8g.setDefaultForegroundColor();
  u8g.setFontPosTop();
}
void u8g_draw_circle(int r) {
  u8g.drawStr( 0, 5, " Circle ");
  u8g.drawCircle(20,40,5+r); 
  u8g.drawCircle(50,40,10+r);
  u8g.drawCircle(88,40,15+r);
}
void u8g_draw_filled_circle(int r) {
  u8g.drawStr( 0, 5, " Filled Circle  ");
  u8g.drawDisc(20,40,5+r); 
  u8g.drawDisc(50,40,10+r);
  u8g.drawDisc(88,40,15+r);
}


void loop(void){
Clear();
   u8g.firstPage(); 
  do{
    u8g_draw_circle(5);
  }
  while(u8g.nextPage() );
  delay(2000);
Clear();
   u8g.firstPage(); 
  do{
    u8g_draw_filled_circle(5);
  }
  while(u8g.nextPage() );
  delay(2000);
}
Title: Re: ST7920 GLCD SPI Issue
Post by: Felix on May 19, 2014, 09:12:35 AM
It should work since it's still an atmega328 running at 16mhz. What is different is the Moteino runs at 3.3V.
Also if you're not using the FLASH nor the radio maybe you want to pull those CS lines UP. (They are active low). You can do it in software with setting as INPUT and writing a HIGH, or you can just use a 10K resistor to 3.3V.
Ideally you should try with a barebones Moteino (no flash or radio) and try the simplest things, like initializing or drawing a line/character.
Title: Re: ST7920 GLCD SPI Issue
Post by: Jfisher on May 20, 2014, 09:02:10 AM
Thanks Felix, I pulled up the CS lines (Pins 8 and 2) but no luck.

Good news is I found it was the logic converter which was the issue, (the LCD is a 5V). I discovered this as this was the only hardware difference between test scenarios (the GLCD was driven directly by the Duemilanove). Fortunately the GLCD runs on 5V (from a boost module) but communicates on 3V3 on SPI, so I got rid of the logic converter.

The LCD runs on hardware SPI now, but garbles the text as soon as the radio talks. I'll investigate this further over the weekend.