Pages: [1]   Go Down
Author Topic: Wire.write vs Wire.send. new problems  (Read 1300 times)
0 Members and 2 Guests are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi all,

i had been writing some code a few months ago, and now i wanted to get back to this project; I installed
version 1.0 of the arduino software and i encountered some problems with the wire library.
I have a twin relay connected to the arduino trough I2C and that worked ok when i used wire.send.
This is the information of the register :

Name: Relay A timed off
Format:<Saddr><4><Hbyte><Lbyte><Stop>

This command turns relay A off in n number of
200mS intervals. As an example if the relay is
required to go off 30 seconds after the
command then ( 30 / 0.2 = 150) the delay
would be 150.
This should be converted to hex and sent as
two bytes so the command in this case would
be
<S-addr><4><0x0><0x96><Stop>

The number is a 16 bit value so the maximum
delay is 65535 200mS intervals or just over
218 minutes (3.6 hours). No checking is made
if the number entered is not within this range
so unpredictable results will occur if a number
is entered outside of this range.

So in my 0.22 arduino i programmed :

Code:
  Wire.beginTransmission(RelayBoard);     
  Wire.send(4);                       // Send register to write to
  Wire.send(0x0);                       // send low value to be sent to it
  Wire.send(0x3);                       // send high value to be sent to it
  Wire.endTransmission();
Worked perfectly. Now in arduino 1.0, i'm no longer able to use Wire.send , i had to use Wire.write .
When i change my .send to .write , i get the following error at the line wire.send (0x0);

"call of overloaded 'write(int) is ambigous"

so i tried :
Code:
wire.write ((byte) 0x0)
 wire.write ((byte) 0x3)

but my relay does not respond to this smiley-sad Any idea what's up with this ? thanks

Logged

0
Offline Offline
Jr. Member
**
Karma: 4
Posts: 88
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
Wire.write((uint8_t) value);

should work in the way that you describe.  You could use a byte for the value and I don't think the compiler will complain.  In any event, your technique sounds good:  The only difference you should see is that
  • They replaced send() with write
  • They removed send(int value), because in that one it was doing a cast to a uint8_t under the covers, thereby trashing the topmost byte of your 16-bit int.

Significantly, though, the code works the same under the covers.

You must have something else wrong with your code.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok, i know where i have to look then. Thanx allot for the reply !
Logged

Pages: [1]   Go Up
Jump to: