We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
xdata unsigned long var_long _at_ 0x0150; unsigned char * pointer; pointer=0x0150; var_long=0x45213256; SBUF=*pointer; ... SBUF=*(pointer+1); ... SBUF=*(pointer+2); ... SBUF=*(pointer+3); ...
my uart communication work, when i send datas byte one byte. when i try to send a long variable in above form , uart com. dont work. is this format illegal? xdata unsigned long var_long _at_ 0x0150; unsigned char * pointer; pointer=0x0150; var_long=0x45213256;
*pointer : 0x45 ?? *(pointer+1) : 0x21 ?? *(pointer+2) : 0x32 ?? *(pointer+3) : 0x56 ??
"uart com. dont work"
What do you mean by "don't work"?
Does it not transmit anything at all?
Does it transmit something, but just not the expected data? - if so, what does it transmit?
Have you single-stepped this in the simulator?
How do you know that it's your UART comms that "don't work" rather than whatever is receiving the data?
Are you correctly waiting for the transmittion of one byte to complete before loading the next into SBUF?
you'r right, my question wasn't clear;
SBUF=0x12; ... SBUF=0x45 ... SBUF=0x63; ... SBUF=0x24;
(... = while(TI==0); TI=0;)
when i send datas byte one byte, i can get this bytes at other device. but i try to send a byte which at specific adress. (in this form other device can't get anything)
xdata unsigned long long_data _at_ 0x0010;
long_data=0x45256541;
0x0010 : 0x45 0x0011 : 0x25 0x0012 : 0x65 0x0013 : 0x41
"in this form other device can't get anything"
You have two possibilities:
1. Your code didn't send anything;
2. Your code did send something, but the other device didn't receive it.
Only you can answer that!
Are you sure that your other device can cope with receiving bytes so close together?
You are assigning an integer to a generic pointer. I think you either need to make the pointer mspace specific or assign it thusly:
pointer = (unsigned char xdata *)0x0150;
Or just get rid of the "magic numbers" altogether and let the compiler do it for you:
pointer = &var_long;
that way you know it'll be right!
which is the alternative non-portable approach
Which is portable, and may be no less efficient...
"Or just get rid of the "magic numbers" altogether ..."
But then it wouldn't be nearly so magic when (if) it works and what's the fun in that?
like: pointer[0], pointer[1], pointer[2], pointer[3]
like
pointer = (unsigned char *) &longvar; ... SBUF = *pointer++; // msb (assumes big-endianness) ... SBUF = *pointer++; // 2sb ... SBUF = *pointer++; // 3sb ... SBUF = *pointer++; // lsb
To be pedantic, that's post-increment - not auto-increment
If the underlying architecture has an auto-increment facility, the compiler might use it to implement the post-increment...
Right you are, thank you. I stand corrected :)