Hi David,
A few suggestions
Option 1
Why not add a value for 50 kHz, although we cannot enter 0.5.
Option 2
Or replace the 100 kHz by 50 kHz?
So instead of:
const _i2c_slowest = 127 -- (40 kHz @ 20 MHz Fosc)
Use:
const _i2c_slowest
= target_clock / 50_000 / 4 - 1 –- 50 kHz
Option 3
Another option would be to use a user defined constant, for example:
const I2C_USER_BUS_SPEED = 50_000
And then overrule everything by:
if defined(I2C_USER_BUS_SPEED) then
spadd = target_clock / I2C_USER BUS_SPEED / 4 - 1
else
if _i2c_bus_speed == 10 then sspadd = _i2c_1mhz
elsif _i2c_bus_speed == 4 then sspadd = _i2c_400khz
elsif _i2c_bus_speed == 1 then sspadd = _i2c_100khz
elsif _i2c_bus_speed == 0 then sspadd = _i2c_slowest
else sspadd = _i2c_100khz -- default
end if