Core2 for AWS IoT EduKit BSP 1.5.1
Core2ForAWS_Port_A_I2C_Begin
I2CDevice_t Core2ForAWS_Port_A_I2C_Begin(uint8_t device_address, uint32_t baud);
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 * I2CDevice_t
A pointer to the I2C peripheral configuration.
Definition: i2c_device.h:41

Allocates a peripheral connected to expansion port A.

This function allocates configuration of an attached I2C peripheral on expansion port A with a minimum baud rate of 100,000Hz. The macro PORT_A_I2C_STANDARD_BAUD can used for a generally compatible baud rate for most peripherals. The maximum rate supported by the ESP32-D0WD is 5MHz.

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

Note
The AXP192 PMU is configured to output 5v on the expansion port's VCC pin. Some peripherals require 3.3V and requires adjusting the output from the AXP192. This is currently unsupported, but can be acheived using the AXP192 driver (located in the core2forAWS/axp192 folder) for advanced developers.

The example code allocates a I2C heart rate sensor peripheral in the variable 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
void Core2ForAWS_Init(void)
Initializes the power chip with default values, enables battery charging, and initializes all enabled...
Definition: core2forAWS.c:32
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
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]device_addressThe 7-bit I2C device address.
[in]baudThe baud rate of I2C communications.
Returns
A pointer to the I2C device configuration.