# I2C on amd64



## Phishfry (Feb 25, 2022)

I want to use some 2x16 or 4x20 LCD displays on my servers starting with my firewall.
What is the best approach? There are USB interface LCD but I pefer i2c.
Mainly because I plan to use sysutils/lcdproc and linux libusb can be troublesome.
So I bought some i2c LCD to test with.
What is the best way to get i2c from an amd64 machine? There is no i2c visible.
I bought a usb dongle to test with as my X9SRL as it has an internal USB-A jack on the board.








						1PCS FT232H Multifunction High-Speed USB to JTAG UART/ FIFO SPI/ I2C  | eBay
					

Find many great new & used options and get the best deals for 1PCS FT232H Multifunction High-Speed USB to JTAG UART/ FIFO SPI/ I2C at the best online prices at eBay! Free shipping for many products!



					www.ebay.com
				



FT200XD is a USB to I2C interface with the following advanced features:

What do you use to drive an LCD on amd64?


----------



## obsigna (Feb 25, 2022)

FT200XD is an USB to I2C slave converter. I am still not 100 % sure, but from all what I understand about I2C, that means, you can connect this dongle as an I2C device to an existing I2C bus (which got already a master), and this won’t work with an AMD64 board, which got nothing I2C.
My best educated guess is that you need something like this one:








						CH341T module USB to I2C IIC UART USB to TTL single-chip serial port downloader  | eBay
					

Find many great new & used options and get the best deals for CH341T module USB to I2C IIC UART USB to TTL single-chip serial port downloader at the best online prices at eBay! Free shipping for many products!



					www.ebay.com
				




In the description about I2C is written in Chinenglish:
_"Ø  Only doMaster.20K,100K,400K,750KMore communication rate adjustable"_

This sounds like an I2C master. Yet, remains the question of the driver.


----------



## chrbr (Feb 25, 2022)

I would use RS232 and a small Atmel controller to convert the stuff to I2C. This might add an FTDI USB-RS232 dongle but matches my actual skills .


----------



## Phishfry (Feb 25, 2022)

I decided to get a few more. See what works.






						CP2112 Classic USB to UART Bridge - Silicon Labs
					

The CP2112 HID USB to SMBus/I2C Bridge provides a complete plug and play interface solution that includes royalty-free drivers. This USB 2.0 compliant device includes 8 digital I/O pins and is availble in a 4x4 mm QFN24 package. <a...




					www.silabs.com
				











						CP2112 Debug Board USB to SMBus I2C Communication Module for CCS811 Module   | eBay
					

Module size: 29.5mm 21.3mm, with two M3 mounting holes, one MicroUSB female port. USB suspend status via SUSPEND and /SUSPEND pins.



					www.ebay.com
				




This should round out the collection.








						CH341A Programmer USB to UART IIC SPI I2C Convertor Parallel Port  | eBay
					

Find many great new & used options and get the best deals for CH341A Programmer USB to UART IIC SPI I2C Convertor Parallel Port at the best online prices at eBay! Free shipping for many products!



					www.ebay.com


----------



## obsigna (Feb 26, 2022)

chrbr said:


> I would use RS232 and a small Atmel controller to convert the stuff to I2C. This might add an FTDI USB-RS232 dongle but matches my actual skills .


Here in Brazil, I found this one based on an ATtiny85:








						Arduino Digispark Attiny85 Usb I2c Spi Pwm Adc - R$ 52,9
					

O Digispark é uma placa de desenvolvimento baseada no microcontrolador Attiny85 semelhante à linha Arduino, só que mais barato, menor e um pouco menos potente. Com toda uma série de shields para estender sua funcionalidade e a capacidade de usar o familiar software Arduino IDE, o Digispark é uma...




					produto.mercadolivre.com.br
				




This seems to do the USB to I2C/SPI conversion via an Atmel contoller. Is it really easy to address an Atmel? I neve did this, but would be ready to learn.


----------



## obsigna (Feb 26, 2022)

Phishfry said:


> I decided to get a few more. See what works.
> 
> https://www.silabs.com/interface/usb-bridges/classic/device.cp2112
> https://www.ebay.com/itm/373738466687
> ...


