Compare commits

...

2 Commits

Author SHA1 Message Date
693446dfe0 Fonctionnel 2026-01-17 18:18:39 +01:00
80593efd46 I2C Slave configuré pour la carte Detection2023 2026-01-17 14:38:03 +01:00

20
main.c
View File

@ -11,14 +11,16 @@
#include <stdio.h>
#include <string.h>
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 = PICO_DEFAULT_I2C_SDA_PIN; // 4
static const uint I2C_SLAVE_SCL_PIN = PICO_DEFAULT_I2C_SCL_PIN; // 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;
@ -71,7 +74,7 @@ static void setup_slave() {
gpio_pull_up(I2C_SLAVE_SCL_PIN);
i2c_init(i2c0, I2C_BAUDRATE);
// configure I2C0 for slave mode
// configure I2C1 for slave mode
i2c_slave_init(i2c0, I2C_SLAVE_ADDRESS, &i2c_slave_handler);
}
@ -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
}