Core2 for AWS IoT EduKit BSP 1.5.1
Core2ForAWS_Port_A_I2C_Read
esp_err_t Core2ForAWS_Port_A_I2C_Read(I2CDevice_t device, uint32_t register_address, uint8_t *data, uint16_t length);
esp_err_t Core2ForAWS_Port_A_I2C_Read(I2CDevice_t device, uint32_t register_address, uint8_t *data, uint16_t length)
Reads from I2C peripheral connected to expansion port A.
Definition: core2forAWS.c:522
void * I2CDevice_t
A pointer to the I2C peripheral configuration.
Definition: i2c_device.h:41

Reads from I2C peripheral connected to expansion port A.

This function reads a specified number of bytes starting from the specified register on the peripheral.

Note
Some peripherals do not support specifying a register address to read from. In this scenario, input the I2C_NO_REG macro as the register_address.

Read more about I2C capabilities of the ESP32 microcontroller and available APIs in the ESP-IDF.

The example code allocates a I2C heart rate sensor peripheral called port_A_peripheral of type I2CDevice_t that has an 8-bit device address of 0xA0 (right-shifted by 1-bit to be a 7-bit address) and using the standard baud rate. It then waits 10 seconds before looping to read from the peripheral, and since the device doesn't take a register address, it uses the macro I2C_NO_REG. The reading is printed every 10 seconds to the serial output.

Example:

#include <stdio.h>
#include <stdlib.h>
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#include "esp_log.h"
#include "core2forAWS.h"
#define DEVICE_ADDRESS 0xA0 >> 1
static const char *TAG = "MAIN";
void i2c_test_task(void * param){
vTaskDelay(pdMS_TO_TICKS(10000));
for(;;){
uint8_t heart_rate = 255;
esp_err_t err = Core2ForAWS_Port_A_I2C_Read(port_A_peripheral, I2C_NO_REG, &heart_rate, 1);
if(!err){
ESP_LOGI(TAG, "Heart Rate — %ubpm", heart_rate);
}
vTaskDelay(pdMS_TO_TICKS(10000));
}
Core2ForAWS_Port_A_I2C_Close(port_A_peripheral);
vTaskDelete(NULL);
}
void app_main()
{
xTaskCreatePinnedToCore(&i2c_test_task, "i2c_test_task", 4096, NULL, 5, NULL, 1);
}
void Core2ForAWS_Port_A_I2C_Close(I2CDevice_t device)
Frees the configuration pointer to the I2C peripheral connected on port A.
Definition: core2forAWS.c:530
I2CDevice_t Core2ForAWS_Port_A_I2C_Begin(uint8_t device_address, uint32_t baud)
Allocates a peripheral connected to expansion port A.
Definition: core2forAWS.c:518
void Core2ForAWS_Init(void)
Initializes the power chip with default values, enables battery charging, and initializes all enabled...
Definition: core2forAWS.c:32
Functions to initialize and access Core2 for AWS IoT EduKit hardware features.
#define PORT_A_I2C_STANDARD_BAUD
The standard baud rate for I2C peripherals connected to Port A.
Definition: core2forAWS.h:191
#define TAG
Definition: i2c_device.c:10
#define I2C_NO_REG
Used when the I2C peripheral does not use registers for read/write operations.
Definition: i2c_device.h:24
Parameters
[in]deviceThe device configuration pointer.
[in]register_addressThe address of the register to begin reading from.
[out]dataThe data read from the register(s).
[in]lengthThe number of bytes to read from the peripheral.
Returns
The I2C device configuration.