NetBSD-Users archive

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

Re: I cannot make i2c work in raspberry pi Zero W



Ramiro Aceves <ea1abz%gmail.com@localhost> writes:

> Hello,
>
> I have connected a BMP280 pressure sensor to my piZeroW just to learn a little of i2c programming on NetBSD. Before doing real programming I issued a i2scan command to ensure the system works, but a lot of inexistent devices are detected (even if nothing is connected to the pi)
>
> netbsd-raspaZeroW# i2cscan /dev/iic0
> /dev/iic0: found device at 0x09
> /dev/iic0: found device at 0x0a
> /dev/iic0: found device at 0x0b

[snip]

Ya, in 10.x (and probably -current) i2cscan often does this.. there is a
PR open about it and a proposed fix / change.  This didn't happen in
9.x.  It is quite annoying...  I don't know if the fix that is proposed
is proper...

BTW - make sure that iic0 is the actual bus with devices on it... the
RPI may report iic0, iic1 and iic2...  for my RPI0, RPI2 and RPI3
boards, iic2 is the one that you can usually put devices on.

> I also configured config.txt file (added last line):
>
> netbsd-raspaZeroW# cat /boot/config.txt
> #
> upstream_kernel=1
> os_prefix=dtb/
> cmdline=../cmdline.txt
> # UART settings, see https://www.raspberrypi.com/documentation/computers/configuration.html#configuring-uarts
> enable_uart=1
> force_turbo=0
> # Default kernel for BCM2836 and later
> kernel=/kernel7.img
> # Override kernel for BCM2835 based boards
> [pi0]
> kernel=/kernel.img
> [pi0w]
> kernel=/kernel.img
> [pi1]
> kernel=/kernel.img
> [all]
> #
> dtparam=i2c_arm=on
> netbsd-raspaZeroW#

All of the above is probably fine, assuming that the i2c bus is found.
I am not familiar with using that particular dtparam line... and don't
have a RPI0W.  I have never needed anything to enable i2c on the RPI.
You will have to use an overlay to enable SPI..  Be aware that the Linux
overlays (nearly every one of the found on the Internet) probably won't
work with NetBSD.

> But the result is the same. Am I missing something?

Ya...  just load the driver ... i.e. put bmx280thp and bmx280thpi2c in
/etc/modules.conf and do modules=YES in /etc/rc.conf and reboot (you can
probably get away with bmx280thpi2c, as the main driver should be a
dependent module and if you have auto loading enabled, it should
load... but you can load it yourself too).  Or... compile up a custom
kernel with the additional config lines you need.. See bmx280thp(4) for
examples of that.

In the first case, simply loading the drivers, the driver will probe the
i2c bus for something at i2c address 0x76 and 0x77 and see if it is a
BMP280 or BME280.  If so, the driver will attach.  If your chip is at
another address, you will have to use the second way and compile a
kernel telling it what address the chip is at.  It would be unusual for
your chip to NOT be at 0x76 or 0x77.

You may also be able to speak to the chip using SPI if the breakout
board you have brought out the SPI pins.  To do that, wire your board up
as a SPI device and enable SPI for your RPI device.  This may require an
device tree overlay.  Then compile a kernel with the needed config
lines..  see bmx280thp(4) for examples of this.  There are no modules
for SPI.

The BM[PE]280 should work just fine on gpioiic (the bitbanger i2c bus
using gpio pins) too...  just make sure you add pull up resisters to the
SDA and SCL lines.  See gpioiic(4) and gpioctl(8) for examples of how to
attach gpioiic to gpio pins.

> Thanks so much.
> Ramiro.


I wrote the BM[PE]280 driver and use one all of the time on a RPI0 with
NetBSD 10.x (and 9.x before that).



-- 
Brad Spencer - brad%anduin.eldar.org@localhost - KC8VKS - http://anduin.eldar.org


Home | Main Index | Thread Index | Old Index