• Moved UART1 away from B6/B7. Good point - I overlooked that... Then, did some further testing (full test script source below) :

    
    function init()
    {
      try {
        I2C1.writeTo(0x68,0);
        var data=I2C1.readFrom(0x68,3);
        console.log(data);
    	LED2.set();
      } catch (error) {
        console.log(error);
    	LED1.set();
      }
    }
    
    function freeI2Cbus(clkPin, sdaPin)
    {
      var i;
      while (!sdaPin.read())
      {
    	 clkPin.set(); //about 150 us : OK
    	 clkPin.reset();
    	 clkPin.set();
      }
      clkPin.set();
      sdaPin.set();
      // 9 pulses will end any bus state
      for (i=0; i<10; i++)
      {
    	  clkPin.set();
    	  clkPin.reset();
      }
      sdaPin.reset();
      clkPin.set();
      sdaPin.set(); // 0->1 @ clk 1 : STOP
      clkPin.set(); // delay...
    }
    
    function onInit()
    {
      Serial1.setup(9600,{rx:A10, tx:A9}); // Move away from B6, B7
      freeI2Cbus(B6, B7);
      I2C1.setup({ scl : B6, sda: B7 });
      LED1.reset();
      LED2.reset();
      init();
      //setTimeout(init,2000);
    }
    

    Consider the attached scope waveforms : CH1 = SCL, CH2 = SDA. Top = the 'freeI2Cbus()' waveform, Middle = the same with slower timebase. No signals for the next 500ms (or more, no matter how long I wait). Looks like 'init()' does not generate any signal on SCL or SDA !

    The bottom waveform is the result of using the software 'new I2C()' class : everything perfect, proving the hardware is OK.

    var i2c;
    function onInit()
    {
      Serial1.setup(9600,{rx:A10, tx:A9}); // Move away from B6, B7
      freeI2Cbus(B6, B7);
      i2c = new I2C(); // Use bit bang ...
      i2c.setup({ scl : B6, sda: B7 });
      LED1.reset();
      LED2.reset();
      init();
      //setTimeout(init,2000);
    }
    ...
    
    function init()
    {
      try {
        i2c.writeTo(0x68,0);
        var data=i2c.readFrom(0x68,3);
        console.log(data);
    	LED2.set();
      } catch (error) {
        console.log(error);
    	LED1.set();
      }
    }
    
    

    Hardware is a DS3231 chip, not a module, with a direct connection with a 2x 2cm PCB trace and 2 3k3 pullups. DS3231 gets its power from the 3V3 output of the Pico, everything properly decoupled.

    Moving B6/B7 to B3/B10 is difficult since the design is already using the pins for other stuff... But if that is the only solution...

    All of this testing was done with the Pico connected to the IDE (over USB). So my comment about problems 'after save()' do not hold true anymore I'm afraid.


    1 Attachment

    • i2c1.jpg
About

Avatar for jgw @jgw started