Master Device
Overview of basic functions for I2C communication with Feelix
Define the addresses for each of the slaves that will be connected to the master.
#define SLAVE_0_ADDRESS 0x70
#define SLAVE_1_ADDRESS 0x71
#define SLAVE_2_ADDRESS 0x72Create MasterDevice object. Pass an array with the addresses of all slaves as argument.
uint8_t slaves[] = { SLAVE_0_ADDRESS, SLAVE_1_ADDRESS };
/* initialize master device */
MasterDevice I2C_Master(slaves);Initialization
Initialize master device in void setup()
/* initialize as Master device */
I2C_Master.init(
ESP32_SDA, //I2C Data (SDA)
ESP32_SCL, //I2C Clock (SCL)
CLOCK_SPEED::SLOW_MODE, //Clock frequency
// CLOCK_SPEED::SLOW_MODE = 100000
// CLOCK_SPEED::FAST_MODE = 400000
DEBUG, //(optional)
// bool debug (set to false before production)
callbackArr, //(optional)
// array with callback functions (functionPtr)
callbackLength); //(optional) size of arrayReceiving motor parameters
Request motor parameters (angle, velocity, voltage, status) from slave device in void loop()
Create a callback function to receive the device parameters from the slave. Call before void setup()
The received data is stored in the following variables
Sending variables to slave
Send a float variable to the slave. The function triggers a callback at the slave side at slaveCallbackIndex of the callback array.
float data,
uint8_t slaveAddress,
uint8_t slaveCallbackIndex
Send an integer variable to the slave. The function triggers a callback at the slave side at slaveCallbackIndex of the callback array.
int16_t data,
uint8_t slaveAddress,
uint8_t slaveCallbackIndex
Send a byte variable to the slave. The function triggers a callback at the slave side at slaveCallbackIndex of the callback array.
uint8_t data,
uint8_t slaveAddress,
uint8_t slaveCallbackIndex
Send a char array to the slave. The function triggers a callback at the slave side at slaveCallbackIndex of the callback array.
char (&data)[]
uint16_t dataSize
uint8_t slaveAddress,
uint8_t slaveCallbackIndex
Last updated
Was this helpful?
