I2C: ASF: SAMD20: Unexpected 80uA in sleep (standby). How to really turn off I2C?

Go To Last Post
2 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Wow I can't find this.  I just want to turn off I2C and see the 2uA sleep current I've always been seeing.  Can someone give me the magic secret code that I'm apparently not supposed to know about?

 

void configure_i2c_master(void)
{
    /* Initialize config structure and software module. */
    struct i2c_master_config config_i2c_master;
    i2c_master_get_config_defaults(&config_i2c_master);
    
    /* Change buffer timeout to something longer. */
    config_i2c_master.buffer_timeout = 10000;
    config_i2c_master.pinmux_pad0 = PINMUX_PA16C_SERCOM1_PAD0;//Pin 16 SDA
    config_i2c_master.pinmux_pad1 = PINMUX_PA17C_SERCOM1_PAD1;//Pin 17 SCL

    config_i2c_master.generator_source = GCLK_GENERATOR_1;

    /* Initialize and enable device with config. */
    i2c_master_init(&i2c_master_instance, SERCOM1, &config_i2c_master);
    i2c_master_reset(&i2c_master_instance);    
    //! [enable_module]
    //i2c_master_enable(&i2c_master_instance);
}

 

notice I commented  i2c_master_enable(&i2c_master_instance);  that's not the problem, it's i2c_master_init();  wouldn't you think that i2c_master_reset() would restore the SAMD20 to the state it was in before calling i2c_master_init()....?  well it doesn't.

 

Inside of i2c_master_init(), the problem is the last line, return _i2c_master_set_config(module, config);

 

Inside of _i2c_master_set_config(), the problem is this block:

 

    /* SERCOM PAD1 - SCL */
    if (pad1 == PINMUX_DEFAULT) {
        pad1 = _sercom_get_default_pad(sercom_hw, 1);
    }
    pin_conf.mux_position = pad1 & 0xFFFF;
    pin_conf.direction    = SYSTEM_PINMUX_PIN_DIR_OUTPUT_WITH_READBACK;
    system_pinmux_pin_set_config(pad1 >> 16, &pin_conf);

 

that call to system_pinmux_pin_set_config() causes an extra 80uA to show up.   but only the one for SCL.  The corresponding block of code for SDA doesn't affect the current.

 

system_pinmux_pin_set_config() is a wrapper of _system_pinmux_config(), and inside _system_pinmux_config(), there's a bunch of crap that I haven't crammed into my head yet, and don't want to.  I really don't want to!  Please help : (

Last Edited: Thu. Oct 15, 2015 - 11:33 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I found the answer, looking at that pinmux code:

 

    /* SERCOM PAD1 - SCL */
    if (pad1 == PINMUX_DEFAULT) {
        pad1 = _sercom_get_default_pad(sercom_hw, 1);
    }
    pin_conf.mux_position = pad1 & 0xFFFF;
    pin_conf.direction    = SYSTEM_PINMUX_PIN_DIR_OUTPUT_WITH_READBACK;
    system_pinmux_pin_set_config(pad1 >> 16, &pin_conf);

 

Changing pin_conf.direction to SYSTEM_PINMUX_PIN_DIR_INPUT gave me the 2uA I wanted, so that told me there had to be something connected to whatever pin SCL was on.  In other words, I'm using a SAMD20 Xplained Pro (with no external connections), so there had to be something on that board.  I changed pinmux and sercom to something else, and it worked.  You can see the wrong settings I had in the first post.