Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 19 of 19

Thread: I2C problem

  1. #1

    I2C problem

    Hi,
    I have a problem with I2C. I am running default Wire.h slave sender master reciever codes but the slave wont answer to master. and I am using 2K resistors.
    Click image for larger version. 

Name:	IMG_20190313_122353.jpg 
Views:	43 
Size:	67.6 KB 
ID:	16152
    Attached Thumbnails Attached Thumbnails Click image for larger version. 

Name:	IMG_20190313_122357.jpg 
Views:	49 
Size:	99.5 KB 
ID:	16153  

  2. #2
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    5,679
    Oh my.. you really should practice soldering..
    maybe a connection problem.
    edit: connections on 18/19 on the left teensy do not look good. mabe it works, maybe not.

    Please post the programs for both, Master and slave.

  3. #3
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,299
    This may be a little late to save those boards, but maybe it'll help?


  4. #4
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,299
    To move forward on this, I'd suggest putting an LED on each of those 4 pins and try running the LED blink example. That can help you figure out if the pins really are connected.

    If you do find 1 or more pins need to be re-soldered, here's a couple ideas that might help...

    Solder has a chemical added called "flux". It's essential to getting good results. A common novice mistake looks like applying the solder to your iron, then with a ball of molten solder hanging off the tip of the iron, touching it to the pad and pin to be soldered. All the flux chemical ends up only on your iron, where it can't have the cleaning & whetting action on the pad & pin.

    Put the tip of your iron onto the existing solder and let it get fully molten. Then apply a little more solder, hopefully touching or coming as close as practical to the pad. This will add more solder, which isn't really what you want... the thing you *really* need is some of the flux chemical to get into the molten mix. It will really help the new and old solder to flow.

    Always leave the iron in contact for at least half a second after you withdraw the solder. Letting all 3 metals (the solder, the pin, and the pad) fully heat to the same temperature is important. Then they all cool together. That's essential for forming a good bond between the metals.

  5. #5
    Thanks for the ideas, the connection between the pins and teensy is good. The program suddenly started working I dont know what I have done, but now it works.

    However I have another problem. I am playing with TCA 8418. But as soon as I try to end transmission the program wont contiunue.
    Code:
    #include <Wire.h>
    #include <WireKinetis.h>
    
    #define adress 0x34
    
    void setup() {
      
      Serial.begin(9600);
      Serial.println("setup begin");
      Wire.beginTransmission(adress);
                Serial.println("setup");
      Wire.write(0x01);
                 Serial.println("setup");
      Wire.write(0xFF);   //initial setup of the chip
                Serial.println("setup");
      Wire.endTransmission();
    
     
    Serial.println("setup");
    
       Wire.beginTransmission(adress);
       Wire.write(0x1E);    
       Wire.write(00000001); // set row 1
       Wire.endTransmission();
    Serial.println("setup");
        Wire.beginTransmission(adress);
        Wire.write(0x1E);
        Wire.write(00001111); //set colum 1-4
         Wire.endTransmission();
         Serial.println("setup done");
        
    }
    byte REG;
    void loop() {
      Wire.beginTransmission(adress);
        Wire.write(0x04);
        Wire.endTransmission();
        Wire.requestFrom(adress, 1);        // request 1 byte(s) from slave device.  
        while(Wire.available())             // slave may send less than requested.  
        { 
          REG = Wire.read();  
          Serial.println(REG); 
        } 
    
    }
    This is the output of the code
    setup begin
    setup
    setup
    setup

    I dont know what to do, and I sadly dont have osciloscope

  6. #6
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    5,679
    Quote Originally Posted by MistrKernnunos View Post
    The program suddenly started working I dont know what I have done, but now it works.
    Do yourself a favour and solder it better... it works now, but you can't be sure it still works in a hour, a week or a month.

  7. #7
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    5,679
    https://www.arduino.cc/en/Reference/WireEndTransmission

    endTransmission gives you a returncode - have you tried to print it?

  8. #8
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,299
    Quote Originally Posted by Frank B View Post
    but you can't be sure it still works in a hour, a week or a month.
    Or when the temperature changes, causing slight thermal expansion of the material.

  9. #9
    Hi, I resoldered the pins. Teensy can find the chip and start a transmission, but it hangs when I end the transmission. Do you have any ideas what icould caus the hang?

  10. #10
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,299
    Quote Originally Posted by MistrKernnunos View Post
    Do you have any ideas what icould caus the hang?
    Could be a hardware issue, like one or both pins stuck low.

    Could be something wrong on the software side.

    Since we can't see your new hardware connection, and we don't know what you're doing for the code, how could anyone help? You need to show us what you're doing, ideally with enough info that anyone could reproduce the problem if they have the right hardware.

  11. #11
    I am using the same code, that I have posted earlier. And there is a foto of the circuit and the chip that I am using is TCA 8418.
    Click image for larger version. 

