Dein Warenkorb ist gerade leer!
I2C-Bus Hardware Konfiguration
…
Am Anfang wäre eine Hardware Konfiguration immer gut.
Beispiel: i2c4 mux Bus 1: dig_in 0x20 <dig_in 12-20> halt automatisch weiterzählen. I2c4 mux Bus 2: dig_in 0x20 <dig_in 21-28> usw. das für dig_out und auch ain_in und ain_out
Das ist eine sehr gute Idee – das ermöglicht eine strukturierte Initialisierung und automatische Zuweisung der IOs auf mehreren I²C-Bussen mit Multiplexern.
🔧 Idee für ein Konfigurationsformat:
typedef struct {
uint8_t i2c_bus; // z. B. 4 für I2C4
uint8_t mux_channel; // MUX-Kanal (falls vorhanden)
uint8_t i2c_addr; // I²C-Adresse des Expanders
uint8_t io_start; // Startindex für globale IO-Zuweisung
uint8_t io_count; // Anzahl der IOs
char io_type[8]; // "din", "dout", "ain", "aout"
} IOHardwareConfig;
🧠 Beispielkonfiguration:
IOHardwareConfig config_table[] = {
{ 4, 1, 0x20, 12, 8, "din" }, // dig_in 12–19 auf MUX Bus 1
{ 4, 2, 0x20, 20, 8, "din" }, // dig_in 20–27 auf MUX Bus 2
{ 4, 0, 0x21, 0, 8, "dout" }, // dig_out 0–7 ohne MUX
{ 4, 0, 0x48, 0, 4, "ain" }, // analog_in 0–3 via ADC
{ 4, 0, 0x60, 0, 4, "aout" }, // analog_out 0–3 via DAC
};
🛠 Initialisierungsfunktion:
void IOHardware_Configure(void)
{
for (size_t i = 0; i < sizeof(config_table) / sizeof(config_table[0]); i++)
{
IOHardwareConfig *cfg = &config_table[i];
if (strcmp(cfg->io_type, "din") == 0) {
for (int j = 0; j < cfg->io_count; j++) {
int index = cfg->io_start + j;
IOExpander_AddInput(cfg->i2c_bus, cfg->mux_channel, cfg->i2c_addr, j, index);
}
}
else if (strcmp(cfg->io_type, "dout") == 0) {
for (int j = 0; j < cfg->io_count; j++) {
int index = cfg->io_start + j;
IOExpander_AddOutput(cfg->i2c_bus, cfg->mux_channel, cfg->i2c_addr, j, index);
}
}
// analog (ain/aout) ähnlich...
}
}
✅ Vorteile:
- automatische globale IO-Zuordnung
- saubere Trennung von Hardware und Funktion
- flexibel erweiterbar (MUX, Adresse, Bus)
Tags:

Schreibe einen Kommentar