diff --git a/src/config.h b/src/config.h index e43e86f..5a73ac6 100644 --- a/src/config.h +++ b/src/config.h @@ -24,6 +24,11 @@ // Allow powering off the sonde by pressing the button for over a second (when the sonde is not transmitting) #define ALLOW_POWER_OFF false +// Define the I²C bus clock speed in Hz. +// The default of 100000 (= 100 kHz) should be used with the Si5351 clock generator to allow fast frequency changes. +// Note that some BMP280 sensors may require decreasing the clock speed to 10000 (= 10 kHz) +#define I2C_BUS_CLOCK_SPEED 100000 + // Enable use of an externally connected I²C BMP280/BME280 atmospheric sensor // NOTE: Only BME280 sensors will report humidity. For BMP280 humidity readings will be zero. #define SENSOR_BMP280_ENABLE false diff --git a/src/hal/i2c.c b/src/hal/i2c.c index 9bfa0fb..63d985c 100644 --- a/src/hal/i2c.c +++ b/src/hal/i2c.c @@ -17,7 +17,7 @@ i2c_port DEFAULT_I2C_PORT = { .i2c = I2C_PORT, }; -void i2c_init() +void i2c_init(uint32_t clock_speed) { GPIO_InitTypeDef gpio_init; @@ -49,7 +49,7 @@ void i2c_init() I2C_InitTypeDef i2c_init; I2C_StructInit(&i2c_init); - i2c_init.I2C_ClockSpeed = 100000; + i2c_init.I2C_ClockSpeed = clock_speed; i2c_init.I2C_Mode = I2C_Mode_I2C; i2c_init.I2C_DutyCycle = I2C_DutyCycle_2; i2c_init.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit; diff --git a/src/hal/i2c.h b/src/hal/i2c.h index cb88dd3..32140e1 100644 --- a/src/hal/i2c.h +++ b/src/hal/i2c.h @@ -20,7 +20,7 @@ extern i2c_port DEFAULT_I2C_PORT; extern "C" { #endif -void i2c_init(); +void i2c_init(uint32_t clock_speed); void i2c_uninit(); int i2c_read_bytes(struct _i2c_port *port, uint8_t address, uint8_t reg, uint8_t size, uint8_t *data); int i2c_read_byte(struct _i2c_port *port, uint8_t address, uint8_t reg, uint8_t *data); diff --git a/src/main.c b/src/main.c index 5f5023f..9469e2d 100644 --- a/src/main.c +++ b/src/main.c @@ -84,8 +84,8 @@ int main(void) log_info("External USART init\n"); usart_ext_init(EXTERNAL_SERIAL_PORT_BAUD_RATE); } else { - log_info("I2C init\n"); - i2c_init(); + log_info("I2C init: clock speed %d kHz\n", I2C_BUS_CLOCK_SPEED / 1000); + i2c_init(I2C_BUS_CLOCK_SPEED); } log_info("SPI init\n"); spi_init();