SAMD51 I2C master not working

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

hi, i am beginner at the atmel mcu and now i am developing a little device with a samd51 based custom board.

 

my board has a security chip and interfaces with it through I2C. so i configurated the SAMD51G18 as I2C master. 

 

i tested i2c1 (SERCOM4) with i2c example function but i could not see any clock or data signal from the i2c pins 

 

here are the schematic 

 

 

 

i assigned gclk0 to the mcu, uart and two i2c. 

 

 

 

now i am testing with the code which atmel start generated. 

 

here is clock, pin initialization code 

 

port and clock initializing code

void I2C_1_PORT_init(void)
{

    gpio_set_pin_pull_mode(PA13,
                           // <y> Pull configuration
                           // <id> pad_pull_config
                           // <GPIO_PULL_OFF"> Off
                           // <GPIO_PULL_UP"> Pull-up
                           // <GPIO_PULL_DOWN"> Pull-down
                           GPIO_PULL_OFF);

    gpio_set_pin_function(PA13, PINMUX_PA13D_SERCOM4_PAD0);

    gpio_set_pin_pull_mode(PA12,
                           // <y> Pull configuration
                           // <id> pad_pull_config
                           // <GPIO_PULL_OFF"> Off
                           // <GPIO_PULL_UP"> Pull-up
                           // <GPIO_PULL_DOWN"> Pull-down
                           GPIO_PULL_OFF);

    gpio_set_pin_function(PA12, PINMUX_PA12D_SERCOM4_PAD1);
}

void I2C_1_CLOCK_init(void)
{
    hri_gclk_write_PCHCTRL_reg(GCLK, SERCOM4_GCLK_ID_CORE, CONF_GCLK_SERCOM4_CORE_SRC | (1 << GCLK_PCHCTRL_CHEN_Pos));
    hri_gclk_write_PCHCTRL_reg(GCLK, SERCOM4_GCLK_ID_SLOW, CONF_GCLK_SERCOM4_SLOW_SRC | (1 << GCLK_PCHCTRL_CHEN_Pos));

    hri_mclk_set_APBDMASK_SERCOM4_bit(MCLK);
}

void I2C_1_init(void)
{
    I2C_1_CLOCK_init();
    i2c_m_sync_init(&I2C_1, SERCOM4);
    I2C_1_PORT_init();
}

 

and here is main 

 

main

int main(void)
{

    struct io_descriptor *I2C_1_io;
    uint8_t s = 0;

 

    USART_0_example();
    
    CRYPTOGRAPHY_0_example();

    I2C_0_example();
 

    i2c_m_sync_get_io_descriptor(&I2C_1, &I2C_1_io);
    i2c_m_sync_enable(&I2C_1);
    i2c_m_sync_set_slaveaddr(&I2C_1, 0xc0, I2C_M_SEVEN);

 

    /* Replace with your application code */
    while (1) {
            io_write(I2C_1_io, (uint8_t *)&s, 1);

            delay_ms(100);

    }

}

 

first,  uart, i2c0 works properly. but when i checked the PA12 pin of the I2C_1 clock with my  oscilloscope , i could not find any signal yet.

i want to know what i missed ?? is it clock problem or something else ?? 

 

previously thanks  :-(

 

----
Hello ~ (^^ 3 i am beginner of atmel mcu. but i will study hard.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Maybe I missed it, But according to your layout above, it doesn't look like you use pull up resistors.  

 

Image result for i2c

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

yes, there is no resistor. when i saw this circuit first time, i also thought as you thought . but the first version of this circuit which is based on SAMD21 works perfectly without pullup resistor. so i think pullup resistor is not necessary.

----
Hello ~ (^^ 3 i am beginner of atmel mcu. but i will study hard.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

But you are pulling them up to VDD right? Either way I2C standard is with a resistor if you want the most reliable communication. The resistor is based off your baud rate I'm not sure how fast you are running at but 10K ohm is recommended at 100khz if you are going faster I would use a 2K ohm resistor and at least try it man why not. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

thanks your reply! i have not thought yet pullup resistor effects the performance. actually speaking, first version circuit has performance issue. but do you think in this case, if i insert t pullup resistor, i will resolve this problem??

----
Hello ~ (^^ 3 i am beginner of atmel mcu. but i will study hard.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I mean if there is no clock then there can be several things going on... I would disconnect or restart the slave and see if you can get a clock out of the master ... I2C Slave protocol will pull down the clock or the datat i forget which one but, if there is an error and then you have to restart the slave or disconnect it or do something to get it to release the lines  

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I2C by design needs pullup resistors. Solve that problem first.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kartman wrote:
I2C by design needs pullup resistors. Solve that problem first.

 

thanks, i will fix it first 

----
Hello ~ (^^ 3 i am beginner of atmel mcu. but i will study hard.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

first of all, i want to say "thanks aberle !" and thanks kartman 

i added pull-up resistor with 10k ohm and then i finally detect clock and data signal !!

 

 

 

 

----
Hello ~ (^^ 3 i am beginner of atmel mcu. but i will study hard.

Last Edited: Thu. Mar 7, 2019 - 06:07 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You've not studied the I2C specification then, have you? Not only did you not put pullup resistors, you then put the wrong value of pullup resistors! Off the top of my head the resistors should be 2k2-3k3 for a 3V circuit with minimal capacitance. 

 

https://www.nxp.com/docs/en/user...

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kartman wrote:

You've not studied the I2C specification then, have you? Not only did you not put pullup resistors, you then put the wrong value of pullup resistors! Off the top of my head the resistors should be 2k2-3k3 for a 3V circuit with minimal capacitance. 

 

https://www.nxp.com/docs/en/user...

 

 

thank you, i will read it  :-)

----
Hello ~ (^^ 3 i am beginner of atmel mcu. but i will study hard.