How to configure two I2C SERCOM on SAMD20E17?

Discussions around product based on ARM Cortex M0+ core.

Moderator: nferre

terbo
Posts: 26
Joined: Sun Oct 06, 2013 11:04 pm

How to configure two I2C SERCOM on SAMD20E17?

Fri Jul 25, 2014 4:06 pm

Hi.
I will use SAMD20E17 with two I2C SERCOMs (one in master mode and one in slave mode). Acc to Table 5-1: "PORT Function Multiplexing on page" of the SAMD20 datasheet, I understand that for SAMD20Exx (please correct me if I'm wrong):
PA16 is SERCOM1 (data)
PA17 is SERCOM1 (clk)
PA22 is SERCOM3 (data)
PA23 is SERCOM3 (clk).

First, I only implement SERCOM3; with the following configuration:

Code: Select all

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);

	config_i2c_master.buffer_timeout = 1000;  // TEB: was 10000
     i2c_master_init(&i2c_master_instance, SERCOM3, &config_i2c_master);
	i2c_master_enable(&i2c_master_instance);	
#endif
}
This works fine, but when I try to send some data, the following happens:

Code: Select all

I call the:  i2c_master_write_packet_wait(...)
... which calls: _i2c_master_write_packet(...)
static enum status_code _i2c_master_write_packet(
		struct i2c_master_module *const module,
		struct i2c_master_packet *const packet)
{
	SercomI2cm *const i2c_module = &(module->hw->I2CM);

	/* Return value. */
	enum status_code tmp_status;
	uint16_t tmp_data_length = packet->data_length;

	_i2c_master_wait_for_sync(module);

	/* Set address and direction bit. Will send start command on bus. */
	i2c_module->ADDR.reg = (packet->address << 1) | I2C_TRANSFER_WRITE;
The above statement causes a branch to the HardFault_Handler()

Prior to entering HardFault_Handler(), the datastructures contains the following:
i2c_module = 0x42001400

packet = 20000058
->address = 0x00000055
->data_lenght = 0x00000004
->data = 0x0cde4 <bq_buf_ctrl> "" (*data=0)
->ten_bit_adress = false
->high_speed = false
->hs_master_code = 0
->address = 0x00000055


Any clues ?

It seems like my pointers all have OK (?) values ?
Why this branch to HardFault_Handler() ?
Are there any configuration error for this SERCOM3?

I'll very much appreaciate assistance with this issue.

Best Regards Terje Bohler

Return to “SAM D20 Cortex-M0+ MCU”

Who is online

Users browsing this forum: No registered users and 1 guest