U8glib, ST7920 (Vitek VG128647) and DUE - slow loop, unable to use hardware SPI

First off, thanks for a great library!

I had some trouble getting my Vitek VG128647 display to work glitch free with an Arduino DUE in parallel mode. It took quite a while to figure out that on this display the PSB pin is not broken out, but is on an unmarked jumper. But after changing the jumper I finally have the display working well in software SPI mode using the following constructor:

U8GLIB_ST7920_128X64_1X u8g(18, 16, 17);    // SPI Com: SCK = en = 18, MOSI = rw = 16, CS = di = 17

In soft-serial mode, the display's refresh rate is quite slow (around 4FPS). While I can work with that, the problem is that with the picture loop in the main loop, it slows the main loop down to about the same +- 4 loops a second, since the picture loop has to execute first before the loop continues. (Using 4X mode makes very little difference).

My question: is there any way to prevent the U8glib code from blocking the execution of other code in this way? I'm building audio applications, and I've had some success by making use of the DUEs numerous timers and placing my other code (button checks, analog readings, updating of LEDs) in interrupt routines. But I seem to only get away with adding two more interrupt routines in addition to the main audio one, before the audio starts to degrade.

I understand that using hardware SPI will speed up the refresh rate, but my second problem is that I can't seem to get hardware SPI to work. I used the following constructor: U8GLIB_ST7920_128X64_1X u8g(10); // chip select I used the SCK an MOSI pins on the DUE's SPI header, and also tried with a number of different chip select pins, but no luck so far. Am I forgetting something?

Regards, MS

Slow picture loop: Can you post those parts of your code, related to the picture loop. Biggest mistake often is, to do additional calculation within the picture loop. Bad:

void loop(void) {
  int value;
  u8g.firstPage();  
  do {
    value = calculate_value_which_takes_a_long_time();
    draw(value);
  } while( u8g.nextPage() );
}

Here the calculation of the "value" is done within the loop. This will slow down execution and may also lead to unexpected results on the screen if value changes in the loop itself. Instead do this:

void loop(void) {
  int value;
 value = calculate_value_which_takes_a_long_time();
  u8g.firstPage();  
  do {
    draw(value);
  } while( u8g.nextPage() );
}

Rule: Calculate as much as possible outside the picture loop. Store the results in some global variables, and use these variables to draw your picture.

HW SPI: HW SPI is not supported for the ST7920 on the Due (see here: https://code.google.com/p/u8glib/wiki/device)

Oliver

Hey there Oliver,

Thanks for your reply (and again for the library).

Oops, hadn't notice the n.a in hardware SPI box - guess, that's that.

No, I didn't have anything else in the picture loop - it was slow even with the Hello World sketch. My problem is that doing analog readings and the like in the loop (not in the picture loop, in the main loop) is held back by the picture loop. If the refresh rate is 4fps, analog readings also only happen 4 times a second. Something is taking quite long to complete in the picture loop.

By the way, is it normal to get the following warnings on compile with the Due: U8glib\utility\u8g_com_arduino_st7920_spi.c.o: warning: multiple common of `u8g_data_pin' U8glib\utility\u8g_com_arduino_st7920_custom.c.o: warning: previous common is here U8glib\utility\u8g_com_arduino_st7920_spi.c.o: warning: multiple common of `u8g_clock_pin' U8glib\utility\u8g_com_arduino_st7920_custom.c.o: warning: previous common is here

I've ordered one of these for testing: http://www.vitek.com.tw/graphic-module/128x64.html

It seems the library is quite a bit faster with the KS0108 controller.

Let's see how it goes.

Thanks for mentioning the warnings. I have created an issue for this.

openGLCD together with the KS0108 display will be even faster.

Oliver