Serial Communication : 8bit
dkwon
Posts: 13
Hello,
I am doing serial communcation between pc and javelin.
Since using sendByte funtion, I can only send 8bit data. Is there any way to get higher resolution data?
Thanks in advance.
I am doing serial communcation between pc and javelin.
Since using sendByte funtion, I can only send 8bit data. Is there any way to get higher resolution data?
Thanks in advance.
Comments
int c;
txUart.sendByte(c);
txUart.sendByte(c>>>8); //notice the unsigned shift
On the receiving side (eg. pc), the program must·know when to expect an integer.
You could send a synchronize value that is never an existing value, for example 0xFFFF.
regards peter
How can i send negative value?
In PC side java, how can i convert the data from javelin?
A signed integer of 16bits has dedicated b15 as the sign bit.
On the receive end:
int L = receiveByte(); //assuming you send low byte first
int H = receiveByte();
int value = (H<<8)|(L&0xFF); //16bits value
regards peter
Can you give me an example of negative values also for Javelin side and PC side?
How can I know it is negative in PC side?
Do I have to send additional byte to notify it is negative like 0:negative and 1: positive?
For synchronization, you mention that I can use 0xFFFF. But javelin complains the number is out of something.
Please give me how can I synchronize PC and javelin.
Thanks alot!!
For unsigned 16bits values use short.
Example:
int p = -32768;
short q = 0x8000;
int r = (short)0x8000;
p,q and r all have the same value, namely 0x8000,
but p and r are treated as signed.
positive values 0 to 32767 (hex 0x0000-0x7FFF)
negative values -32768 to -1 (hex 0x8000 to 0xFFFF)
if -32768 is never a valid value for your·data, you can use 0x8000 to synchronize.
On the receive end (your pc program), ints may be 32bits.
In that case assembling a 16bits value always is positive.
Then you can do this:
int L = receiveByte(); //lowbyte
int H = receiveByte(); //highbyte
int R = (H<<8)|(L&0xFF); //16bits value
int result = (R >= 0x8000) ? R-65536 : R; //make negative int
If your pc program has a 16bits integer type (like int16) you could use that.
regards peter
Post Edited (Peter Verkaik) : 10/26/2005 5:01:05 PM GMT