How to read element into a Structure store in Progmem

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

Hi freaks,
someone can help me to read the elements stored into a structure stored into the Program memory?
I declared into an header file the struct:

 struct  BUTTON_t
 {
      uint8_t  AT45Addr_Start_Gif_Button;
      uint8_t  AT45Addr_Stop_Gif_Button;
      uint8_t  AT45Addr_Button_Pressed_Bmp;
      uint16_t X_Pos;  
      uint16_t Y_Pos;   
      uint16_t X_Dim;        
      uint16_t Y_Dim; 
      uint8_t  AT45_Text; 
      uint16_t Txt_X_Pos;  
      uint16_t Txt_Y_Pos;  
 };

then I initialized it as:

 struct BUTTON_t PROGMEM Button_Start =
 {
   .AT45Addr_Start_Gif_Button  = 1,
   .AT45Addr_Button_Pressed_Bmp= 1, 
   .AT45Addr_Stop_Gif_Button   = 1;
   .X_Pos                      = 180,
   .Y_Pos                      = 120,
   .X_Dim                      = 36,
   .Y_Dim                      = 29,
   .AT45_Text                  = 0, 
   .Txt_X_Pos                  = 0,
   .Txt_Y_Pos                  = 0 
 };

now at a function I'd like to pass a pointer at this struct and use the data but I'm not able to do it.
I wrote like this:

void Create_Button ( struct BUTTON_t *button)
{  
  Write_BMP_from_AT45(pgm_read_byte (&button.AT45Addr_Start_Gif_Button),
                      pgm_read_byte (&button.X_Pos),
                      pgm_read_byte (&button.Y_Pos)
					  );
}

but the compiler give me back 3 errors:

../Objects.c:47: error: request for member 'AT45Addr_Start_Gif_Button' in something not a structure or union

and other two errors like this but for X_Pos and Y_Pos.
Where I'm wrong? Please Someone can help me?
Thanks
Davide

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

Read your C textbooks for the correct way to access structure members.

You can read your flash memory (with pgm_read_byte())
You cannot write to the flash memory.

You can write to EEPROM or SRAM.

David.

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

Hi David, thanks for your answer.
I'm not writing the flash memory, the function you saw called Write_BMP_From_AT45 doesn't write in flash but read a BMP from dataflash and write it into screen area.
I use the
pgm_read_byte (&button.AT45Addr_Start_Gif_Button), etc.. for to read theparameter of the struct but maybe it's not the right way to use it.
Bye.
Davide

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

Oh god! I think to have found the solution.
I did't consider that it's a pointer to a structure! I've to write
pgm_read_byte
(&button->AT45Addr_Start_Gif_Button),
I've to use. -> !
Now no errors appear.
Davide

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

But it doesn't run again.... :)
Ok, I've to read better the C Book :)
Davide

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

Now it work well I post if someone need it.

I declared a

typedef struct
{
  ....pharameters
}BUTTON_t;

I initialize the struct like this:

BUTTON_t PROGMEM Button_Start = 
{
   .first_Pharameter  = 1,
   .second_Pharameter = 233,
   etc....
};

I define the function as:

void function (BUTTON_t *Pointer)
{
   print_BMP( pgm_read_byte(&Pointer->first_data),
              pgm_read_byte(&Pointer->seconrd_data),
              etc...
             );   
}

and I call it so:

function ((BUTTON_t *)Button_Start);

Now it runs well.
Davide

[[code] tags added - please get into the habit of doing this yourself in future posts]