I2C on Atmel Start

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

Hi,

I have a SAMD11 configured as I2C Master Sync and a SAMD21 configured as a Slave Sync.

Despite several attempts, it looks like the two parties can't communicate.

 

Is there anyone with some idea why?

 

MASTER (SAMD11)

Master SAMD11

 

#include <atmel_start.h>

struct io_descriptor *I2C_0_io;
int32_t result;

void I2C_init(void)
{

	i2c_m_sync_get_io_descriptor(&I2C_0, &I2C_0_io);
	i2c_m_sync_enable(&I2C_0);
	i2c_m_sync_set_slaveaddr(&I2C_0, 0x12, I2C_M_SEVEN);
}

int main(void)
{
	/* Initializes MCU, drivers and middleware */
	atmel_start_init();
	I2C_init();

	/* Replace with your application code */
	while (1)
	{
		result = io_write(I2C_0_io, (uint8_t *)0xFF, 1);
		delay_ms(10);
	}
}

 

 

SLAVE (SAMD21)

SLAVE SAMD21

 

#include <atmel_start.h>

struct io_descriptor *io;
uint8_t               c;

void I2C_slave_init(void)
{
	i2c_s_sync_get_io_descriptor(&I2C_0, &io);
	i2c_s_sync_set_addr(&I2C_0, 1);
	i2c_s_sync_enable(&I2C_0);
}

int main(void)
{
	/* Initializes MCU, drivers and middleware */
	atmel_start_init();

	PORT->Group[1].DIRSET.reg = PORT_PB30;
	PORT->Group[1].OUTSET.reg = PORT_PB30;

	I2C_slave_init();

	/* Replace with your application code */
	while (1)
	{
		io_read(io, &c, 1);
		delay_ms(10);

		if(c == 0xFF)
		{
			PORT->Group[1].OUTCLR.reg = PORT_PB30;
		}

	}
}

 

Thanks a lot in advance for any kind advice.

 

Filo

This topic has a solution.

Last Edited: Wed. Oct 18, 2017 - 09:21 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Show us your schematic, what pull up resistors are you using on the SDA/SCL lines?

 

Jim

 

 

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

Hi Jim,

I am using 4.7Kohm on both SDA and SCL as pullup resistors.

Circuit is 3.3V

 

I2C

 

Thanks so much for your help

 

Filo

Last Edited: Tue. Oct 17, 2017 - 07:42 PM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Check your addresses.  The master is talking to slave 0x12 via  i2c_m_sync_set_slaveaddr(&I2C_0, 0x12, I2C_M_SEVEN) and the slave is listening to address to 0x01 via i2c_s_sync_set_addr(&I2C_0, 1).

 

Try setting the addresses to the same value.

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

Thanks so much ScottMN, definitely a very good spot!

 

I think there could be a BUG in the atmel start interface cause i have set 0x12 as slave address (as per picture above) in the slave config. interface and nevertheless the value was not set.

 

Below the working code for reference:

 

SLAVE

#include <atmel_start.h>

struct io_descriptor *io;
uint8_t               c;

void I2C_slave_init(void)
{
	i2c_s_sync_get_io_descriptor(&I2C_0, &io);
	i2c_s_sync_set_addr(&I2C_0, 0x12);
	i2c_s_sync_enable(&I2C_0);
}

int main(void)
{
	/* Initializes MCU, drivers and middleware */
	atmel_start_init();

	PORT->Group[1].DIRSET.reg = PORT_PB30;
	PORT->Group[1].OUTSET.reg = PORT_PB30;

	I2C_slave_init();

	/* Replace with your application code */
	while (1)
	{
		io_read(io, &c, 1);
		delay_ms(10);

		if(c == 0xFF)
		{
			PORT->Group[1].OUTCLR.reg = PORT_PB30;
		}
		else
		{
			PORT->Group[1].OUTSET.reg = PORT_PB30;
		}

	}
}

 

MASTER

#include <atmel_start.h>

struct io_descriptor *I2C_0_io;
int32_t result;

void I2C_init(void)
{

	i2c_m_sync_get_io_descriptor(&I2C_0, &I2C_0_io);
	i2c_m_sync_enable(&I2C_0);
	i2c_m_sync_set_slaveaddr(&I2C_0, 0x12, I2C_M_SEVEN);
}

int main(void)
{
	/* Initializes MCU, drivers and middleware */
	atmel_start_init();
	I2C_init();

	/* Replace with your application code */

	uint8_t b = 0xFF;

	while (1)
	{
		result = io_write(I2C_0_io, &b, 1);
		delay_ms(10);
	}
}

 

Thanks again,

 

Filo