ESP-32 I2C Read & Write with STM32F0

RafaelArkenos
Posts: 2
Joined: Mon Jul 22, 2019 5:27 pm

ESP-32 I2C Read & Write with STM32F0

Postby RafaelArkenos » Mon Jul 22, 2019 5:34 pm

Hello there guys;

I'm working in a project who i needs to communicate a ESP32 with STM32F0 using I2C.. i'm already capable to read or write into STM32F0 but when im reading trought I2C and tries to stop to read and start do write the ESP32 somehow stops to communicate with STM32. Someone have any application capable to read and write trought I2C?

I'm using SDK-IDF.

This is the read and write code that i'm using:

Code: Select all

esp_err_t i2c_read(uint8_t address, uint8_t *buffer, uint16_t length)
{
	//printf("Entrei no I2C_READ");
    esp_err_t result;
    i2c_cmd_handle_t cmd = i2c_cmd_link_create();
    i2c_master_start(cmd);
    i2c_master_write_byte(cmd, (address << 1) | I2C_MASTER_READ, ACK_CHECK_ENABLE);
    if (length > 1) {

    //	printf("Entrei no IF > 1");
        i2c_master_read(cmd, buffer, length - 1, ACK_VAL);
    }
    i2c_master_read_byte(cmd, buffer + length - 1, NACK_VAL);
    i2c_master_stop(cmd);
    result = i2c_master_cmd_begin(I2C_MASTER_NUM, cmd, 1000 / portTICK_RATE_MS);
    i2c_cmd_link_delete(cmd);

    return result;
}

esp_err_t i2c_write(uint8_t address, uint8_t *buffer, uint16_t length) {

	esp_err_t result;
	i2c_cmd_handle_t cmd = i2c_cmd_link_create();
	i2c_master_start(cmd);
	i2c_master_write_byte(cmd, (address << 1) | I2C_MASTER_WRITE, ACK_CHECK_ENABLE);
	i2c_master_write(cmd, buffer, length, ACK_CHECK_ENABLE);
	i2c_master_stop(cmd);
	result = i2c_master_cmd_begin(I2C_MASTER_NUM, cmd, 1000 / portTICK_RATE_MS);
	i2c_cmd_link_delete(cmd);

	return result;
}
Thanks in advance!

Who is online

Users browsing this forum: No registered users and 71 guests