General
The semf::SoftI2cMaster class emulates an semf::I2c communication interface with two semf::Gpio and a semf::app::Timer. The timer can be a hardware timer or a semf::SoftwareTimer. Because of the performance a hardware timer is recommended.
A single master bus setting with acknowledge, start, stop and restart conditions is supported.
Take care that the semf::Gpio ’s speed setting is as fast as possible.
The I2c frequency is half of the timer’s frequency.
Initialization
To initialize you only need two Gpios and a Timer object. Both Gpios have to be configured as an output in opendrain mode. For the Timer a hardware Timer is recommended.
#include "main.h"
extern TIM_HandleTypeDef htim1;
semf::Stm32F4Timer timer(htim1);
semf::Stm32F4Gpio gpioScl(GPIOB, GPIO_PIN_6);
semf::Stm32F4Gpio gpioSda(GPIOB, GPIO_PIN_7);
i2c.init();
This class used two GPIOs (SCL and SDA) and a Timer and implements a software I2C Master interface.
Usage
uint8_t slaveAddress = 0x50;
void onI2cDataAvailable()
{
}
i2c.dataAvailable.connect(onI2cDataAvailableSlot);
i2c.setAddress(slaveAddress);
static uint8_t readBuffer[12];
i2c.read(readBuffer, sizeof(readBuffer));
void onI2cDataWritten()
{
}
i2c.dataWritten.connect(onI2cDataWrittenSlot);
i2c.setAddress(slaveAddress);
uint8_t writeBuffer[4] = { 1, 2, 3, 4};
i2c.write(writeBuffer, sizeof(writeBuffer));
{
}
i2c.error.connect(onI2cErrorSlot);
Class for representing errors. Every error should have a unique source code. As a user feel encourage...
StaticSlot for lightweight signal/slot implementation. This StaticSlot ist for connecting a signal to...