| View previous topic :: View next topic | 
	
	
		| Author | Message | 
	
		| younder 
 
 
 Joined: 24 Jan 2013
 Posts: 53
 Location: Brazil
 
 
			    
 
 | 
			
				| Write/read float to internal DSPic30F eeprom - SOLVED! |  
				|  Posted: Sat Jan 21, 2017 10:47 am |   |  
				| 
 |  
				| 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
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Sat Jan 21, 2017 9:22 pm |   |  
				| 
 |  
				| 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
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Sun Jan 22, 2017 9:23 am |   |  
				| 
 |  
				| 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
 |  | 
	
		|  | 
	
		|  |