Name:	IMG_20190317_191230.jpg 
Views:	22 
Size:	103.6 KB 
ID:	16167

  12. #12
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    5,679
    Try the i2c scanner example. Does it find the chip?

  13. #13
    Yes, it finds the chip

  14. #14
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    5,679
    Well then problem is in your code... I don't have this chip. Have you read the datasheet?

  15. #15
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,299
    Your code in msg #5 is missing Wire.begin().

    Open any of the Wire library examples to see how it should be done.

  16. #16
    Thanks for the advice. Now it is not hanging on the endTransmission, but it is returning 2 and that means NACK on adress, but I am sure that the adress is right.

  17. #17
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,299
    Maybe run that scanner example again? It's the easiest way to check the address.

  18. #18
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    5,679
    if adress== correct goto post #14, last sentence.

  19. #19
    Thanks for the advices. Now it is working well, bur I have different problem. the problem is that whenever I press a button that is in the key matrix the chip wont respond to any messeges. the wire.endTransmission returns 2.
    Code:
    #include <Wire.h>
    
    #include <WireKinetis.h>
    
    #include "Wire.h"
    
    #define adress 0x34
    #define row 0x07
    #define col 0x0F
    
    void setup() {
    pinMode(11, INPUT_PULLUP);
    pinMode(13, OUTPUT);
      Serial.begin(9600);
      delay(1000);
      Serial.println("setup begin");
      Wire.begin();
      
      Wire.beginTransmission(0x34);
                Serial.println("setup");
      Wire.write(0x01);
                 Serial.println("setup");
      Wire.write(0x01);   //initial setup of the chip
                Serial.println("setup");
    int n = Wire.endTransmission();
    
    Serial.println(n);
    
    Serial.println("setup");
    
       Wire.beginTransmission(adress);
       Wire.write(0x1D);    
       Wire.write(row); // set row 1
      n = Wire.endTransmission();
      Serial.println(n);
    Serial.println("setup");
        Wire.beginTransmission(adress);
        Wire.write(0x1E);
        Wire.write(col); //set colum 1-4
        n = Wire.endTransmission();
    
          Wire.beginTransmission(adress);
       Wire.write(0x29);    
       Wire.write(row); // set debounce for row 1
      n = Wire.endTransmission();
      Serial.println(n);
    
        Wire.beginTransmission(adress);
       Wire.write(0x2A);    
       Wire.write(col); // set row 1
      n = Wire.endTransmission();
      Serial.println(n);
      
         Serial.println("setup done");
        Serial.println(n);
    }
    byte REG;
    void loop() {
    
      int INTERUPPT = digitalRead(11);
      if(INTERUPPT == LOW)
      {
         digitalWrite(13, HIGH);
      }
      
      delay(1000);
      
      
        Wire.beginTransmission(0x34);
        Wire.write(0x1E);
        Serial.print("prenos: ");
       int m = Wire.endTransmission();
       Serial.println(m);
        Wire.requestFrom(0x34, 1);        // request 1 byte(s) from slave device.  
        while(Wire.available())             // slave may send less than requested.  
         {
          
          
          REG = Wire.read();  
          Serial.print("reg: ");
          Serial.println(REG);
          
         }
      
     // delay(1000);
    
    
    }

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •