Pages: [1]   Go Down
Author Topic: Why would this lcd CGRAM address function crash my Arduino Pro Mini (Uno)?  (Read 3478 times)
0 Members and 1 Guest are viewing this topic.
Wales
Offline Offline
Jr. Member
**
Karma: 0
Posts: 57
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Finally, after months of trouble, I've narrowed my problems down to the following bit of code in an library I found:

Code:
void OLEDFourBit::setGraphicCursor( uint8_t x, uint8_t y ){
if( _is_graphicmode ){
if( 0 <= x && x <= 100 ){
command(LCD_SETDDRAMADDR | x);
}
if( 0 <= y && y <= 1 ){
command(LCD_SETCGRAMADDR | y);
}
}
}

and in the header file:
Code:
virtual size_t write(uint8_t);
using Print::write;

If I do
Code:
lcd.write((byte)0xFF);
then all is good.

But if I do
Code:
lcd.setGraphicCursor(0,1); // First col, 2nd row
and then do
Code:
lcd.write((byte)0xFF);
then it crashes the Arduino, which is a Pro Mini 16Mhz.
I know this because I'm printing out millis, and they reset to zero after the last lcd.write - in other words, if I repeat
Code:
lcd.write((byte)0xFF);
10 times then I get a nice 10-wide solid block, but after that, millis are back to zero, which I assume means the Arduino has crashed and reset.

I'm using VisualMicro, but not sure what watches or breakpoints to insert to debug. When I upload, I get

Code:
Compiling 'oled4bit' for 'Arduino Pro or Pro Mini w/ ATmega328 (5V, 16 MHz)'
Binary sketch size: 3924 bytes (used 13% of a 30720 byte maximum) (0.19 secs)
Minimum Memory Usage: 120 bytes (6% of a 2048 byte maximum)

So it's not like I'm low on space. Weird and confusing, eh?
BTW, same happens with Arduino IDE.
Logged

0
Offline Offline
Shannon Member
****
Karma: 215
Posts: 12463
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You can only determine RAM usage at runtime as stack and heap memory use is
not known at compile time.
Logged

[ I won't respond to messages, use the forum please ]

Wales
Offline Offline
Jr. Member
**
Karma: 0
Posts: 57
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You can only determine RAM usage at runtime as stack and heap memory use is
not known at compile time.
Hmmm, so something, somewhere, is chomping up all the RAM and doing that bitwise OR with the command(LCD_SETCGRAMADDR | y); is probably just pushing it over the edge?
Logged

Offline Offline
Sr. Member
****
Karma: 12
Posts: 381
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you have lots of string literals, that could do it (although I would expect those to show up in your "minimum memory usage" stat. We don't have your sketch however).

If this could be your problem, look at PROGMEM to see about moving your strings literals to ROM.

http://www.arduino.cc/en/Reference/PROGMEM
« Last Edit: November 17, 2013, 05:42:21 pm by arduinodlb » Logged

Do not IM me. I will not respond. Ask questions in the forum.

Pages: [1]   Go Up
Jump to: