Pages: [1]   Go Down
Author Topic: 4 x I2C devices check not work propary  (Read 286 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 46
I just want to learn more :)
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

what i am doing wrong.
i need at start-up a I2C check if the connection is made proparly.

Code:
  byte Respond1;                            // At startup, check if I2C Device responding
  byte Respond2;                            // At startup, check if I2C Device responding
  byte Respond3;                            // At startup, check if I2C Device responding
  byte Respond4;                            // At startup, check if I2C Device responding

Code:
void setup()
{
  Serial.begin(9600);
  lcd.begin(24, 2);                                 // Type LCD
  lcd.clear();
  Wire.begin();                                     // Wake up I2C Master. Connect pin 4 (the clock, or SCL, pin) and pin 5 (the data, or SDA, pin)
   
   lcd.setCursor(4,0);
   lcd.print("I2C Initializing");
   lcd.setCursor(0,1);
   
Wire.beginTransmission(Tuner_address_TX);
    Wire.requestFrom(Tuner_address_TX, 1);                      // request 1 bytes from Tuner_address_TX 0x60
    Respond1 = Wire.endTransmission();
  if (Respond1 == 0)
    lcd.print("");
    else
    lcd.setCursor(0,1);
    lcd.print("  I2C ERROR Tuner 0x60  ");
   
 delay(2500);
    lcd.setCursor(0,1);

Wire.beginTransmission(PCF1_BUTTON);
    Wire.requestFrom(PCF1_BUTTON, 1);                      // request 1 bytes from PCF1_BUTTON 0x3E
//    Respond2 = Wire.endTransmission();
  if (Respond2 == 1)
    lcd.print("");
    else
    lcd.setCursor(0,1);
    lcd.print(" I2C ERROR Buttons 0x3E ");

 delay(2500);
    lcd.setCursor(0,1);

Wire.beginTransmission(PCF2_LED);
    Wire.requestFrom(PCF2_LED, 1);                      // request 1 bytes from PCF2_LED 0x3D
    Respond3 = Wire.endTransmission();
  if (Respond3 == 0)
    lcd.print("");
    else
    lcd.setCursor(2,1);
    lcd.print("  I2C ERROR Led's 0x3D  ");

 delay(2500);
    lcd.setCursor(0,1);

Wire.beginTransmission(PCF3_RELAY);
    Wire.requestFrom(PCF3_RELAY, 1);                      // request 1 bytes from PCF3_RELAY 0x3B
    Respond4 = Wire.endTransmission();
  if (Respond4 == 0)
    lcd.print("");
    else
    lcd.setCursor(1,1);
    lcd.print(" I2C ERROR Relay's 0x3B ");

    delay(2500);
    lcd.setCursor(0,1);
   
    lcd.clear();
    lcd.setCursor(7,0);
    lcd.print("I2C Ready");
   
    delay(2000);
    lcd.clear();
« Last Edit: June 18, 2013, 04:29:38 pm by Midway » Logged

Portugal
Offline Offline
Edison Member
*
Karma: 27
Posts: 1413
Tomorrow I will know a BIT more than yesterday
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Wire.beginTransmission(Tuner_address_TX);
    Wire.requestFrom(Tuner_address_TX, 1);                      // request 1 bytes from Tuner_address_TX 0x60
    Respond1 = Wire.endTransmission();
From here:http://arduino.cc/en/Reference/WireBeginTransmission
Quote
Begin a transmission to the I2C slave device with the given address. Subsequently, queue bytes for transmission with the write() function and transmit them by calling endTransmission().
What are you transmitting?
If you just want read the byte from the slave you should just use the requestFrom() to invoke slave the byte.
Then you should use the available() and read() functions.  

Quote
Respond1 = Wire.endTransmission();
This returns a boolean value
What are you receiving from it?
« Last Edit: June 18, 2013, 05:05:29 pm by HugoPT » Logged

Debian,Mint,Ubuntu
Arduino Mega 2560
Arduino Nano
Arduino Duemilanove
MAC OS Montain Lion
Raspberry PI Model B


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

what is the problem?  when i experimented with something similar i had an issue that any time there was a problem it just hung!  and so i couldn't report anything.

also make sure that you have the right value for a resistor; especially if you have over a half meter of cable (check the spec).

we just spent an hour trying to debug an i2c (three arduinos) and found that if one was powered off, or the code was wrong everything hung and it hung on the Wire.endTransmission (which is of course when the data is transmitted).

you raise a good point though - how to debug things like this.  the truth is that once you get it working you probably won't go back again; so it might not be worth the trouble to check this.

another thing we bumped into was volatile memory  (volatile int).  i'm not sure if you can store data in there and harvest it after a reset or not. 
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

First things first. Get your shift key repaired. When you refer to yourself it is I, not i.

Code:
Wire.beginTransmission(PCF3_RELAY);
    Wire.requestFrom(PCF3_RELAY, 1);                      // request 1 bytes from PCF3_RELAY 0x3B
    Respond4 = Wire.endTransmission();
  if (Respond4 == 0)
    lcd.print("");
    else
    lcd.setCursor(1,1);
    lcd.print(" I2C ERROR Relay's 0x3B ");

Better read this: http://gammon.com.au/i2c

If you are planning to have " I2C ERROR Relay's 0x3B " appear if there is an error, you need some more braces than you have shown.
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

How to use this forum

Point 10. Post in proper sentences.
Logged

Pages: [1]   Go Up
Jump to: