Hi,
I am trying to write and read a sequence of bytes (e.g. : FF FF FF FF) to/from UART using M52259. Basically I have managed to write a program which sends characters and receive. I want to develop this one but, no success using integers. I have attached source files from the project with characters. Maybe someone can give me a hint (I am e beginner ).
thank you!
Solved! Go to Solution.
To send integer you might set
as integers and on the other side you deserialise this response
so
int myint=1234567;
for(i=0;i<4;i++)
{
response->DATA[i]=((myint & (0xFF << (i*8)))>>(i*8));
}
and on other side when you deserialise
int myint=0;
for(i=0;i<4;i++)
{
myint |= (response->DATA[i])<<(i*8);
}
This way code is endian dependless and it only depends on fact that reciver has integers of size 32 bits.
If you know that both sides uses same endianess you can apply union when you serialise/deserialise.
http://en.wikipedia.org/wiki/Endianness
http://www.wellho.net/resources/ex.php4?item=c209/union.c
To send integer you might set
as integers and on the other side you deserialise this response
so
int myint=1234567;
for(i=0;i<4;i++)
{
response->DATA[i]=((myint & (0xFF << (i*8)))>>(i*8));
}
and on other side when you deserialise
int myint=0;
for(i=0;i<4;i++)
{
myint |= (response->DATA[i])<<(i*8);
}
This way code is endian dependless and it only depends on fact that reciver has integers of size 32 bits.
If you know that both sides uses same endianess you can apply union when you serialise/deserialise.
http://en.wikipedia.org/wiki/Endianness
http://www.wellho.net/resources/ex.php4?item=c209/union.c
Thank you for the useful information!