diff --git a/main.c b/main.c index 6667c99..b0f99f9 100644 --- a/main.c +++ b/main.c @@ -11,14 +11,16 @@ #include #include -static const uint I2C_SLAVE_ADDRESS = 0x17; +static const uint I2C_SLAVE_ADDRESS = 0x09; static const uint I2C_BAUDRATE = 100000; // 100 kHz +uint reception; + #ifdef i2c_default // For this example, we run both the master and slave from the same board. // You'll need to wire pin GP4 to GP6 (SDA), and pin GP5 to GP7 (SCL). -static const uint I2C_SLAVE_SDA_PIN = 19; // 4 -static const uint I2C_SLAVE_SCL_PIN = 18; // 5 +static const uint I2C_SLAVE_SDA_PIN = 17; // 17 +static const uint I2C_SLAVE_SCL_PIN = 16; // 16 static const uint I2C_MASTER_SDA_PIN = 6; static const uint I2C_MASTER_SCL_PIN = 7; @@ -55,6 +57,7 @@ static void i2c_slave_handler(i2c_inst_t *i2c, i2c_slave_event_t event) { break; case I2C_SLAVE_FINISH: // master has signalled Stop / Restart context.mem_address_written = false; + reception++; break; default: break; @@ -70,9 +73,9 @@ static void setup_slave() { gpio_set_function(I2C_SLAVE_SCL_PIN, GPIO_FUNC_I2C); gpio_pull_up(I2C_SLAVE_SCL_PIN); - i2c_init(i2c1, I2C_BAUDRATE); + i2c_init(i2c0, I2C_BAUDRATE); // configure I2C1 for slave mode - i2c_slave_init(i2c1, I2C_SLAVE_ADDRESS, &i2c_slave_handler); + i2c_slave_init(i2c0, I2C_SLAVE_ADDRESS, &i2c_slave_handler); } #endif @@ -90,8 +93,13 @@ int main() { setup_slave(); //run_master(); while(1){ - puts("\nI2C slave example\n"); - sleep_ms(1000); + if(reception != 0){ + puts("reception != 0\n"); + reception = 0; + printf(">a:%d\n", context.mem[0]); + } + puts("I2C slave example\n"); + sleep_ms(10); } #endif } \ No newline at end of file