View previous topic :: View next topic |
Author |
Message |
xTeox
Joined: 27 Aug 2009 Posts: 10
|
Problem with EEPROM read/write float custom routine |
Posted: Wed Oct 07, 2009 2:02 pm |
|
|
Hi, everyone!
I'm with a problem... my routine doesn't work. It is only writing the first byte (but it access 4 times the loop 'for') and I don't know why. And, when tries to read, it return 0.
The routines:
Code: |
float EEPROM_ler (int e, int tamanho)
{
int i;
float dados;
dados = 0;
for (i = 0; i < tamanho; i++)
*((int*) &dados + i) = read_eeprom (e + i);
return dados;
}
////////////////////////////////////////////////////////////////
void EEPROM_gravar (int e, int32 dados, int tamanho)
{
int i;
for (i = 0; i < tamanho; i++)
write_eeprom (e + i, *((int*) &dados + i));
}
|
I've tried to do the same with this alteration:
Code: | float EEPROM_ler (int e)
{
float dados;
int i;
int* ptr = &dados;
dados = 0;
for (i = 0; i < 4; i++)
*(ptr++) = read_eeprom (e++);
return dados;
}
////////////////////////////////////////////////////////////////
void EEPROM_gravar (int e, int32 dados)
{
char i;
int* ptr = &dados;
for (i = 0; i < 4; i++)
write_eeprom (e++, *(ptr++));
}
|
But still the same!
PS.: it works with alterations to read/write long (int16). |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
xTeox
Joined: 27 Aug 2009 Posts: 10
|
|
Posted: Wed Oct 07, 2009 2:33 pm |
|
|
huahuahuahuahuahuahu........ forget it!.... I found the mistake!!!!!!!!!.... it's on the parameters of write function... I was sending a int32 data, when it must be a float data... uhahuahuauhhuahua....
ty who try to find a answer... |
|
|
|