|
|
View previous topic :: View next topic |
Author |
Message |
roby Guest
|
help request about i2c |
Posted: Thu Oct 13, 2005 10:16 am |
|
|
I do not speak english very well, so please, accept my simple explanation.
I have two pics that communicate over i2c
One pic has a variable A that is a 16 bit integer, it must be transmitted to the second pic and written to a variable B that is 16 bit integer
How can I do?
The compiler has a routine for i2c that transmits variables 8 bit integer
Thanks |
|
|
Ttelmah Guest
|
|
Posted: Thu Oct 13, 2005 10:44 am |
|
|
You just write the two bytes that 'make up' the integer, and put them back together again at the other end.
There are a lot of code methods to access the bytes, but CCS, has two functions, 'make8', and 'make16', that do this for you. So if you send LSB first, then:
if you have the 16 bit value declared as 'val_to_send',
i2c_write(make8(val_to_send,0);
//Sends the first byte
12c-write(make8(val_to_send,1);
//sends the second.
At the other end, if you receive the two bytes into two 8bit variables called 'low', and 'high', you can re-assemble it with:
val_received=make16(high,low);
Best Wishes |
|
|
|
|
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
|