| i2c.h | ||
| README.md | ||
i2c
This is a simple bit-banged software implementation of the i2c protocol.
How to use
It is intended to be used as a single-header library. Just download it and add to your project.
This is an example to scan for devices:
#include <stdint.h>
#include <stdio.h>
#include "i2c.h"
void print_device(uint8_t addr){
printf("Found device at 0x%02X\n", addr);
}
int main(){
i2c_init();
i2c_scan(print_device);
return 0
}
Configuration
If you need to toggle defaults, you need to define some values BEFORE including the library for first time.
For example, to change from i2c standard mode (100 kbps) to fast mode (400 kbps) you do:
#define I2C_FREQ 400
#include "i2c.h"
At the moment the following variables are configurable:
-
I2C_FREQ: How fast are the transactions. Protocol supports multiple modes, typical values are 100, 400, and 1000, but you need to check your maximum ratings with your device datasheet.
-
SDA_GPIO: Which GPIO to use as SDA
-
SCL_GPIO: Which GPIO to use as SCL
-
I2C_CONTROLLER: Which controller is targeted. Currently the library has support for the following microcontrollers (with its constant values):
- Raspberry Pico (both RP2040 and RP2350): 0