Merge pull request #2588 from dhalbert/nrf-fix-i2c-speed

nrf: fix i2c frequency setting
This commit is contained in:
Limor "Ladyada" Fried 2020-02-05 12:45:15 -05:00 committed by GitHub
commit 06b43069a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -137,11 +137,17 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self, const mcu_pin_obj_t *
nrfx_twim_config_t config = NRFX_TWIM_DEFAULT_CONFIG(scl->number, sda->number);
// change freq. only if it's less than the default 400K
if (frequency < 100000) {
config.frequency = NRF_TWIM_FREQ_100K;
} else if (frequency < 250000) {
#if defined(TWIM_FREQUENCY_FREQUENCY_K1000)
if (frequency >= 1000000) {
config.frequency = NRF_TWIM_FREQ_1000K;
} else
#endif
if (frequency >= 400000) {
config.frequency = NRF_TWIM_FREQ_400K;
} else if (frequency >= 250000) {
config.frequency = NRF_TWIM_FREQ_250K;
} else {
config.frequency = NRF_TWIM_FREQ_100K;
}
self->scl_pin_number = scl->number;