Announcement

Collapse
No announcement yet.

Problems with I2c

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problems with I2c

    Hi everybody !
    I've received my new "toy", a PICadillo 35t !
    I have no problems to play with the example given with the libraries and it's fun.
    But i have a problem to play with an I2c item, a Dallas DS1631 who is a temperature sensor.
    I already use this sensor with Arduino, up to 8 sensors in the same time, but with the PICadillo nothing does work.
    I connect Gnd, +3.3V, SCL on pin9 and SDA on pin11 and the two jumpers on J2 jumper but nothing happends.

    Here is the code i try to use, that is an arduino example to read temperature from a DS1631 and print it on Serial monitor. I also modify this to print temperature(s) on 16*4LCD, Nokia3310LCD, and more, and it works great on Arduino.

    Oh, and sorry for my english, i'm french :/


    Code:
    #include <Wire.h>
    
    // PIN adresses are set to GND
    #define DS1631_ADDR 0x90 >> 1
    
    // SETUP
    void setup()
    {
        // Setup Serial connection
        Serial.begin(9600); 
        Serial.println("");
        Serial.println("-----------------------------------");
        Serial.println("DS1631 test: Temp. sensor"); 
        Serial.println("-----------------------------------");
        Serial.println("");
    
        Wire.begin();             // join I2C bus
    
        // Stop conversion to be able to modify "Access Config" Register
        Wire.beginTransmission(DS1631_ADDR);
        Wire.write((int)(0x22)); // Stop conversion
        Wire.endTransmission();  
    
        // Read "Access Config" regsiter
        Wire.beginTransmission(DS1631_ADDR);
        Wire.write((int)(0xAC)); // @AC : Acces Config
        Wire.endTransmission();
        Wire.requestFrom(DS1631_ADDR,1); //Reade 1 byte
        Wire.available();
        int AC = Wire.read(); // read a byte
    
        Serial.print("Acces Config (Before): "); 
        Serial.print(AC);  
        Serial.println("");
    
        // WRITE into "Access Config" Register
        Wire.beginTransmission(DS1631_ADDR);
        Wire.write(0xAC); // @AC : Acces Config
        Wire.write(0x0C); // Continuous conversion & 12 bits resolution
        Wire.endTransmission();
    
        // READ "Access Config" register
        Wire.beginTransmission(DS1631_ADDR);
        Wire.write((int)(0xAC)); // @AC : Acces Config
        Wire.endTransmission();
        Wire.requestFrom(DS1631_ADDR,1);
        Wire.available();
        AC = Wire.read();
    
        Serial.print("Acces Config (AFTER): "); 
        Serial.print(AC);  
        Serial.println("");
    
        // START conversion to get T°
        Wire.beginTransmission(DS1631_ADDR);
        Wire.write((int)(0x51)); // Start Conversion
        Wire.endTransmission();
    }
    
    // Main Loop
    void loop()
    {
        //READ T°
        Wire.beginTransmission(DS1631_ADDR);
        Wire.write((int)(0xAA)); // @AA : Temperature
        Wire.endTransmission();
        Wire.requestFrom(DS1631_ADDR,2); // READ 2 bytes
        Wire.available(); // 1st byte
        int Th = Wire.read(); // read a byte
        Wire.available(); // 2nd byte
        int Tl = Wire.read(); // readread a byte
    
    
        // T° processing
        if(Th>=0x80) //if sign bit is set, then temp is negative
            Th = Th - 256;
        int T_dec=(10*(100*(Tl/16)))/16; // decimal part of the T°
    
        // Display T° on "Serial Monitor"
        Serial.print("Temperature : ");
        Serial.print(Th);   
        Serial.print(".");
        if (T_dec<10)   Serial.print("0");
        if (T_dec<100)   Serial.print("0");
        Serial.print(T_dec);   
        Serial.print(" degC / ");
        Serial.print("Th register: "); 
        Serial.print(Th);  
        Serial.print(" / ");
        Serial.print("Tl register: "); 
        Serial.print(Tl);  
        Serial.println("");
    
        // Wait 1s before restart
        delay(1000);
    }
    Can anybody help me ?

    Best regards, David.
    Last edited by Dagui; 28th September 2014, 01:58 AM.

  • #2
    Do you have the required pull-up resistors on the I2C bus? The Arduino (wrongly) enables its internal pull-up resistors on the IO ports instead of making you use external resistors. I say "wrongly" for two reasons:

    1. It doesn't teach you that you need pull-up resistors, and
    2. The resistors are completely the wrong value, being around 10- to 20-times too large.

    You need to add a resistor between each of SCL and +3.3V and SDA and +3.3V. The resistors should be around 3.3KΩ in value, though anywhere between 1KΩ and 4.7KΩ will suffice. They should both be the same value though.

    Comment


    • #3
      Hello, the problem was this, i found only 10k resistors but it works perfectly Thanks a lot !!

      Comment


      • #4
        Unfortunately, there's a hardware compatibility issue for the I²C pins.

        Pin 18 corresponds to A4 or SCL on the PICadillo but to A4 or SDA on the chipKIT Uno32. Correlatively, pin 19 corresponds to A5 or SDA on the PICadillo but to A5 or SCL on the chipKIT Uno32 ——see attached documents.
        Click image for larger version

Name:	image_322.png
Views:	19
Size:	1.07 MB
ID:	41676 Click image for larger version

Name:	image_323.png
Views:	87
Size:	118.9 KB
ID:	41677
        As a consequence, shields using the I²C bus can't work with the PICadillo.

        Comment


        • #5
          Are you saying that SCL and SDA are backwards on the Picadillo? That will have to be corrected in the next revision that's for sure. For now though of course you could install some short jumper wires on the jumper block J2 to swap them over (1-4, 2-3).

          Looking at the schematics, it looks like you are indeed right. Not sure how that one slipped us by.

          Comment


          • #6
            Another critical issue: the PIC32 doesn't handle the slave I²C protocol correctly. Interrupt is fired every single byte.

            This seems to be a known issue for many PIC32 MCUs.

            See for example issue #310 TWI I2C Wire Library Limited to 1 Byte in Slave Mode at https://github.com/chipKIT32/chipKIT...mment-34546546

            Comment


            • #7
              Not quite sure how this is a critical issue for us when its in regards to Microchip, and not the Picadillo itself.
              Not much we can do about that...
              James

              Comment


              • #8
                Effectively the I2c pins are backwards on the Picadillo, but it is not an insurmountable problem.
                I do not use shields, only home made PCBs, and two wires on the J2 jumper of the Picadillo can delete the problem.

                Thanks everybody for all the time you spent ! Now i will open another post concerning the touch panel.

                Best regards, Dagui

                Comment

                Working...
                X