Probems on I2C of SAMC

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

Hi guys, I am having problems to write and consequently read anything to/from I2C master at SERCOM3 (I know this SERCOM is compatible with I2C).

 

I have followed all the instructions on AT03250: SAM D/R/L/C I2C Master Mode (SERCOM I2C) Driver, but my microcontroller (ATSAMC21E18A) does not send any byte (I have also checked with an oscilloscope).

 

Have anybody worked with this micro? Does anyone have a sample code working? Do I have to multiplex any pin?

If needed I can also put my code here.

 

Thank you all, Felipe.

Regards!
FS.

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

Regarding pin multiplexing there is a default for each SERCOM, for C21E I think it would be

#define SERCOM3_PAD0_DEFAULT      PINMUX_PA22C_SERCOM3_PAD0
#define SERCOM3_PAD1_DEFAULT      PINMUX_PA23C_SERCOM3_PAD1

which should be ok (well if that is where you expect the signals). Normally you do need to specify what pins to use (the actual mux setup is done by the ASF driver however). You set this in the config members pinmux_pad0 and  pinmux_pad1.

You could try to change the device, SERCOM and pins in an existing ASF quick start project for C21 like "Quick start for the SAM SERCOM I2C Master Driver (Polled) - SAMC21 Xplained Pro". You could search for some topics here also, will be relevant even if they concern D20/D21 and others since the SERCOM is compatible. Or show the code.
/Lars

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

Do you have pull-up resistors btw?

/Lars

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

Hey Lajon, I do have 10k pull-ups resistors and they should be okay for 100kHz clocks. Beside, I have checked the signal with an oscilloscope and I can't even see a signal fall (there is no clock at all).

I am using SERCOM3 and, if I am not mistaken, SERCOM3 has default pins PA16 (PAD[0]) and PA17(PAD[1]). At least that is what the datasheet says.

 

About the code I have done exactly what the manual tells. The only thing that I have done differently is use the SERCOM3 instead of the SERCOM define. Here is the configuration routine.

 

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;
	/* Initialize and enable device with config. */
	i2c_master_init(&i2c_master_instance, SERCOM3,&config_i2c_master);
	i2c_master_enable(&i2c_master_instance);
}

 

I have also tried to send a single byte from I2C using direct register access or using the ASF i2c_master_write_byte function. No success yet.

 

I will check the pins again. 

Regards!
FS.

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

I looked again at the datasheet and now I realized that there is something that made me confuse: on page 34 there are two SERCOM columns: one called SERCOM and another SERCOM-ALT. For the first the PA16 belongs to SERCOM0 and for the second it belongs to SERCOM3.

What are the differences between those two?

Regards!
FS.

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

The  SERCOM (or other function for a pin) that will be used is determined by the setting of the Peripheral Function Multiplexer for that pin.

David

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
	config_i2c_master.pinmux_pad0    = PINMUX_PA16D_SERCOM3_PAD0;
	config_i2c_master.pinmux_pad1    = PINMUX_PA17D_SERCOM3_PAD1;

Is needed because the default (which is in the ASF implementation so not something you can see in the datasheet) is PA22 and PA23.

The difference between SERCOM and SERCOM-ALT is that they are two different mux functions, notice the column headers 'C' and 'D', the 'D' is included in the pin naming above (while  'C' is included in  PINMUX_PA22C_SERCOM3_PAD0).

/Lars

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

I changed for SERCOM1 and it works... Thank you both!

Regards!
FS.