Port-arm archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

How to I2C in RPi3B+ (also gpioiic) ?



Hi,

I am trying to get I2C to work in RPi3B+ (possibly later in BBB) in NetBSD 10.0 Release.

I am doing experiments, but it does not seem to work or i did not understand
how to make it.

To get started I am connecting an external clock DS3231, a device I used in the past.

To have a comparison, this is what i do in Linux and wish to be able to do in NetBSD

--------------------------------------------------------
--------- Linux ----------------------------------------
--------------------------------------------------------

. wire the device
|--------|-- VCC ------- pin-1  : 3.3V    |--------|
| WIDGET |-- GND ------- pin-6  : GND     |  RPi   |
|  I2C   |-- SDA ------- pin-3 :          |  3B+   |
|--------|-- SCL ------- pin-5 :          |--------|


. enable i2c
$> sudo raspi-config
=> enable i2c
=> reboot

. Check if there are available any I2C channels :
$> i2cdetect -l
i2c-1   i2c             bcm2835 (i2c@7e804000) I2C adapter
i2c-2   i2c             bcm2835 (i2c@7e805000) I2C adapter

=> ok, 2 channels found

. Check to see if my device is recognized, i know it should be at address 0x68
$> i2cdetect -y -r 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:                         -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- 57 -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- 68 -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

=> ok device recognized

. Try to read the number of seconds from the external clock (read register 0x00)
$> i2cget -y 1 0x68 0x00
0x32
$> p@pulce6:~$ i2cget -y 1 0x68 0x00
0x34

=> ok seems to work

--------------------------------------------------------------
--------------------------------------------------------------

Now i try to replicate the same in NetBSD 10.0 in 2 ways

===============================================================
=== NetBSD 10.0, method 1, using builtin i2c (via DTS, i guess)
===============================================================


. wiring is now the same as in Linux

. check if i2c is there in dmesg
$> doas dmesg | grep -i iic
[     1.000004] bsciic0 at simplebus1: Broadcom Serial Controller
[     1.000004] bsciic0: interrupting on icu irq 53
[     1.000004] iic0 at bsciic0: I2C bus
[     1.000004] bsciic1 at simplebus1: Broadcom Serial Controller
[     1.000004] bsciic1: interrupting on icu irq 53
.... the same for iic1, iic2

. try to see if i can see my device at address 0x68

$> doas i2cscan /dev/iic0
....
/dev/iic0: found device at 0x74
/dev/iic0: found device at 0x75
/dev/iic0: found device at 0x76
/dev/iic0: found device at 0x77
/dev/iic0: 103 devices found

=> failed, it found devices everywhere
=> same result using parameter "-r"
=> same result on /dev/iic1 and /dev/iic2


================================================
=== NetBSD 10.0, method 2, i try to use gpioiic
=================================================

This method is more general, does not depend on board hardware
and if it worked it would work also in BeagleBone, so it is actually
my first choice, for ease of portability.


. wiring
|--------|-- VCC ------- pin-1  : 3.3V    |--------|
| WIDGET |-- GND ------- pin-6  : GND     |  RPi   |
|  I2C   |-- SDA ------- pin-11 : GPIO-17 |  3B+   |
|--------|-- SCL ------- pin-13 : GPIO-27 |--------|


---- /etc/rc.conf -------
gpio=YES
modules=YES
-------------------------

----- /etc/modules.conf -----
gpioiic
-----------------------------

---- /etc/gpio.conf -----
# --- i pin sono SDA (GPIO-17) e SCL (GPIO-27) -----
# offset: 17
# mask  : 0x401 -- decimale --- 1025
# flag  : 0x0   --  prima SDA poi SCL
gpio0 attach gpioiic 17 0x401 0x0
-------------------------


. $> doas dmesg
...
[    14.646954] gpioiic0 at gpio0: SDA[17] push-pull tri-state pull-up, SCL[27] push-pull
[    14.646954] iic3 at gpioiic0: I2C bus
[    14.696957] seeprom0 at iic3 addr 0x57: AT24Cxx or compatible EEPROM
[    14.707062] seeprom0: autoconfiguration error: invalid size specified; assuming 2KB (16Kb)
[    14.786967] dsrtc0 at iic3 addr 0x68: DS1307 Real-time Clock/NVRAM

=> good, the device at 0x68 was fond
=> it seems it reconized a clock device DS1307
=> there should be the dsrtc0 device, but i can't see where it is, not in /dev

. Let's try to scan iic3
$> doas i2cscan /dev/iic3
/dev/iic3: found device at 0x30
/dev/iic3: found device at 0x31
/dev/iic3: found device at 0x32
...
/dev/iic3: found device at 0x5c
/dev/iic3: found device at 0x5d
/dev/iic3: found device at 0x5e
/dev/iic3: found device at 0x5f
/dev/iic3: found device at 0x68
/dev/iic3: 24 devices found

=> umm, strange, 0x68 is ok, the other values are not

=======================================


Questions.

1. Is anybody able to get some form of I2C to work ?

2. Does it exist a command similar to i2cget in NetBSD to query
   directly a device via shell ? Otherwise, is there a code
   snipped around I can start from to get the same thing in C ?

3. using gpioiic the widget was recognized and it seems
   the device dsrtc0 was created (I guess a driver was found) but
.. Where is it ? I don't see it in /dev/
.. How do I use that device dsrtc0 ?



Extra Notes.

. AFAI-remember there were similar problems in FreeBSD I2C some while ago.
  and it was solved recently, still I have not tested.

. the clock is just the first device i had at hand, i wish to connect
  other devices. for example these, I can test with those if you know
  them better of have them at hand.
  . DHT20 , temp./humi. sensor --- never used
  . SSD1306, LCD   --- tested working in Linux
  . ADS1115, ADC   ---- never used

. My knowledge of kernel code is almost null and I am not an EE
  so unfortunately I can't fix it myself in reasonable time.



bye

Nicola Mingotti






















Home | Main Index | Thread Index | Old Index