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 CCS Technical Support

Problem with EEPROM read/write float custom routine

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



Joined: 27 Aug 2009
Posts: 10

View user's profile Send private message MSN Messenger

Problem with EEPROM read/write float custom routine
PostPosted: Wed Oct 07, 2009 2:02 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Oct 07, 2009 2:32 pm     Reply with quote

Look in this file for routines to do this:
Quote:
c:\program files\picc\drivers\internal_eeprom.c


Or look at this FAQ article:
http://www.ccsinfo.com/faq.php?page=write_eeprom_not_byte
xTeox



Joined: 27 Aug 2009
Posts: 10

View user's profile Send private message MSN Messenger

PostPosted: Wed Oct 07, 2009 2:33 pm     Reply with quote

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...
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