I2C on Breakout Rak4260

The goal for resolving this issue is to setup the RAK4260 as a master with i2c. We want to read 100 bytes and then write 100 byte of data. Our slave has been confirmed to work with another device as master.

Currently we are not getting any data and the i2c bus times out waiting for data. No data is being read.

The issue is setting up the I2C with the RAK4260-LoRaNode-demo which is located here on Github.

The closest thing I found to code examples using this chip was located on microchip’s documentation for SERCOM with I2C on their website here.

A question I don’t know the answer to is which SERCOM am I suppose to be using? I see references that indicate SERCOM1,SERCOM4, or SERCOM5 being for I2C and cannot find definite answer.

A second question I have is whether there is any additional stuff that needs to be turned on for I2C? Something could not be initiated correctly or at all.

The code follows the logic of the Microchip Basic example on Page 35 but with different parameters. For now, the read function from the slave is the one we are focused on getting completed and is the only one shown.

Thank you in advanced.

Code Below:

Pre main function code:

#define DATA_LENGTH 100
static uint8_t write_buffer[DATA_LENGTH] = {
	0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
	0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,	
	0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,	
	0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,	
	0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
	0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
	0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
	0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
	0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
	0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,

	
};
static uint8_t read_buffer[DATA_LENGTH];

#define SLAVE_ADDRESS 0x50
#define TIMEOUT 1000
struct i2c_master_module i2c_master_instance;

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, SERCOM4,
	 &config_i2c_master);
	i2c_master_enable(&i2c_master_instance);
}

Main Function Code After Initial Setup.

	/* Configure device and enable. */
	configure_i2c_master();
	/* Timeout counter. */
	uint16_t timeout = 0;
	/* Init i2c packet. */
	struct i2c_master_packet packet = {
		.address = SLAVE_ADDRESS,
		.data_length = DATA_LENGTH,
		.data = write_buffer,
		.ten_bit_address = false,
		.high_speed = false,
		.hs_master_code = 0x0,
	};
	
	struct i2c_master_config config_i2c_master;
	i2c_master_get_config_defaults(&config_i2c_master);
	config_i2c_master.buffer_timeout = 10000;
	i2c_master_init(&i2c_master_instance, SERCOM4,&config_i2c_master);
	
	
	printf("I2C INITIALIZED %u \n" , 100);
	
	
	/* Read from slave until success. */
	packet.data = read_buffer;
	while (i2c_master_read_packet_wait(&i2c_master_instance, &packet) !=
	STATUS_OK) {
		/* Increment timeout counter and check if timed out. */
		if (timeout++ == TIMEOUT) {
			break;
		}
	}
	
	printf("I2C Done");
	
	for(int i =0 ; i < DATA_LENGTH ; i++){
		printf("Index");
		printf("%u" , i );
		printf(":");
		printf("%u" , packet.data[i]);
		printf("\n");
	}

Hello @applecrusher

The code below is one of the LoraWAN examples from Microchip Studio.
The i2c slave is ATECC680A crypto chip.

#define SLAVE_ADDRESS				0x28
#define TIMEOUT						1000
#define SLAVE_WAIT_TIMEOUT			10
#define LEN_EUI						256
#define MAC_ADDR_LEN				8

#ifndef EDBG_I2C_MODULE
#define EDBG_I2C_MODULE   					SERCOM1
#endif

#ifndef EDBG_I2C_SERCOM_PINMUX_PAD0
#define EDBG_I2C_SERCOM_PINMUX_PAD0			PINMUX_PA16C_SERCOM1_PAD0
#endif

#ifndef EDBG_I2C_SERCOM_PINMUX_PAD1
#define EDBG_I2C_SERCOM_PINMUX_PAD1			PINMUX_PA17C_SERCOM1_PAD1
#endif

/*********************************************************************//**
\brief    Configures the I2C module as Master
*************************************************************************/
static void configure_i2c_master(void)
{
	/* Create and initialize config structure */
	struct i2c_master_config config_i2c;
	i2c_master_get_config_defaults(&config_i2c);

	/* Change pins */
	config_i2c.pinmux_pad0  = EDBG_I2C_SERCOM_PINMUX_PAD0;
	config_i2c.pinmux_pad1  = EDBG_I2C_SERCOM_PINMUX_PAD1;

	/* Initialize and enable device with config */
	i2c_master_init(&i2c_master_instance, EDBG_I2C_MODULE, &config_i2c);

	i2c_master_enable(&i2c_master_instance);
}

/*********************************************************************//**
\brief		Reads back the device MAC address stored in User page of EDBG
\param[in]  eui - Device EUI read back from EDBG(8 bytes)
*************************************************************************/
 void edbg_eui_read_eui64(uint8_t *eui)
{
	configure_i2c_master();
	uint32_t timeout = 0;
	
	/** Send the request token */
	master_packet.address         = SLAVE_ADDRESS;
	master_packet.data_length     = sizeof(write_buffer);
	master_packet.data            = write_buffer;
	master_packet.ten_bit_address = false;
	master_packet.high_speed      = false;
	master_packet.hs_master_code  = 0x0;
	while (i2c_master_write_packet_wait_no_stop(&i2c_master_instance, &master_packet) !=
			STATUS_OK) {
		/* Increment timeout counter and check if timed out. */
		if (timeout++ == TIMEOUT) {
			return;
		}
	}

	/** Get the extension boards info */
	master_packet.data_length     = 256;
	master_packet.data            = kit_data;
	while (i2c_master_read_packet_wait(&i2c_master_instance, &master_packet) !=
			STATUS_OK) {
		/* Increment timeout counter and check if timed out. */
		if (timeout++ == TIMEOUT) {
			return;
		}
	}
   
    // First 8bytes value is MAC Address
	memcpy(eui, kit_data, MAC_ADDR_LEN);
}
1 Like