Option 3 is definitely to best one ! Thanks Rob ! Le jeudi 4 avril 2024 à 20:44:53 UTC+2, Rob CJ a écrit :
> Hi David, > > I added option 3) to the library. Not yet tested and not yet uploaded but > can you give it a try. > > So define: > const I2C_USER_BUS_SPEED = 50_000 > > And give it a try. This version also has the user defined i2c_pins that > you can use, solving 2 issues at the same time. > > Kind regards, > > Rob > > ------------------------------ > *Van:* jal...@googlegroups.com <jal...@googlegroups.com> namens Rob CJ < > rob...@hotmail.com> > *Verzonden:* donderdag 4 april 2024 19:33 > *Aan:* jal...@googlegroups.com <jal...@googlegroups.com> > *Onderwerp:* Re: [jallib] [Request] I2c_hardware.jal : Option for > user-selected bus speed > > 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:* jal...@googlegroups.com <jal...@googlegroups.com> namens David VB < > pinhe...@gmail.com> > *Verzonden:* donderdag 4 april 2024 15:30 > *Aan:* jallib <jal...@googlegroups.com> > *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 jallib+un...@googlegroups.com. > 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 jallib+un...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/jallib/GVXP195MB1637ABCF1E78FC9E3837C64EE63C2%40GVXP195MB1637.EURP195.PROD.OUTLOOK.COM > > <https://groups.google.com/d/msgid/jallib/GVXP195MB1637ABCF1E78FC9E3837C64EE63C2%40GVXP195MB1637.EURP195.PROD.OUTLOOK.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 jallib+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/jallib/0f7360da-ce5d-4025-8d44-e04a106e85f3n%40googlegroups.com.