Make I²C bus clock speed configurable and add notes about the speed

pull/20/head
Mikael Nousiainen 2022-06-16 18:53:54 +03:00
rodzic 0aa49f5a2c
commit b0602f8b18
4 zmienionych plików z 10 dodań i 5 usunięć

Wyświetl plik

@ -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

Wyświetl plik

@ -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;

Wyświetl plik

@ -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);

Wyświetl plik

@ -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();