samd21 i2c failing after a while

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

Hello everyone,

I'm working on a sodaq sara board (samd21j18a based) with Atmel Studio. I'm having a hard time querying the UBLOX M8Q gps chip using a i2c port.

 

I2C is configured using asf (I know I should not...) and works for a couple of seconds and then constantly times out.

 

Here's the setup:

	struct i2c_master_config config_i2c_master;
	i2c_master_get_config_defaults(&config_i2c_master);
	config_i2c_master.buffer_timeout =55000;

	config_i2c_master.pinmux_pad0 = PINMUX_PA16C_SERCOM1_PAD0;
	config_i2c_master.pinmux_pad1 = PINMUX_PA17C_SERCOM1_PAD1;
	config_i2c_master.baud_rate = I2C_MASTER_BAUD_RATE_100KHZ ;
	config_i2c_master.baud_rate_high_speed = I2C_MASTER_BAUD_RATE_100KHZ;
	config_i2c_master.generator_source = GCLK_GENERATOR_0;
	config_i2c_master.scl_low_timeout = false;
	config_i2c_master.master_scl_low_extend_timeout = false;
	config_i2c_master.scl_stretch_only_after_ack_bit = false;
	config_i2c_master.slave_scl_low_extend_timeout = false;
	config_i2c_master.master_scl_low_extend_timeout = false;

	while(i2c_master_init(&i2c_master_instance, SERCOM1, &config_i2c_master)   != STATUS_OK);
	i2c_master_enable(&i2c_master_instance);

 

and the ~1hz routine polling data from the chip

 

struct i2c_master_packet wr_packet;
	wr_packet.address     = gps._addr;
	wr_packet.data_length = POLL_DATA_AMOUNT;
	wr_packet.data        = inputReg;
	wr_packet.high_speed = false;
	wr_packet.ten_bit_address=false;

	if(i2c_master_read_packet_wait(&i2c_master_instance, &wr_packet) !=	STATUS_OK)
	{
			return;
	}

	ioport_toggle_pin_level(RED_LED);
	putN(inputReg,POLL_DATA_AMOUNT);

It works a couple of time (and data is forwarded  to UART by putN) then "master_read_packet" starts failing every time with 0x12 error code.

 

One suggestion from the UBLOX community is that clock stretching should be disabled on the mcu. I think it is the case in my configuration but I'm not entirely sure.

 

I have pretty much tried any setting provided by the asf I2C master framework and I am running out of ideas, any help would be much appreciated.

 

Thanks.

Last Edited: Thu. Jun 13, 2019 - 07:48 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I never found the reason of my problem but coding the I2C driver from scratch solved my issue.