A demo/development platform for software-based I2C protocol.
It can be run on a desktop by starting two instances of the executable that communicate with each other using a JSON file or it can be build and uploaded to run on the AVR/STM32 microcontrollers.
Each target platform is using the same version of the I2C library by compiling the appropriate HAL implementation and has a common console source code for control.
There are scripts for each target platforms that help with deployment under utils/
.
The logic analyzer can be used to examine the transmission.
Create the build-system
cmake -S . -B build-desktop/ -DTARGET_PLATFORM=DESKTOP
Build executable
cmake --build build-desktop/
Run
build-desktop/src/desktop/DesktopDemo
Run Tests
build-desktop/test/Tests
Files generated in the output/
directory such as pins.log
, master.log
or slave.log
can be used by logic analyzer by providing the filenames in the analyzer-properties file.
{
"logicProbe": { "file": "/path/to/the/pins.log" },
"loggingProbe": [
{ "name": "Transceiver", "file": "/path/to/the/master.log" },
{ "name": "Receiver", "file": "/path/to/the/slave.log"}
],
"signals": ["SDA", "SCL", "Transmitter SDA", "Transmitter SCL", "Receiver SDA", "Receiver SCL"]
}
cmake -S . -B build-avr/ -DTARGET_PLATFORM=AVR -DCMAKE_TOOLCHAIN_FILE=cmake/avr/avr-toolchain.cmake
cmake --build build-avr/
sudo make -C build-avr/ upload_AvrDemo
Or by using utils/build-avr.sh
.
The value of BC547
BJTs with the load of I2C bus current
cmake -S . -B build-stm32/ -DTARGET_PLATFORM=STM32 -DCMAKE_TOOLCHAIN_FILE=cmake/stm32/stm32-toolchain.cmake
cmake --build build-stm32/
sudo make -C build-stm32/ Stm32Demo.bin_upload
Or by using utils/build-stm32.sh
.
Each of the deployments allows for control of the I2C library using the console from src/common/console.c
.
These commands are used to retrieve current settings of the I2C configuration.
- get role: Returns the current role of the I2C device (MASTER or SLAVE).
- get address: Returns the current I2C address.
- get time_unit: Returns the current time unit setting.
- get logging_level: Returns the current logging level (0-5).
- get scl: Returns the current level of the SCL pin.
- get sda: Returns the current level of the SDA pin.
These commands are used to set various parameters of the I2C configuration.
- set role [master/slave]: Sets the role of the I2C device.
- set address [0-127]: Sets the I2C address.
- set time_unit [0-1000]: Sets the time unit.
- set logging_level [0-5]: Sets the logging level.
- set scl [0/1]: Sets the SCL_OUT pin level
- set sda [0/1]: Sets the SDA_OUT pin level
These commands are specific to writing operations in I2C communication.
- write byte [0-255]: Writes a byte to I2C.
- write addr [0-127] [r/w]: Writes an address with read or write data direction bit.
- write start: Sends a start condition.
- write stop: Sends a stop condition.
- write to [0-127] [0-255]: Writes to an address with a payload.