I am trying to send a float value over an I2C connection.
I have an I2C communication working perfectly and I can easily send a string from one Arduino to another.
As a float in a 32 bit number and i2c transmits 8 bit packets i cannot simply pass the float value to Wire.Send().
I believe the solution may lie with bit shifting of by using pointers to read each byte of the float individually. I would then need to reconstruct the float value.
I believe that would send the low byte of the address of MyFloat. You need to dereference the pointer to get the first byte...
Wire.Send( [glow]*[/glow]MyFloatPtr );
But that only sends the first byte. It needs to be repeated for the remaining three bytes...
Wire.Send( *MyFloatPtr ); // send first byte
++MyFloatPtr;
Wire.Send( *MyFloatPtr ); // the second
++MyFloatPtr;
Wire.Send( *MyFloatPtr ); // third
++MyFloatPtr;
Wire.Send( *MyFloatPtr ); // fourth and final byte
The code above is functionally equivalent to the earlier version.
When i call this method i only get the first byte of the float all the other values as 0xff (tested with logic analyser). i'm not entirely sure how the wire library works but i believe the problem is that i'm calling Wire.send() multiple times. By doing this the bytes are not cued in the buffer before they are requested by the master.
I've just had another look at the following reference page.