Mega2650 + UTFT

Hallo an alle,

sitze seit ein paar Stunden an einem Problem und ich hoffe ihr könnt mir weiter helfen.
Meine Vorraussetzungen sind folgende:
Arduino Mega 2560
ITDB02 Mega Shield 2.1
ITDB02-5.0 TFT LCD mit touch

und das möchte ich machen:

  • mehrere Bilder darstellen

Meine Vorgehensweise:

Bilder liegen als Bitmap im Sketchordner und werden über den Flash genutzt (progmem)
Als nächstes sende ich die Bilder mit Hilfe der UTFT-Lib (Electronics - Henning Karlsen) über den Befehl drawBitmap aufs Display
Dies funktioniert mit bis zu 11 Bildern (je 5 kB) bei dem folgenden Beispiel, was einer binären Sketchgröße von 69.616 Bytes enstspricht. Sobald ich das 12. Bild hinzufüge funktioniert das Board nicht mehr.
Hier einmal der Beispielcode:

#include <UTFT.h>
#include <avr/pgmspace.h>

UTFT myGLCD(ITDB50,38,39,40,41);

void setup()
{
myGLCD.InitLCD(LANDSCAPE);
myGLCD.fillScr(255, 255, 255);
myGLCD.setColor(0, 0, 0);
delay(2000);
}

void loop()
{
extern unsigned int Test[0x9C4];
extern unsigned int Test_1[0x9C4];
extern unsigned int Test_2[0x9C4];
extern unsigned int Test_3[0x9C4];
extern unsigned int Test_4[0x9C4];
extern unsigned int Test_5[0x9C4];
extern unsigned int Test_6[0x9C4];
extern unsigned int Test_7[0x9C4];
extern unsigned int Test_8[0x9C4];
extern unsigned int Test_9[0x9C4];
extern unsigned int Test_10[0x9C4];
extern unsigned int Test_11[0x9C4];
extern unsigned int Test_12[0x9C4];
extern unsigned int Test_13[0x9C4];

int i =0;

myGLCD.drawBitmap (i, 0, 50, 50, Test);
i++;
myGLCD.drawBitmap (i50, 0, 50, 50, Test_1);
i++;
myGLCD.drawBitmap (i
50, 0, 50, 50, Test_2);
i++;
myGLCD.drawBitmap (i50, 0, 50, 50, Test_3);
i++;
myGLCD.drawBitmap (i
50, 0, 50, 50, Test_4);
i++;
myGLCD.drawBitmap (i50, 0, 50, 50, Test_5);
i++;
myGLCD.drawBitmap (i
50, 0, 50, 50, Test_6);
i++;
myGLCD.drawBitmap (i50, 0, 50, 50, Test_7);
i++;
myGLCD.drawBitmap (i
50, 0, 50, 50, Test_8);
i++;
myGLCD.drawBitmap (i50, 0, 50, 50, Test_9);
i++;
myGLCD.drawBitmap (i
50, 0, 50, 50, Test_10);
i++;
myGLCD.drawBitmap (i50, 0, 50, 50, Test_11);
i++;
// myGLCD.drawBitmap (i
50, 0, 50, 50, Test_12);
}

Beispiel für ein Bild:

#include <avr/pgmspace.h>

prog_uint16_t Test[0x9C4] PROGMEM ={
0x13FA, 0x13FA, 0x13FA, 0x13FA, 0x13FA, ...(Bitmap)... , 0x13FA
}

Hat jemand eine Idee woran dies liegen kann? Der Mega besitzt eine Flashgröße von 256KB abzüglich Bootloader. Somit kann dieser ja nicht voll sein. Da die Bilder im Flash bleiben kann ja auch der SRam keine Probleme bekommen, oder habe ich da einen Denkfehler?

Würde mich freuen wenn jemand Rat weiß.

Viele Grüße

Patrick

Does anyone have an idea to solve this problem?

Best regards, Mikel

You have an 8-Bit Controller with 16-Bit addresses that can only address 64kB of memory

To use more than that you can't use PROGMEM, but need to do this:
1.) place the data into specific memory sections using the section attribute
2.) use an assembler macro to calculate so-called far addresses
3.) instead of the pgm_read_xxx() macros use pgm_read_xxx_far()

See here:
http://forum.arduino.cc/index.php?topic=174084.msg1294539#msg1294539

You also need to modify the UTFT library and either change the drawBitmap() methods or better yet use conditional compiling to change the behavior, depending on whether a certain #define like USE_FAR_POINTERS exists in the header file.

There are several lines like this that need to be changed:

col=pgm_read_word(&data[tc]);

to

col=pgm_read_word_far(GET_FAR_ADDRESS(&data[tc]));

Where GET_FAR_ADDRESS() is the macro in the above link

Or as said something like this:

#ifdef USE_FAR_POINTERS
   col=pgm_read_word_far(GET_FAR_ADDRESS(&data[tc]));
#else
   col=pgm_read_word(&data[tc]);
#endif

Thanks a lot, Mikel