Compare commits

..

No commits in common. "Ulysse2026" and "master" have entirely different histories.

20
main.c
View File

@ -11,16 +11,14 @@
#include <stdio.h>
#include <string.h>
static const uint I2C_SLAVE_ADDRESS = 0x09;
static const uint I2C_SLAVE_ADDRESS = 0x17;
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 = 17; // 17
static const uint I2C_SLAVE_SCL_PIN = 16; // 16
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_MASTER_SDA_PIN = 6;
static const uint I2C_MASTER_SCL_PIN = 7;
@ -57,7 +55,6 @@ 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;
@ -74,7 +71,7 @@ static void setup_slave() {
gpio_pull_up(I2C_SLAVE_SCL_PIN);
i2c_init(i2c0, I2C_BAUDRATE);
// configure I2C1 for slave mode
// configure I2C0 for slave mode
i2c_slave_init(i2c0, I2C_SLAVE_ADDRESS, &i2c_slave_handler);
}
@ -93,13 +90,8 @@ int main() {
setup_slave();
//run_master();
while(1){
if(reception != 0){
puts("reception != 0\n");
reception = 0;
printf(">a:%d\n", context.mem[0]);
}
puts("I2C slave example\n");
sleep_ms(10);
puts("\nI2C slave example\n");
sleep_ms(1000);
}
#endif
}