Problem with progmem data call

Go To Last Post
11 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I store some data in progmem as it takes up too much space in ram/rom so i created an array of strings and when i call the string out and copy it into another string and print it to serial out i get garbage computer symbols, the line of code i bring the string out of memory is strcpy_P(PrintString, (PGM_P)pgm_read_word(&(StoredString[0])));

thanks

Last Edited: Wed. May 3, 2017 - 07:49 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Moved to appropriate forum,

 

Can you specify the AVR and Toolchain you are using?

 

Thanks

Jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 2

Also, provide more context -- ideally, a complete test program that demonstrates your symptoms.  Tell what you expect to happen, and what >>is<< happening. 

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Theone6000 wrote:
print it to serial out i get garbage computer symbols,

In at least 98% of cases, the reason for "garbage symbols" in UART comms is the wrong baud rate  - so check that first.

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This seems to work well for flash-based strings:

 

const char STR001[] PROGMEM  = "Example One";
const char STR002[] PROGMEM  = "Example Two with more words";
const char STR003[] PROGMEM  = "Ex Three";

// Then set up a table to refer to your strings.

PGM_P  STR_table[]  = {STR001, STR002, STR003};

 

void setup()
{
  Serial.begin(9600);
}

void loop()
{
     int i;
     char  buffer[45];    

     for (i = 0; i<3; i++) {
         strcpy(buffer, (PGM_P) pgm_read_word(&(STR_table[i])));
         Serial.println( buffer );
     }     
}

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Why are people still using PROGMEM and pgm_read_word when the compiler now has "__flash" to make all this stuff 10 times easier?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

> Why are people still using PROGMEM and pgm_read_word when the compiler

> now has "__flash" to make all this stuff 10 times easier?

 

Because C++ is so cool.
 

avrfreaks does not support Opera. Profile inactive.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

SprinterSB wrote:
Because C++ is so cool.
cheeky

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Isolate your flash data and accesses in a C source file, using the modern __flash stuff. Then call it from C++.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I guess but a real shame the avr-g++ people won't allow their language to be "polluted" with __flash :-(

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yup, but sinse they won't give we can but whine and find a different solution :-)

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

Last Edited: Fri. May 5, 2017 - 05:41 PM