For the mere USB to serial conversion, FreeBSD got a CH341 driver as a kernel module - uchcom(4). For sure this module won't enable I2C/SPI, however, I can imagine that this would be a good basis to get I2C working as well.

The tiny CH341T conversion boards (the one that you found and the one that I found as well) feature a 12.000 MHz quartz. This means that we can get USB1 full speed = 12 Mbit/s out of it. For addressing the 16x2/20x4 displays this is way more than enough. This would even serve for high speed I2C operation (3.4 MHz) as well. I am looking for a device which would be able to address ADCs and DACs, like these ones:



			https://www.ti.com/product/DAC8574
		



			https://www.ti.com/product/ADS122C04
		


From the specs, the USB to I2C converter based on the CH341T should work. I could need some help for the driver, though.
Anyway, I just ordered this one:








						Módulo Conversor Ch341 Usb Para I2c / Ttl Serial 5v 3.3v - R$ 53
					

DESCRIÇÃO DO PRODUTO:1 x Módulo Conversor CH341T USB para I2C / TTL serial 5V 3.3V;CARACTERISTICAS:Chip: CH341T;Compatibilidade com USB 2.0;Modo USB para TTL (UART) configurável através de Jumper - (Comunicação via TXD e RXD);Modo USB para I2C (IIC) configurável através de Jumper - (Comunicação...




					produto.mercadolivre.com.br


----------



## obsigna (Feb 26, 2022)

Phishfry said:


> ...
> ...
> What do you use to drive an LCD on amd64?


There is yet another almost unknown option, namely the parallel port I2C bit-banging interface lpbb(4)

Even modern x86 motherboards feature parallel port headers, only these are no more connected to the outside. For example, I got an ASRock B250M Pro4, and I can see the LPT1 pinout on board:






With FreeBSD 13.0-RELEASE-p7, this is still activated:
`dmesg`

```
...
ppc1: <Parallel port> port 0x378-0x37f,0x778-0x77f irq 5 drq 3 on acpi0
ppc1: SMC-like chipset (ECP/EPP/PS2/NIBBLE) in COMPATIBLE mode
ppc1: FIFO with 16/16/9 bytes threshold
ppbus0: <Parallel port bus> on ppc1
lpt0: <Printer> on ppbus0
lpt0: Interrupt-driven port
ppi0: <Parallel I/O> on ppbus0
...
```

I can load the lpbb kernel module, and this enables an I2C bus in FreeBSD:

`kldload lpbb.ko`
`kldstat`

```
...
14    1 0xffffffff8232f000     2228 lpbb.ko
15    1 0xffffffff82332000     326c iicbb.ko
16    1 0xffffffff82336000     433c iicbus.ko
```

We only would need to produce the quite simple adapter circuit which is lined out on said man page.


----------



## Phishfry (Feb 26, 2022)

That was kinda why I posted.
Hoping someone with SuperMicro server board is using an external interface.
The boards have a management system to talk to disk backplane.
I thought it was i2c. Shows as SES management in dmesg.

I have some hardware coming. I like USB approach as it is easily transferable.
I did see that tiny USB attiny version. Would have bought one but high shipping.

Had to revamp my order. I was worried about CH341 with no designator. Wanted CH341T.








						1PC CH341T 2-in-1 module USB to I2C IIC UART USB to TTL MCU  | eBay
					

Find many great new & used options and get the best deals for 1PC CH341T 2-in-1 module USB to I2C IIC UART USB to TTL MCU at the best online prices at eBay! Free shipping for many products!



					www.ebay.com
				




Also got a GPIO expander by not reading well and researching. Bad listing.








						9 Pin Motherboard Header to 2 Ports USB 2.0 Female Cable Adapter  | eBay
					

Find many great new & used options and get the best deals for 9 Pin Motherboard Header to 2 Ports USB 2.0 Female Cable Adapter at the best online prices at eBay! Free shipping for many products!



					www.ebay.com
				












						PCF8574 GPIO Extender - With Arduino and NodeMCU
					

PCF8574 GPIO Extender - With Arduino and NodeMCU: In my last tutorial, I talked about the TCA9548A MUX which can be used to add at the max of 64 I2C or I²C sensors to your Arduino/ESP8266/ESP32.  In this tutorial, I am going to talk about the PCF8574 8-bit GPIO Port Extender. It is one of the many …




					www.instructables.com


----------



## obsigna (Feb 26, 2022)

The SMBus, which is present on most motherboards, is actually a subset of I2C, here from dmesg of my ASRock:

```
...
ichsmb0: <Intel Kaby Lake SMBus controller> port 0xf000-0xf01f mem 0xdf24a000-0xdf24a0ff irq 16 at device 31.4 on pci0
smbus0: <System Management Bus> on ichsmb0
...
```
With that the only problem is, that I don't see any SMBus pinout on the board, where I could connect something. Perhaps pin 5 (SMCLK = SCL) and Pin 6 (SMDAT = SDA) of an unused PCIe slot could be used:








						PCI Express - Wikipedia
					






					en.wikipedia.org
				




There is yet another option, using the I2C interface of the video port, but it seems no to work in general:


			The 25¢ I2C Adapter «  Paint Your Dragon


----------



## chrbr (Feb 26, 2022)

Dear obsigna,


obsigna said:


> Is it really easy to address an Atmel? I neve did this, but would be ready to learn.


There are a few tools in the ports system. Please seek for AVR at freshports. In case of my experience I have used ATmega in the past. But I am not sure if I did the programming with Debian or FreeBSD. I have build the programmer based on a schematic diagram published within the AVRGCC project or so. The PC interface has been the LPT port. The programming has been done with devel/avrdude.


----------



## skunk (Feb 26, 2022)

Sadly the SMBUS is usually internal to the mobo, so it is a no-go.

Another option would be to use a (secondary) graphics card.
Some graphics cards have their I2C port handler in their freedesktop xf86-driver-... source. Most of the drivers use the int86 VESA BIOS interface, though, so check before getting a graphics card for this purpose. If it is a microcontroller, one could (ab)use an unused VGA port for I2C.
(You know, the VESA line, for EDID, DPMS etc, it is an I2C line)


----------



## obsigna (Feb 27, 2022)

skunk said:


> Sadly the SMBUS is usually internal to the mobo, so it is a no-go.


I am not that pessimistic about this option. FreeBSD comes with a smb(4) character device driver, which according to the man page:


> ... provides generic I/O to any smbus(4) instance. To control SMB devices, use /dev/smb? with the ioctls described below. Any of these ioctl commands takes a pointer to struct smbcmd as its argument. ...


We need to find pins where we can connect our I2C devices. I got an almost unused x86 machine with a free mini-PCIe slot. When I find some time (don't hold your breath), I will attach an I2C device which I know very very well (the ADS1115 - 16 bit ADC) to the pins 24 (VDD), 26 (GND), 30 (SCL), 32 (SDA) of it, and then I will see how far this goes.


----------



## Phishfry (Feb 27, 2022)

While researching items in /dev I stumbled into this:








						Exposing the System Management Bus
					

It's the weekend, it's raining, pubs 🍻 are closed, and COVID19 has us shuttered in; again! Time for some hardware hacking. The following article will explore exposing the System Management Bus (SMB/SMBus) on a common-as-muck PC motherboard, for the purpose of attaching assorted sensors for fun, pro




					www.linkedin.com


----------



## obsigna (Feb 28, 2022)

That looks very promising. However, I don't own this high precision soldering device, but fortunately, the PCIe connector gaps are not that tiny like that of the DIMM connectors. So, I need to go the PCIe path.

I found already out, that I needed to call `kldload smb.ko` in order to activate /dev/smb0. On FreeBSD, the SMBus is realized on top of the IIC bus, see smbus(4) and iicsmb(4).

Reading that article, I am quit optimistic now. And we learn as well that the rainy weather in the UK and the closed pubs because of COVID19 are good for something

That said, everybody take care, stay healthy and write useful articles!


----------



## Phishfry (Feb 28, 2022)

My SuperMicro X9SRL motherboard has i2c. The manual has this:


> The Power Supply I2C Connector, located at
> JPI2C1, monitors the status of the power sup-
> ply, fan and system temperature. See the table
> on the right for pin definitions.


It does not look like the standard pinout of SDA SCL CLK + -

This also looks relevant:


> System Management Bus (JIPMB)
> A System Management Bus header for the
> IPMI slot is located at IPMB. Connect the
> appropriate cable here to use the IPMB I2C
> connection on your system.


----------



## obsigna (Feb 28, 2022)

Are you talking about this one?



This would be easy: 1 = SCL, 2 = SDA, 4 = GND, 5 = VDD (3.3 V). Note, for your display, 3.3 V is not sufficient, it needs 5 V. So, you would connect only SCL and SDA of the display to pins 1 and 2 respectively, and take 5 V and GND directly from free red and black wires out of the PSU.


----------



## Phishfry (Feb 28, 2022)

Wow reading the manual. What a concept.
I believe these are the SES0 device I see in dmesg:


> T-SGPIO & SCU-SGPIO Headers
> Two T-SGPIO (Serial-Link General Purpose
> Input/Output) headers are supported on the
> motherboard. Additionally, one SCU-SGPIO
> ...



But right underneath this is the section on TPM chip/socket.
Are'nt those i2c as well? Maybe it was SPI...


----------



## obsigna (Feb 28, 2022)

Phishfry said:


> Wow reading the manual. What a concept.
> I believe these are the SES0 device I see in dmesg:
> 
> 
> ...


I don't believe this is I2C, it may be SPI.

I forgot to say, that JPI2C1 is not 100 % I2C but it is actually SMB. Most probably you need some glue code for addressing your I2C devices. Does FreeBSD on this SuperMicro board already come up with /dev/smbX device identifiers? In case not, what happens, if you issue `kldload smb.ko` on the command line?

Another hurdle is, that we cannot say now, whether this connector belongs to the regular SMBus of the system, which got already a bus master, or whether this is meant to be connected as a client to a 3rd party SMBus wich got its own bus master. In the second case this connector would be useless for using it with your display.


----------



## Phishfry (Feb 28, 2022)

smb.ko is being loaded automatically. I have smb0 and devices (could be RAM)

```
root@x9srl:/home/firewall # smbmsg -p
Probing for devices on /dev/smb0:
Device @0x10: rw
Device @0x5a: rw
Device @0x88: rw
Device @0x90: rw
Device @0xd2: rw
Device @0xdc: rw
```

I have hand loaded iic.ko with no device nodes showing there.


----------



## obsigna (Feb 28, 2022)

OK, now connect the display to JPI2C1 -- important, VDD must be 5 V. Then look whether it is enumerated by `smbmsg -p`.

Perhaps on /dev/smb1?


----------



## Phishfry (Feb 28, 2022)

I need to regroup and use another SuperMicro board for experimenting. The X9SRL is my firewall.
Thank You so much for the help.


----------



## Phishfry (Feb 28, 2022)

obsigna said:


> whether this connector belongs to the regular SMBus of the system, which got already a bus master, or whether this is meant to be connected as a client to a 3rd party SMBus wich got its own bus master. In the second case this connector would be useless for using it with your display.


Yes I was wondering about this too. It appears that the IPMI/BMC is the master and monitors the board via SMBus.
That was for an older SuperMicro board with external IPMI PCI module.
I don't know if true on my integrated BMC. From my reading of the BMC GUI I would say probably so.

I want to prototype this concept on another rig first. I have X10SRL which should be similar.
Currently covered on my bench by embedded boards.
Alot of SuperMicro server boards have these power supply i2C connectors.
Even X8 boards had them if i remember right. Tyan server boards have them too.


----------



## obsigna (Mar 1, 2022)

Last weekend, I ordered the open collector hex inverter chip 74LS05, which I would need to turn the internal parallel port into I2C by using the FreeBSD's bit banging driver - lpbb(4). Here in Brazil we have carneval and I will receive it only on Thursday. In advance, I just started to draw the scheme of the tiny adapter board using KiCAD, and I was looking up the pinout of the parallel port male connector on the main board. I found it here:


			Motherboard 25-pin parallel port header - HD44780 LCD display hookup - The GPSy EV Project
		


However, I found more on this page. Here the parallel port is used to directly connect the HD44780 display without the PCF8574 I2C/GPIO converter in the middle. So, if you are only looking for means to connect the display, this would be the straightest option.


			LCD Smartie - A free open-source LCD program!
		


Anyway, my aim is still to connect I2C devices, and I will explore the lpbb facility once the 74LS05 arrived.


----------



## obsigna (Mar 2, 2022)

I reworked the scheme in lpbb(4) and created a PCB layout using KiCAD. Bear with me, I am a chemist and not an electronics professional. I allow anybody to lough at me, as long as you give constructive advises on how to improve the design.

Presumably, tomorrow the 74LS05 chips will arrive and I will reproduce the design on a prototype board first. In case it works well, then I will make the KiCAD project available on GitHub. If anybody considers a mass production, I suggest to refactor this for using SMD parts.









The tiny board is meant to be plugged in vertically in to the parallel port's 25 pin header on the motherboard, for example this one:


----------



## SirDice (Mar 2, 2022)

Use a logic level converter to convert the 3.3V signals to 5V TTL and vise versa. You could drive a 5V TTL input with a 3.3V output (3.3V is above the logic '1' minimal voltage of TTL) but driving a 3.3V input with a 5V TTL signal is likely going to blow something up (unless the chip is 5V tolerant but I doubt that).

The TXS0108E is useful. You can buy these on breakout boards. They're not that expensive.



			https://www.ti.com/lit/ds/symlink/txs0108e.pdf
		




			https://www.amazon.nl/gp/product/B07NNRS8FS/ref=ppx_yo_dt_b_asin_title_o00_s00?ie=UTF8&psc=1


----------



## obsigna (Mar 2, 2022)

SirDice said:


> Use a logic level converter to convert the 3.3V signals to 5V TTL and vise versa. You could drive a 5V TTL input with a 3.3V output (3.3V is above the logic '1' minimal voltage of TTL) but driving a 3.3V input with a 5V TTL signal is likely going to blow something up (unless the chip is 5V tolerant but I doubt that).
> 
> The TXS0108E is useful. You can buy these on breakout boards. They're not that expensive.
> 
> ...


The I2C device which I want to use with this are 5 V capable, for example this one:


			https://www.ti.com/lit/ds/symlink/ads1115.pdf
		


I will start my experiments with this ADS1115, it works very well on a BeagleBone Black at a 3.3 V level, however, I had this working already behind an ADUM1251, which is an I2C isolator.


			https://www.analog.com/media/en/technical-documentation/data-sheets/ADUM1250_1251.pdf
		


With this in place, the BBB worked at 3.3 V and the other side at 5 V (actually ±2.5 V) with the ADS1115. This is a perfect way to make an uniploar (0 ... VDD) ADC working bipolar (-VDD/2 ... +VDD/2).


----------



## chrbr (Mar 2, 2022)

Regarding level shifters it is possible to build a bidirectional one by 2x transistors in common base configuration. As far as I remember you can find it by searching for "Nokia" and "Level shifter". I did not find a PDF on my PC but I have a print out somewhere which I can scan and send you if you are interested. Of course a dedicated IC is easier to use.

About the 74LS05 it seems to be a circuit which connects SDA and SCL to two different pins per signal. It will be a matter of the driver to combine them to I2C. Just a super minor, it might be safe to connect pin 13 with pin 14. Then the input of U1F is not floating.


----------



## obsigna (Mar 2, 2022)

chrbr said:


> Regarding level shifters it is possible to build a bidirectional one by 2x transistors in common base configuration. As far as I remember you can find it by searching for "Nokia" and "Level shifter". I did not find a PDF on my PC but I have a print out somewhere which I can scan and send you if you are interested. Of course a dedicated IC is easier to use.
> 
> About the 74LS05 it seems to be a circuit which connects SDA and SCL to two different pins per signal. It will be a matter of the driver to combine them to I2C. Just a super minor, it might be safe to connect pin 13 with pin 14. Then the input of U1F is not floating.


Have a look at lpbb(4). I tried to reproduce exactly the scheme which is said to work with the bit banging kernel module.

PS:
Pin 13 of JPP1 is connected to GND and hence to pin 7 of U1 (as it is in said man file).


----------



## chrbr (Mar 2, 2022)

obsigna said:


> Have a look at lpbb(4).


Wow, I have not expected a schematics in ASCII art. If that is supported it is perfect .
Regarding pin 13 I meant the input of the spare inverter section U1F. It is adjacent to pin14 which is its supply pin.


----------



## obsigna (Mar 2, 2022)

chrbr said:


> Wow, I have not expected a schematics in ASCII art. If that is supported it is perfect .
> ...



I hope, I will see this soon, and I will report the results here.



chrbr said:


> ...
> Regarding pin 13 I meant the input of the spare inverter section U1F. It is adjacent to pin14 which is its supply pin.



Aah, OK, I will do this. I left it as is, because it was not even present in Phillip's original ASCII art scheme.


----------



## obsigna (Mar 9, 2022)

I finished the parallel port to I2C bit banging circuit on a tiny prototype board - it is not as nice as a real pcb would have been, like the 3D image in my other post, however, I soldered and checked everything very carefully, and I am sure that this part should work. Into the I2C slot, I plugged in a breakout board featuring a TI-I2C-ADC (ADS1115) -- see the pictures below.

Unfortunately, everything was to no avail, since the lpbb(4) kernel module seems to have been broken for at least 14 years.
https://lists.freebsd.org/pipermail/freebsd-stable/2008-March/041468.html

Well, so it is, this project goes back into the drawer, until I find some time to look at the lpbb module -- don't hold your breath.


----------



## Phishfry (Mar 12, 2022)

Here is the message from the FT232H from my first post that arrived in the mail.

```
Mar 12 06:04:51 E6420 kernel: ugen1.6: <FTDI FT200X USB I2C> at usbus1
Mar 12 06:04:51 E6420 kernel: uftdi0 on uhub3
Mar 12 06:04:51 E6420 kernel: uftdi0: <FT200X USB I2C> on usbus1
```

Looking here I need to switch it from RS232 mode to Open Drain mode with thier Windows utility.








						GitHub - kkrizka/adafruitft232h_i2c_adapter: An I2C adapter for the FT232H breakout board by Adafruit.
					

An I2C adapter for the FT232H breakout board by Adafruit. - GitHub - kkrizka/adafruitft232h_i2c_adapter: An I2C adapter for the FT232H breakout board by Adafruit.




					github.com


----------



## rowan194 (Apr 22, 2022)

Phishfry said:


> Here is the message from the FT232H from my first post that arrived in the mail.
> 
> ```
> Mar 12 06:04:51 E6420 kernel: ugen1.6: <FTDI FT200X USB I2C> at usbus1
> ...


I purchased a similar module which arrived today. It's detected by FreeBSD, but there's possibly one big deal breaker which I missed earlier:

From https://electronics.stackexchange.com/questions/420673/usb-to-i2c-for-a-beginner : "T200XD is a I2C slave chip, so it cannot be used as a master to talk to another I2C slave [...]"

I was expecting it to be a master. The FreeBSD i2c subsystem also seems to expect the hardware acts as a master. Not sure how useful a computer USB<-> I2C slave setup would be, perhaps to emulate a sensor?

I also purchased a CH341 board, which has both serial and I2C pins, but it seems to be supported by FreeBSD only as a serial port (uchcom device); when switched to I2C mode via the board header, it shows up as a ugen device.


----------



## Andriy (Apr 22, 2022)

I see that CP2112 was mentioned earlier. FreeBSD has a driver for it that supports both the GPIO and I2C functions.


----------



## Phishfry (Apr 22, 2022)

Didn't buy that one unfortunately. Revamped my list.
The price increased now on those alot too. More than inflation...

I probably have ADD as I go in wild swings from project to project and never finishing anything.
If I machined like that I wouldn't get paid.


----------



## Andriy (Apr 23, 2022)

Phishfry said:


> The price increased now on those alot too. More than inflation...


I've just checked aliexpress and, oh wow, the price is at least *5x* of what I used to pay for them.


----------

