Pages: [1]   Go Down
Author Topic: PgmPrintln - it's all ascii to me!  (Read 357 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
***
Karma: 1
Posts: 161
What could possibly go wrong?
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

I've been routing around with a problem with a SD card, and think I have narrowed it down to an error handling function that gets called.

I've used SD.h to create my own library of higher level functions for working with files. Although the library is mostly mine, like all my code it includes bit's cribbed from other libraries. In this case the bit i copied was this....

Code:
void SdFileFunctions::error_P(const char* str)
{
  PgmPrint("error: ");
  SerialPrintln_P(str);
  if (card.errorCode()) {
    PgmPrint("SD error: ");
    Serial.print(card.errorCode(), HEX);
    Serial.print(',');
    Serial.println(card.errorData(), HEX);
  }
  while(1);
}

The first thing that I've only just worked out is that while(1) is an endless loop - which finally explains why whenever I get an issue with an SD card my code hangs! (I've puzzling that one for months!)

More baffling (until now) was that the error message generated was this.....
Quote
10111411411111458329997114100461051101051163210297105108101100
83683210111411411111458321,0

I've finally twigged that this is the an error message expressed in ascii code! 101='e' 114='r' 114='r' 111='0' 114='r' .... spells 'error', etc etc....

So it looks to me like PgmPrintln() is printing out the ascii equivalent of everything, instead of the character string.

Here's a working sketch to illustrate the issue....
Code:
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"                       
#else
#include "WProgram.h"                     
#endif

#include <SD.h>                            // New wrapper library for all the low level SD file functions. Replaces Sd2Card.h, FatStructs.h, Sd2PinMap.h, SdFat.h, SdFatmainpage.h, SdFatUtil.h, SdInfo.h

void setup()
{
  Serial.begin(115200);               // Communication speed for the display
  Serial.println("Starting.....");
 
  PgmPrintln("Bannans");
  Serial.println("Done!");
 
}

void loop()
{
  Serial.print(".");
  delay(1000);
}
when I run this I get....
Quote
Starting.....
669711011097110115
Done!
....

All the examples I can find seem to suggest that PgmPrintln() should work just like Serial.print() except that it prints from Progmem instead of normal memory, thus saving space.

The first lesson learnt is don't copy someone elses code unless you understand what it's doing! But apart from that, what's going on, have I misunderstood what SdFileFunctions::error_P(const char* str) is supposed to be doing? or the what PgmPrintln() does?

I'm working on with a Mega 2560 using Arduino version 1.0
Logged

Pages: [1]   Go Up
Jump to: