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

eeprom to byte

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







eeprom to byte
PostPosted: Fri Jul 11, 2003 2:35 am     Reply with quote

I have a Ds2438 ROM address stored on eeprom in the hex form e.g. 26D1B0330000001D. I must now pass the address to the touch_write_byte function in bytes. Can anyone advise? I have tried a few this including the following, but without success!

void Match_ROM()
{
int EEPRi;
char ID[4];

touch_present();
touch_write_byte(0x55); //match ROM
ID[0]='0'; ID[1]='x';
for (EEPRi=135; EEPRi<151; EEPRi=EEPRi+2)
{
ID[2]=read_eeprom(i);
ID[3]=read_eeprom(i+1);
touch_write_byte(ID); // Write ROM address
}
}
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515867
R.J.Hamlett
Guest







Re: eeprom to byte
PostPosted: Fri Jul 11, 2003 4:21 am     Reply with quote

:=I have a Ds2438 ROM address stored on eeprom in the hex form e.g. 26D1B0330000001D. I must now pass the address to the touch_write_byte function in bytes. Can anyone advise? I have tried a few this including the following, but without success!
:=
:=void Match_ROM()
:={
:=int EEPRi;
:=char ID[4];
:=
:=touch_present();
:=touch_write_byte(0x55); //match ROM
:=ID[0]='0'; ID[1]='x';
:=for (EEPRi=135; EEPRi<151; EEPRi=EEPRi+2)
:= {
:= ID[2]=read_eeprom(i);
:= ID[3]=read_eeprom(i+1);
:= touch_write_byte(ID); // Write ROM address
:= }
:=}

I would assume, you actually need to convert from hex, to the raw value, which you are not doing. Something like:

#define intval(x) ((x)<':')?((x)-'0'):((x)-'7')

void Match_ROM()
{
int EEPRi;
char ID;

touch_present();
touch_write_byte(0x55); //match ROM
/* I am not sure why you are setting up extra bytes here?. My memory of the '1 wire' interface, is that after the '55' header byte, it looks immediately for the 64bit address?. If so, it is the address bytes that are now needed. */
for (EEPRi=135; EEPRi<151; EEPRi=EEPRi+2)
{
//Put the first hex value as the MS nibble
ID=intval(read_eeprom(i))<<4;
//Add the second, as the LS nibble
ID=ID+intval(read_eeprom(i+1));
/* At this point, the two hex digits, have been
assembled to a single byte (not two bytes as you show). */
touch_write_byte(ID); // Write ROM address
}

This is based on some accesses I did to another 'one wire' device, so may not be right, but I think is probably closer to the right answer. :-)

Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515868
Levett Prins
Guest







Re: eeprom to byte
PostPosted: Fri Jul 11, 2003 6:11 am     Reply with quote

Thanx, I am trying your advise but I get compiler error:

"Error[60] C:\PROGRA~1\PICC\PROJECTS\BMS\mach_rom.c 19 : Expecting :"

at function:

ID=intval(read_eeprom(EEPRi))<<4;

Can you perhaps see the problem?

Thank you

Levett
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515869
R.J.Hamlett
Guest







Re: eeprom to byte
PostPosted: Fri Jul 11, 2003 7:31 am     Reply with quote

:=Thanx, I am trying your advise but I get compiler error:
:=
:="Error[60] C:\PROGRA~1\PICC\PROJECTS\BMS\mach_rom.c 19 : Expecting :"
:=
:=at function:
:=
:=ID=intval(read_eeprom(EEPRi))<<4;
:=
:=Can you perhaps see the problem?
:=
:=Thank you
I presume you did actually get a 'colon' on the #define line?. For some reason, the board turned the character in the #define line into a 'smiley' (I presume the keysequence used of close bracket colon open bracket, happens to match a value the board remaps into this character...). If not, then this is the cause of the error. Also, I think I'd actually do the input, and the translation on two lines, as:

int8 temp;
....

temp=read_eeprom(EEPRi);
ID=intval(temp);

Though the compiler ought to 'hold' the value, and not recall the function, I wouldn't want to rely on this, so using a temproary value avoids this worry.

Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515871
Levett Prins
Guest







Re: eeprom to byte
PostPosted: Fri Jul 11, 2003 11:26 am     Reply with quote

Still no joy!!!

The code now look like this, but I still get the same error.

void Match_ROM()
{
#define intval(x) ((x)<':')?((x)-'0')):((x)-'7')

int8 EEPRi, EEPR_value;
char ID;

touch_present();
touch_write_byte(0x55); //match ROM
touch_write_byte(0x26); // Write FAMILY CODE for ds2438
for (EEPRi=135; EEPRi<151; EEPRi=EEPRi+2)
{
EEPR_value=read_eeprom(EEPRi);
ID=intval(EEPR_value)<<4; //Put the first hex value as the MS nibble
EEPR_value=read_eeprom(EEPRi+1);
ID=ID+intval(EEPR_value); //Add the second, as the LS nibble
touch_write_byte(ID); // Write ROM address
}
}


Thank you


Levett
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515884
R.J.Hamlett
Guest







Re: eeprom to byte
PostPosted: Fri Jul 11, 2003 1:30 pm     Reply with quote

:=Still no joy!!!
:=
:=The code now look like this, but I still get the same error.
:=
:=void Match_ROM()
:={
:=#define intval(x) ((x)<':')?((x)-'0')) :=
It is the 'face' in the above line, that I was referring to. This is meant to be a ':', and has to be for the code to work. Annoyingly, if you just 'cut' the code and paste it, the face gets removed, but the colon gets lost. However I went the other way, and the board turned the colon, into the face!...

:=int8 EEPRi, EEPR_value;
:=char ID;
:=
:=touch_present();
:=touch_write_byte(0x55); //match ROM
:=touch_write_byte(0x26); // Write FAMILY CODE for ds2438
:=for (EEPRi=135; EEPRi<151; EEPRi=EEPRi+2)
:= {
:= EEPR_value=read_eeprom(EEPRi);
:= ID=intval(EEPR_value)<<4; //Put the first hex value as the MS nibble
:= EEPR_value=read_eeprom(EEPRi+1);
:= ID=ID+intval(EEPR_value); //Add the second, as the LS nibble
:= touch_write_byte(ID); // Write ROM address
:= }
:=}
:=
:=
:=Thank you
:=
:=
:=Levett
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515885
Levett Prins
Guest







Re: eeprom to byte
PostPosted: Sat Jul 12, 2003 4:41 am     Reply with quote

I THINK I AM ALMOST THERE!

I understood you correctly regarding the "smiley". It appears the it represents ":(" and not only ":". So that's fixed now,
but I do not get the correct conversion.

E.g. for EEPROM values D & 1 (that represents the HEX value D1),
I correctly get ID=D0 with function: ID=intval(EEPR_value)<<4;

But with function ID=ID+intval(EEPR_value); , I then get ID=01.

It looks like the first value has been overwritten. To debug, I used: fprintf(PC, "ID=\%X", ID); to get the ID value.

Any suggestions?

Thanx

Levett
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515905
R.J.Hamlett
Guest







Re: eeprom to byte
PostPosted: Sun Jul 13, 2003 2:43 am     Reply with quote

:=I THINK I AM ALMOST THERE!
:=
:=I understood you correctly regarding the "smiley". It appears the it represents "<img src="http://www.ccsinfo.com/pix/forum/sad.gif" border="0">" and not only ":". So that's fixed now,
:=but I do not get the correct conversion.
:=
:=E.g. for EEPROM values D & 1 (that represents the HEX value D1),
:=I correctly get ID=D0 with function: ID=intval(EEPR_value)<<4;
:=
:=But with function ID=ID+intval(EEPR_value); , I then get ID=01.
:=
:=It looks like the first value has been overwritten. To debug, I used: fprintf(PC, "ID=\%X", ID); to get the ID value.
:=
:=Any suggestions?
:=
:=Thanx
:=
:=Levett
Uurgh!.
There is no real reason hy the value should 'overwrite' like this, but you can try a couple of other ways of writing the same line, which might make the compiler get it right.

ID+=intval(EEPR_value);
//should be the same, but the use of the automatic addition
//may prevent the behaviour.

ID!=intval(EEPR_VAL);

In the latter case 'or-ing' the value, should remove any risk of the overwrite.

Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515919
Levett Prins
Guest







Re: eeprom to byte
PostPosted: Sun Jul 13, 2003 2:30 pm     Reply with quote

The != did not work at all. The += worked only with e.g. 0xD1 but with 0x33 it generated 0x06 (adding 3+3). I eventually got it working with the following (non-elegant) code:

void Match_ROM()
{
#define intval(x) ((x)<':')?((x)-'0'):((x)-'7')

int8 EEPRi, i, EEPR_value;
char ID;

touch_present();
touch_write_byte(0x55); //match ROM
touch_write_byte(0x26); // Write FAMILY CODE for ds2438
for (EEPRi=137; EEPRi<151; EEPRi=EEPRi+2)
{
ID=0X00;
EEPR_value=intval(read_eeprom(EEPRi+1));
for (i = 0; i < 4; i++) if(bit_test(EEPR_value,i)) bit_set(ID,i);
EEPR_value=intval(read_eeprom(EEPRi));
for (i = 0; i < 4; i++) if(bit_test(EEPR_value,i)) bit_set(ID,(i+4));
touch_write_byte(ID); // Write ROM address
}
}

Thank you very much for your advise and patience.

Regards

Levett
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515927
R.J.Hamlett
Guest







Re: eeprom to byte
PostPosted: Mon Jul 14, 2003 6:02 am     Reply with quote

:=The != did not work at all. The += worked only with e.g. 0xD1 but with 0x33 it generated 0x06 (adding 3+3). I eventually got it working with the following (non-elegant) code:
:=
The html on the board, my keyboard/web browser, and what I am typing, are enjoying themselves... The character with the equals sign, should be the vertical pipe character, but is being shown as the exclamation mark... The pipe character, should result in the values being "or'ed", which should be a safe way of combining the values.

:=void Match_ROM()
:={
:=#define intval(x) ((x)<':')?((x)-'0') :=
:=int8 EEPRi, i, EEPR_value;
:=char ID;
:=
:=touch_present();
:=touch_write_byte(0x55); //match ROM
:=touch_write_byte(0x26); // Write FAMILY CODE for ds2438
:=for (EEPRi=137; EEPRi<151; EEPRi=EEPRi+2)
:= {
:= ID=0X00;
:= EEPR_value=intval(read_eeprom(EEPRi+1));
:= for (i = 0; i < 4; i++) if(bit_test(EEPR_value,i)) bit_set(ID,i);
:= EEPR_value=intval(read_eeprom(EEPRi));
:= for (i = 0; i < 4; i++) if(bit_test(EEPR_value,i)) bit_set(ID,(i+4));
:= touch_write_byte(ID); // Write ROM address
:= }
:=}
:=
:=Thank you very much for your advise and patience.
:=
:=Regards
:=
:=Levett
The code behaviour, _should_ be fixable by bracketting. I deliberately ensured the function was fully bracketted in the define, but the compiler is behaving as if it treating the precedence differently from my expectations.

Your test loop approach, is a bit 'brute force', and will give the wrong result for any hex character above 9...
For instance, 'D1', will actually result in '41' being put into the output.

Do it like this instead, and avoid the 'inline' appoach I was using:

int intval(int val) {
if ((val)<':') return (val-'0');
return (val-'7');
}

void Match_ROM()
{
int8 EEPRi, i, EEPR_value;
char ID;

touch_present();
touch_write_byte(0x55); //match ROM
touch_write_byte(0x26); // Write FAMILY CODE for ds2438
for (EEPRi=137; EEPRi<151; EEPRi=EEPRi+2)
{
ID=intval(read_eeprom(EEPRi));
ID = ID + (intval(read_eeprom(EEPRi+1) * 16)
touch_write_byte(ID); // Write ROM address
}
}

You are showing some very 'odd' behaviours by the compiler. Is it perhaps a fairly old version?.

Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515945
Levett Prins
Guest







Re: eeprom to byte
PostPosted: Sat Jul 19, 2003 1:24 am     Reply with quote

Thank you, it is working fine.

I am using PCM ver 3.163, so this could not have been the prolem with the previous approaches.

Regards

Levett
___________________________
This message was ported from CCS's old forum
Original Post ID: 144516173
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