Merge pull request #5190 from jepler/issue4883

samd: diagnose out of range I2C frequency
This commit is contained in:
microDev 2021-08-21 08:00:50 +05:30 committed by GitHub
commit 208ec71372
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -119,6 +119,13 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self,
// clkrate is always 0. baud_rate is in kHz. // clkrate is always 0. baud_rate is in kHz.
// Frequency must be set before the I2C device is enabled. // Frequency must be set before the I2C device is enabled.
// The maximum frequency divisor gives a clock rate of around 48MHz/2/255
// but set_baudrate does not diagnose this problem. (This is not the
// exact cutoff, but no frequency well under 100kHz is available)
if (frequency < 95000) {
mp_raise_ValueError(translate("Unsupported baudrate"));
}
if (i2c_m_sync_set_baudrate(&self->i2c_desc, 0, frequency / 1000) != ERR_NONE) { if (i2c_m_sync_set_baudrate(&self->i2c_desc, 0, frequency / 1000) != ERR_NONE) {
reset_pin_number(sda->number); reset_pin_number(sda->number);
reset_pin_number(scl->number); reset_pin_number(scl->number);