CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Write/read float to internal DSPic30F eeprom - SOLVED!

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
younder



Joined: 24 Jan 2013
Posts: 53
Location: Brazil

View user's profile Send private message

Write/read float to internal DSPic30F eeprom - SOLVED!
PostPosted: Sat Jan 21, 2017 10:47 am     Reply with quote

Hi Guys,

DSPic30F4012
Compiler V5.051

I'm trying to use the example available in the "C:\Program Files\PICC\Drivers\internal_eeprom.c" for Reading and writing a float32 to internal DSpic30F eeprom but It did not worked yet.

Code:

// Purpose:    Write a 32 bit floating point number to internal eeprom
// Inputs:     1) An eeprom address. Four eeprom locations will be used.
//             2) The floating point number to write to internal eeprom
// Outputs:    None
void write_eeprom_float(unsigned int16 address, float32 data)
{
   write_eeprom(address, &data, 4);
}

// Purpose:    Read a 32 bit floating point number from internal eeprom
// Inputs:     An eeprom address
// Outputs:    The floating point number read from the internal eeprom
float32 read_eeprom_float(unsigned int16 address)
{
   float32 data;

   read_eeprom(address, &data, 4);
   
   return(data);
}




Code:


//Totalizer_Km & Totalizer_L are Float Type

//*** Write ***
 write_eeprom_float(0x06, Totalizer_Km);  //0x06 & 0x07
      delay_ms(2);
 write_eeprom_float(0x08, Totalizer_L);   //0x08 & 0x09
      delay_ms(2);

//*** Read ***
Totalizer_Km=read_eeprom_float(0x06); 
Totalizer_L=read_eeprom_float(0x08);






Any help would be very appreciated!
Hugo
_________________
Hugo Silva


Last edited by younder on Sun Jan 22, 2017 9:24 am; edited 1 time in total
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Jan 21, 2017 9:22 pm     Reply with quote

I don't have PCD so I can't test it. But if I did, the first thing I would do
is try addresses that have more separation between them. Just as a test:
Code:

write_eeprom_float(0x10, Totalizer_Km);   
      delay_ms(2);
write_eeprom_float(0x20, Totalizer_L);   
      delay_ms(2);

//*** Read ***
Totalizer_Km = read_eeprom_float(0x10); 
Totalizer_L = read_eeprom_float(0x20);

Also, with the PCM and PCH compilers the compiler waits in a polling loop
until the write eeprom is done. No external delay is necessary. I suspect
the same thing is true for PCD.

I noticed that the function names you're using are different than what
I have in vs. 5.066 in internal_eeprom.c. I have the names shown below,
with the word 'eeprom' at the end:
Code:

void write_float_eeprom(INT_EEPROM_ADDRESS address, float32 data)

float32 read_float_eeprom(INT_EEPROM_ADDRESS address)
younder



Joined: 24 Jan 2013
Posts: 53
Location: Brazil

View user's profile Send private message

PostPosted: Sun Jan 22, 2017 9:23 am     Reply with quote

Thanks PCM programmer! you hit the nail right in the head! It was my mistake... we need 4 bytes in the eeprom for storing a float variable... the data was overwriting 2 bytes - We can close this tread
_________________
Hugo Silva
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group