.eep file not being written during compile?

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

Gents,

First, I am using AVR Studio 6.2.1153 (latest release as of this post) that is fully updated (just forced a check for updates this evening). The program compiles as I would expect, but the data files do not appear to be written correctly. This is what I am trying to do:

So I have a small table I want to put into eeprom, like so:

const uint16_t ADC_temperature_table[] PROGMEM = {
	0x13, 0x16, 0x18, 0x1B,0x1F, 0x22, 0x26, 0x2B, 0x2F, 0x34,
	0x3A, 0x40, 0x46, 0x4D, 0x55, 0x5D, 0x65, 0x6E, 0x78, 0x82,
	0x8D, 0x98, 0xA4, 0xB0, 0xBE, 0xCB, 0xD9, 0xE8, 0xF7, 0x106,
	0x116, 0x127, 0x137, 0x148, 0x15A, 0x16B, 0x17D, 0x18E, 0x1A0, 0x1B2,
	0x1C4, 0x1D5, 0x1E7, 0x1F8, 0x20A, 0x21B, 0x22B, 0x23C, 0x24C, 0x25C,
	0x26B, 0x27B, 0x289, 0x298, 0x2A5, 0x2B3, 0x2C0, 0x2CD, 0x2D9, 0x2E5,
	0x2F0, 0x2FB, 0x305, 0x310, 0x31A, 0x323, 0x32C, 0x335, 0x33D, 0x345,
	0x34C, 0x354, 0x35B, 0x361, 0x368, 0x36E, 0x374, 0x37A, 0x37F, 0x384,
	0x389, 0x38D, 0x392, 0x396, 0x39A, 0x39E, 0x3A2, 0x3A6, 0x3A9, 0x3AC,
	0x3AF, 0x3B2, 0x3B5, 0x3B8, 0x3BB, 0x3BD, 0x3C0, 0x3C2, 0x3C4, 0x3C6,
	0x3C8, 0x3CA, 0x3CC, 0x3CE, 0x3D0, 0x3D1, 0x3D3, 0x3D4, 0x3D6, 0x3D7,
	0x3D9
};

I have these header files:

#include 
#include 
#include 
#include "main.h"

(main.h has the table in it)

And I am reading the data like so:

test = pgm_read_word(&ADC_temperature_table[i]);

The problem is when the program is compile, it only writes 14 bytes to the .eep file:

:00000001FF

Either that is NOT the correct EEPROM file (but it does fit the size of the data memory usage of 14 bytes), or I have something screwed up. Again.

My (limited) understanding of using the program memory is that when the "PROGMEM" keyword is used, the linker puts the data into the EEPROM data file instead of the flash memory file. But that does not appear to be what is going on here.

What am I doing wrong?

 

Clint

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

You are confusing PROGMEM and EEMEM.

:: Morten

 

(yes, I work for Microchip, yes, I do this in my spare time, now stop sending PMs)

 

The postings on this site are my own and do not represent Microchip’s positions, strategies, or opinions.

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

And just to note that if you are writing new code these days that does want to put data in flash then don't use pgmspace.h/PROGMEM/pgm_read_word() anyway. It's all been replaced by __flash.

Anyway, as Morten says the way you use EEPROM is:

Quote:

(main.h has the table in it)

WRONG! You should never put anything that causes storage to be assigned into a header file. If you want the data in a "separate" file use it's own .c file. That is:

// eedata.c
#include "main.h"
 const uint16_t ADC_temperature_table[] EEMEM = {
   0x13, 0x16, 0x18, 0x1B,0x1F, 0x22, 0x26, 0x2B, 0x2F, 0x34,
   0x3A, 0x40, 0x46, 0x4D, 0x55, 0x5D, 0x65, 0x6E, 0x78, 0x82,
   0x8D, 0x98, 0xA4, 0xB0, 0xBE, 0xCB, 0xD9, 0xE8, 0xF7, 0x106,
   0x116, 0x127, 0x137, 0x148, 0x15A, 0x16B, 0x17D, 0x18E, 0x1A0, 0x1B2,
   0x1C4, 0x1D5, 0x1E7, 0x1F8, 0x20A, 0x21B, 0x22B, 0x23C, 0x24C, 0x25C,
   0x26B, 0x27B, 0x289, 0x298, 0x2A5, 0x2B3, 0x2C0, 0x2CD, 0x2D9, 0x2E5,
   0x2F0, 0x2FB, 0x305, 0x310, 0x31A, 0x323, 0x32C, 0x335, 0x33D, 0x345,
   0x34C, 0x354, 0x35B, 0x361, 0x368, 0x36E, 0x374, 0x37A, 0x37F, 0x384,
   0x389, 0x38D, 0x392, 0x396, 0x39A, 0x39E, 0x3A2, 0x3A6, 0x3A9, 0x3AC,
   0x3AF, 0x3B2, 0x3B5, 0x3B8, 0x3BB, 0x3BD, 0x3C0, 0x3C2, 0x3C4, 0x3C6,
   0x3C8, 0x3CA, 0x3CC, 0x3CE, 0x3D0, 0x3D1, 0x3D3, 0x3D4, 0x3D6, 0x3D7,
   0x3D9
};
//main.h
#include 
.. other stuff ...
extern const uint16_t ADC_temperature_table[] EEMEM;
... other stuff ...
// main.c
#include "main.h"

int main(void) {
  uint8_t i;
  uint16_t test;
  i = 35;
  test = eeprom_read_word(&ADC_temperature_table[i]); 
  // use test ...
}

When you build this code a .eep will be created. Put it into the EEPROM using ISP then when you run the code the eeprom_read_word() should find the data.

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

DOH!!!!!  That WOULD explain why it wasn't loading anything into the eeprom! 

 

Thanks for pointing out my stupidity!  ;)  LOL

 

meolsen wrote:

You are confusing PROGMEM and EEMEM.

 

Clint

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

clawson,

 

Thank you for the very detailed explanation of the multiple ways I screwed up this  simple bit of code.  The help is appreciated and it will be put to use!

 

And FYI, I am not sure WHY I decided to put that table in the header instead of the c file...  I know better on SOME days.

 

Clint

Last Edited: Sat. Sep 6, 2014 - 02:18 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson,

 

I've got the eeprom stuff sorted.  Thanks again!

 

I do have one question: where can I find documentation on using __flash instead of using pgmspace.h et. all?  I have not been able to find any relevant documentation on this.

Thanks!

 

Clint

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

:: Morten

 

(yes, I work for Microchip, yes, I do this in my spare time, now stop sending PMs)

 

The postings on this site are my own and do not represent Microchip’s positions, strategies, or opinions.

Last Edited: Sat. Sep 6, 2014 - 12:34 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks!  I searched for "__flash winavr" and kept finding links showing pgmspace.h stuff.

 

Clint