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 Option 3) would be the most flexible. Kind regards, Rob ________________________________ Van: [email protected] <[email protected]> namens David VB <[email protected]> Verzonden: donderdag 4 april 2024 15:30 Aan: jallib <[email protected]> Onderwerp: [jallib] [Request] I2c_hardware.jal : Option for user-selected bus speed Hi, I was struggling with an I2C LCD display until I found out on the manufacturer website that, due to a design flaw, the I²C bus speed should be 50 kHz (for the record: https://support.newhavendisplay.com/hc/en-us/community/posts/9600301114775-NHD-0220D3Z-NSW-BBW-V3-using-I2C-dropping-characters ) My request here is to allow the user to define the sspadd value directly in his application by modifying the following code in i2c_hardware.jal -- set correct speed 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 so that the user may override the default 100 kHz value: by defining _i2c_bus_speed = 0xFF and initialize sspadd with the needed value in his application if _i2c_bus_speed != 0xFF then -- set correct speed 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 end if What do you think ? Kind regards, David -- You received this message because you are subscribed to the Google Groups "jallib" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]<mailto:[email protected]>. To view this discussion on the web visit https://groups.google.com/d/msgid/jallib/28c93aa1-8b14-4004-aa96-a4692f808654n%40googlegroups.com<https://groups.google.com/d/msgid/jallib/28c93aa1-8b14-4004-aa96-a4692f808654n%40googlegroups.com?utm_medium=email&utm_source=footer>. -- You received this message because you are subscribed to the Google Groups "jallib" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/jallib/GVXP195MB1637ABCF1E78FC9E3837C64EE63C2%40GVXP195MB1637.EURP195.PROD.OUTLOOK.COM.
