User avatar
Frank Buss
Posts: 92
Joined: Fri Jan 06, 2012 4:39 pm
Contact: Website

Re: kernel patch for Dallas 1-wire interface

Tue Aug 14, 2012 2:35 pm

I've applied the patch to the Raspbian kernel, this is the new repository:

https://github.com/FrankBuss/linux/tree ... s-raspbian

To compile it yourself, you need to setup a toolchain with hard floating point support, as used for the Raspbian image (I tried it first without, but the kernel module loader crashed for some modules). See http://www.raspbian.org/RaspbianDocumentation and "Distcc Cross compiling for Raspbian" (you don't need to install distcc, but it describes how to use crosstoo-ng to create a cross compiler as well). Then check http://elinux.org/RPi_Kernel_Compilation if you want to know how to use this cross compiler to compile a new kernel.

The Raspbian image used the kernel from https://github.com/raspberrypi/linux, but looks like the defconfig was not the one which was used for the 2012-07-15-wheezy-raspbian.img image. So I've extracted the config from the original Raspbian image from "/proc/config.gz" and added my configurations to it and finally created a new defconfig with "make ARCH=arm savedefconfig" and updated "arch/arm/configs/bcmrpi_defconfig" with it.

If you don't want to compile your own kernel (the howtos are not very accurate from the Raspbian pastebin instruction, e.g. you need to convert the linefeeds from the downloaded config file, otherwise it won't compile), you can install my pre-compiled one. I've created a new script to update a Raspbian installation:

- first install the 2012-07-15-wheezy-raspbian.img (Raspbian “wheezy” from http://www.raspberrypi.org/downloads)
- customize your installation with Raspi-config, which is started at first boot, and finally execute the "update" menu item
- reboot (I've rebooted twice: first for expand_rootfs, then again, just in case :-)
- now you can update the kernel: login as root (or prefix the commands with "sudo") and download and execute the update script:

Code: Select all

rm -f raspbian-w1-update ; wget http://www.frank-buss.de/raspberrypi/raspbian-w1-update
bash raspbian-w1-update
This updates just the linux kernel image and the modules, because the firmware is already the current version.

Testing:

1-Wire:

Code: Select all

modprobe w1-gpio
modprobe w1-therm
cat /sys/bus/w1/devices/22-0000001d84f2/w1_slave
Should output something like this:

Code: Select all

b8 01 4b 46 7f ff 08 10 8a : crc=8a YES
b8 01 4b 46 7f ff 08 10 8a t=27500
(for 27.5°C)

I2C:

Code: Select all

modprobe i2c-bcm2708
modprobe i2c-dev
apt-get install i2c-tools
i2cdetect -y 0
With an attached PCA9555 at address 0x20 you should see something like this:

Code: Select all

     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: 20 -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
SPI:

For SPI I've enabled the SPI dev, which was not enabled in the Raspbian image. With my kernel you can test it like this:

Code: Select all

modprobe spi-bcm2708
modprobe spidev
echo -n 42 > /dev/spidev0.0
This should show a signal like this on your scope (click on the image for full size) :
Image
As you can see, the default transfer rate is 500 kHz, but this can be changed with a kernel boot commandline parameter.

The Video 4 Linux, the new SPI and I2C driver and lots of other drivers, like the Prism2.5/3 USB driver or the RTL8192CU driver, were already enabled in the new image.

All differences between the original Raspbian image is the 1-wire patch and these configuration variables:

Code: Select all

CONFIG_W1=m
CONFIG_W1_MASTER_GPIO=m
CONFIG_W1_SLAVE_THERM=m
CONFIG_W1_SLAVE_SMEM=m
CONFIG_W1_SLAVE_DS2408=m
CONFIG_W1_SLAVE_DS2423=m
CONFIG_W1_SLAVE_DS2431=m
CONFIG_W1_SLAVE_DS2433=m
CONFIG_W1_SLAVE_DS2760=m
CONFIG_W1_SLAVE_DS2780=m
CONFIG_W1_SLAVE_BQ27000=m
CONFIG_RTC_CLASS=y
CONFIG_RTC_DRV_DS1307=m
CONFIG_SPI_SPIDEV=m
I hope this will fix some other problems reported in this thread. If not, please post again or report new bugs and I'll try to fix it. Messages like "works like a charm" are welcome, too :-)

User avatar
Frank Buss
Posts: 92
Joined: Fri Jan 06, 2012 4:39 pm
Contact: Website

Re: kernel patch for Dallas 1-wire interface

Tue Aug 14, 2012 3:10 pm

Bah, can't edit posts. For the 1-wire test: "cat /sys/bus/w1/devices/22-0000001d84f2/w1_slave" depends on your connected 1-wire chip address and the address "22-0000001d84f2" is different for your chip (it is unique). Try "ls /sys/bus/w1/devices/" first.

davidmam
Posts: 101
Joined: Tue Dec 06, 2011 4:13 pm

Re: kernel patch for Dallas 1-wire interface

Tue Aug 14, 2012 3:46 pm

Many thanks for that. I was hoping you would provide a pre-compiled kernel as my cross-compiling options are limited.

Looking forward to trying it out tonight :) (and seeing if I have fried my UART GPIO pins, and if I can get the I2C ADC to work.)

rafal.deska
Posts: 3
Joined: Thu Jul 26, 2012 4:09 pm

Re: kernel patch for Dallas 1-wire interface

Wed Aug 15, 2012 1:14 am

Thanks for your job. Unfortunately the latest kernel doesn't work with 18B20 chip (previous version runs perfectly). There are no 1-wire devices in /sys/bus/w1/devices/w1 bus master directory:
driver uevent w1_master_max_slave_count w1_master_pullup w1_master_slave_count
power w1_master_add w1_master_name w1_master_remove w1_master_slaves
subsystem w1_master_attempts w1_master_pointer w1_master_search w1_master_timeout
lsmod shows loaded modules:
[email protected]:/sys/bus/w1# lsmod
Module Size Used by
w1_therm 2977 0
w1_gpio 1563 0
wire 26105 2 w1_gpio,w1_therm
cn 5133 1 wire
I can't find any extended information in /var/log - dmesg shows only:
[ 105.658513] Driver for 1-wire Dallas network protocol.
Regards
Rafal

User avatar
Frank Buss
Posts: 92
Joined: Fri Jan 06, 2012 4:39 pm
Contact: Website

Re: kernel patch for Dallas 1-wire interface

Wed Aug 15, 2012 4:18 am

rafal.deska wrote:Thanks for your job. Unfortunately the latest kernel doesn't work with 18B20 chip (previous version runs perfectly). There are no 1-wire devices in /sys/bus/w1/devices/w1 bus master directory:
Yes, this is tricky. I don't know, if I did something wrong with the kernel configuration, or if the kernel changed this (which would be bad, because user mode program would break, if they don't do a switch-case based on the kernel version), but the path for the device with the previous version (kernel 3.2.18, based on bootc's kernel) was "/sys/bus/w1/devices/w1_bus_master1/22-0000001d84f2/w1_slave" and now (with kernel 3.1.9, based on the Raspbian kernel distribution) the path is "/sys/bus/w1/devices/22-0000001d84f2/w1_slave". And the 3.2.18 kernel uses "_" to separate the names in "w1 bus master", 3.1.9 uses spaces. Sorry, I didn't mentioned this change explicitly, just in the sample for the w1 test in my posting.

maui
Posts: 25
Joined: Sun Jul 08, 2012 10:10 am

Re: kernel patch for Dallas 1-wire interface

Wed Aug 15, 2012 8:33 am

Hi Frank,

I was waiting for the raspbian patch :)

After doing

Code: Select all

sudo bash raspbian-w1-update
my pi pachtes the kernel fine, then reboots and it stucks at the rainbow image ;)

But I saved my kernel before... so no big deal ;)
I tried 3 times ... :(

It isn't a "fresh" system. I installed XBMC, php, apache, gpio libs,..., may that be the cause?

What can I do now? do I need do cross compile :( ?

rafal.deska
Posts: 3
Joined: Thu Jul 26, 2012 4:09 pm

Re: kernel patch for Dallas 1-wire interface

Wed Aug 15, 2012 8:42 am

Thank you for reply. I resolved the problem - this was a hardware conflict with my bluetooth dongle. After unplugging it I can read back data at /sys/bus/w1/. Today I'll try to start to compile my own kernel.
Regards
Rafal

texy
Forum Moderator
Forum Moderator
Posts: 5160
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: kernel patch for Dallas 1-wire interface

Wed Aug 15, 2012 11:29 am

Frank Buss wrote:
rafal.deska wrote:Thanks for your job. Unfortunately the latest kernel doesn't work with 18B20 chip (previous version runs perfectly). There are no 1-wire devices in /sys/bus/w1/devices/w1 bus master directory:
Yes, this is tricky. I don't know, if I did something wrong with the kernel configuration, or if the kernel changed this (which would be bad, because user mode program would break, if they don't do a switch-case based on the kernel version), but the path for the device with the previous version (kernel 3.2.18, based on bootc's kernel) was "/sys/bus/w1/devices/w1_bus_master1/22-0000001d84f2/w1_slave" and now (with kernel 3.1.9, based on the Raspbian kernel distribution) the path is "/sys/bus/w1/devices/22-0000001d84f2/w1_slave". And the 3.2.18 kernel uses "_" to separate the names in "w1 bus master", 3.1.9 uses spaces. Sorry, I didn't mentioned this change explicitly, just in the sample for the w1 test in my posting.
I don't quite follow this - is the 18B20 working with Raspbian......or not? ;)

Texy
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

Ste123
Posts: 19
Joined: Sat Aug 11, 2012 7:10 am

Re: kernel patch for Dallas 1-wire interface

Wed Aug 15, 2012 12:13 pm

I just followed the instructions from yesterday (14th Aug) and got it all working in a few minutes with a DS18B20

Thank-you Mr Buss.

asb
Forum Moderator
Forum Moderator
Posts: 853
Joined: Fri Sep 16, 2011 7:16 pm
Contact: Website

Re: kernel patch for Dallas 1-wire interface

Wed Aug 15, 2012 2:57 pm

Frank, would you like to submit a pull request against github.com/raspberrypi/linux?

User avatar
Frank Buss
Posts: 92
Joined: Fri Jan 06, 2012 4:39 pm
Contact: Website

Re: kernel patch for Dallas 1-wire interface

Wed Aug 15, 2012 3:00 pm

texy wrote:
Frank Buss wrote:
rafal.deska wrote:Thanks for your job. Unfortunately the latest kernel doesn't work with 18B20 chip (previous version runs perfectly). There are no 1-wire devices in /sys/bus/w1/devices/w1 bus master directory:
Yes, this is tricky. I don't know, if I did something wrong with the kernel configuration, or if the kernel changed this (which would be bad, because user mode program would break, if they don't do a switch-case based on the kernel version), but the path for the device with the previous version (kernel 3.2.18, based on bootc's kernel) was "/sys/bus/w1/devices/w1_bus_master1/22-0000001d84f2/w1_slave" and now (with kernel 3.1.9, based on the Raspbian kernel distribution) the path is "/sys/bus/w1/devices/22-0000001d84f2/w1_slave". And the 3.2.18 kernel uses "_" to separate the names in "w1 bus master", 3.1.9 uses spaces. Sorry, I didn't mentioned this change explicitly, just in the sample for the w1 test in my posting.
I don't quite follow this - is the 18B20 working with Raspbian......or not? ;)

Texy
With my DS1822 is works, and now others reported that it works with 1820, too. What I wanted to say was, that with the new kernel the path to the device changed :-)

User avatar
Frank Buss
Posts: 92
Joined: Fri Jan 06, 2012 4:39 pm
Contact: Website

Re: kernel patch for Dallas 1-wire interface

Wed Aug 15, 2012 3:17 pm

maui wrote:Hi Frank,

I was waiting for the raspbian patch :)

After doing

Code: Select all

sudo bash raspbian-w1-update
my pi pachtes the kernel fine, then reboots and it stucks at the rainbow image ;)

But I saved my kernel before... so no big deal ;)
I tried 3 times ... :(

It isn't a "fresh" system. I installed XBMC, php, apache, gpio libs,..., may that be the cause?

What can I do now? do I need do cross compile :( ?
Maybe you've installed other kernel modules, which are loaded at start? My update script was intended for a clean new installation, and it renames the /lib/modules/3.1.9+ directory , see the the update script content below. But when you say that just restoring the kernel rescued it, it can't be the modules.

Maybe no space left on /boot? This is a smaller partition than the others. You can try to execute the steps in the script at the commandline one by one (use ssh into the device, then you can copy-and-paste it). To verify that the download was ok, here are some checksums (you can verifiy it with "md5sum file", kernel.img=un-g'ziped and renamed kernel-raspbian-w1.gz) :

Code: Select all

57413f4aa5fedba721df41727ed22c26 kernel-raspbian-w1.gz
b0916f6d2a30c551f1935f5597255171 modules-raspbian-w1.tgz
c8c7bda5b0b4e2900f6ddd6c6024cec2 kernel.img
Sizes:

Code: Select all

2950309 kernel-raspbian-w1.gz
9094394 modules-raspbian-w1.tgz
6181884 kernel.img
Contents of /raspbian-w1-update:

Code: Select all

#!/bin/sh

# load: "rm -f raspbian-w1-update ; wget http://www.frank-buss.de/raspberrypi/raspbian-w1-update"
# start as root: "bash raspbian-w1-update"

cd /boot
rm -f kernel-raspbian-w1.gz kernel-raspbian-w1
wget http://www.frank-buss.de/raspberrypi/kernel-raspbian-w1.gz
gzip -d kernel-raspbian-w1.gz
mv kernel-raspbian-w1 kernel.img
cd /lib/modules
rm -f modules-raspbian-w1.tgz
rm -rf 3.1.9+.old
wget http://www.frank-buss.de/raspberrypi/modules-raspbian-w1.tgz
mv 3.1.9+ 3.1.9+.old
tar -xzvf modules-raspbian-w1.tgz
rm -f modules-raspbian-w1.tgz
sync
reboot

User avatar
Frank Buss
Posts: 92
Joined: Fri Jan 06, 2012 4:39 pm
Contact: Website

Re: kernel patch for Dallas 1-wire interface

Wed Aug 15, 2012 3:26 pm

asb wrote:Frank, would you like to submit a pull request against github.com/raspberrypi/linux?
sure, done.

maui
Posts: 25
Joined: Sun Jul 08, 2012 10:10 am

Re: kernel patch for Dallas 1-wire interface

Wed Aug 15, 2012 10:20 pm

Moin Frank,

I did the step by step install but got the same results -> stuck at rainbow screen.
So I wiped my long,good working image and did a fresh install of raspbian, and now ... it works :) :P

But is it normal after running "rpi-update" to patch the kernal again?

Thanks for your effort

User avatar
Frank Buss
Posts: 92
Joined: Fri Jan 06, 2012 4:39 pm
Contact: Website

Re: kernel patch for Dallas 1-wire interface

Thu Aug 16, 2012 4:43 am

maui wrote: I did the step by step install but got the same results -> stuck at rainbow screen.
So I wiped my long,good working image and did a fresh install of raspbian, and now ... it works :) :P
Good that it works now, but would have been interesting to know why it didn't worked for your installation. Maybe I should add a warning "can kill your running system, if it is not a clean Raspbian installation" in the update script :-) But it is a temporary solution anyway. I think my pull request for the official distribution looks good now, so that it will be integrated in the next official release.
maui wrote: But is it normal after running "rpi-update" to patch the kernal again?
I think the "update" menu item in "raspi-config" updates the "raspi-config" program itself, only. I don't know, if the update process for Raspbian can update the Linux kernel. I've tried "apt-get update" and there were no updated packages. But you are right, if the kernel are updated, you have to run the patch again.

maui
Posts: 25
Joined: Sun Jul 08, 2012 10:10 am

Re: kernel patch for Dallas 1-wire interface

Thu Aug 16, 2012 8:44 am

Good to know, that it will be in the next release :)

I know the raspi-config "update" only updates the sources ;)
you have to do a "apt-get upgrade" to install the new updates. But after the first install of the patch I did a rpi-update (firmware updater from Hexxeh) and I had to patch the kernal again after doing that.

EDIT: the rpi-update does update the kernel, but you can skip that with

Code: Select all

SKIP_KERNEL=1 rpi-update

davidmam
Posts: 101
Joined: Tue Dec 06, 2011 4:13 pm

Re: kernel patch for Dallas 1-wire interface

Thu Aug 16, 2012 10:30 am

I should say a big Thankyou to Frank for his hard work on this. I had it up and running with no problems. The only issue now is that when soldering my A2D converter I fried it somewhat so am now looking for a new one. Everything else works fine.

User avatar
Frank Buss
Posts: 92
Joined: Fri Jan 06, 2012 4:39 pm
Contact: Website

Re: kernel patch for Dallas 1-wire interface

Thu Aug 16, 2012 4:49 pm

maui wrote:But after the first install of the patch I did a rpi-update (firmware updater from Hexxeh) and I had to patch the kernal again after doing that.

EDIT: the rpi-update does update the kernel, but you can skip that with

Code: Select all

SKIP_KERNEL=1 rpi-update
Ok. I don't know which version of the firmware the rpi-update installs. The Raspbian distribution contains already a current one, e.g. you don't need to patch the kernel image anymore, like with older firmware from the first Debian distribution, so maybe no firmware update is needed. But maybe other bugs are fixed as well.

User avatar
rleyden
Posts: 71
Joined: Thu Jun 14, 2012 2:17 am

Re: kernel patch for Dallas 1-wire interface

Thu Aug 16, 2012 10:58 pm

Frank Buss wrote:I've applied the patch to the Raspbian kernel, this is the new repository:
Frank,
Thanks for the Raspbian patch. I got my DS18B20 sensor probe working after some trial and error.
I didn’t initially add a resistor to my pre-wired probe ( http://www.ebay.com/itm/1pcs-Waterproof ... 969wt_1503 ) because the Ebay listing said “no external components required”. Without the resistor the sensor is not detected. With a 4 K ohm resistor, everything was fine.

I also tried the method in your first post (I hadn’t read to the end of this thread). There were no errors but “lsmod” showed that w1-gpio hadn’t loaded. Of course, I didn't have the resistor at that point either.
Rich

User avatar
szrpj
Posts: 6
Joined: Tue Jul 03, 2012 9:17 pm
Contact: Website

Re: kernel patch for Dallas 1-wire interface

Sat Aug 18, 2012 9:27 pm

Frank, you are awesome and everything works great (few DS18B20). I hope all those patches will be in "default" raspberrypi/linux soon enough.

eldiabolosk
Posts: 15
Joined: Wed Aug 15, 2012 12:27 am

Re: kernel patch for Dallas 1-wire interface

Sun Aug 19, 2012 3:33 am

netomx wrote:Well now I use mplayer and it's working great, thank you guys. I made a little script, but I saw here that you use perl, and a lot of things, so I just used BASH

Code: Select all

#!/bin/bash
SENSORES=$(cat /sys/bus/w1/devices/w1_bus_master1/w1_master_slaves)
for item in ${SENSORES[*]}
do
VALOR=$(cat /sys/bus/w1/devices/$item/w1_slave | grep t= | cut -f2 -d= | awk '{print $1/1000}')
echo $VALOR
done
Save it to whatever name you want and give permissions, chmod a+x yourscript

and run it like this ./yourscript

enjoy it! I'll make another one but with some voices of MW3 and UrbanAssault =D

Hi,

Thanks for the BASH Script.
I am brand new to all this. I am fluent in BASH. Can use just BASH control devices? Such as reading temp sensors, control valves, etc? What is the advantage of using Tcl?

Ed

Thanks

eldiabolosk
Posts: 15
Joined: Wed Aug 15, 2012 12:27 am

Re: kernel patch for Dallas 1-wire interface

Sun Aug 19, 2012 3:38 am

pygmy_giant wrote:sorted it - needed to update lib/modules aswell as the /boot files ... couldn't use hexxeh's updater as I don't have a linux compatible internet connection as yet - I only have a 3g mobile broadband dongle (need to inxtall some bits and bobs to get it working) - have been thinking that it could possibly also be used as a GPS positioning device...?

GPS: I was thinking about such thing. For seismic acquisition work you can use GPS to sync time. I would love to know know more about it

WiFi: What do you have on mind. Could you use a WiFi modul from on old laptop that had debian drivers? Just an idea. Bear on mind I am brand new to all the hardware world. (It is quite exciting... where have I been all that time?)

User avatar
szrpj
Posts: 6
Joined: Tue Jul 03, 2012 9:17 pm
Contact: Website

Re: kernel patch for Dallas 1-wire interface

Sun Aug 19, 2012 10:04 pm

This is a thread for another topic (not 1-wire support, but some sort of "1-wire scripts"). But anyway — all those scripts should, in the first place, check if the CRC is OK and if it is print the result.

netomx
Posts: 80
Joined: Tue Oct 11, 2011 4:06 am

Re: kernel patch for Dallas 1-wire interface

Mon Aug 20, 2012 1:21 am

eldiabolosk wrote:
netomx wrote:Well now I use mplayer and it's working great, thank you guys. I made a little script, but I saw here that you use perl, and a lot of things, so I just used BASH

Code: Select all

#!/bin/bash
SENSORES=$(cat /sys/bus/w1/devices/w1_bus_master1/w1_master_slaves)
for item in ${SENSORES[*]}
do
VALOR=$(cat /sys/bus/w1/devices/$item/w1_slave | grep t= | cut -f2 -d= | awk '{print $1/1000}')
echo $VALOR
done
Save it to whatever name you want and give permissions, chmod a+x yourscript

and run it like this ./yourscript

enjoy it! I'll make another one but with some voices of MW3 and UrbanAssault =D

Hi,

Thanks for the BASH Script.
I am brand new to all this. I am fluent in BASH. Can use just BASH control devices? Such as reading temp sensors, control valves, etc? What is the advantage of using Tcl?

Ed

Thanks
Well, yeah. Look fot eh GPIO sensors, and you can echo 1 or 0 to an output.

davidmam
Posts: 101
Joined: Tue Dec 06, 2011 4:13 pm

Re: kernel patch for Dallas 1-wire interface

Mon Aug 20, 2012 8:40 am

The wiringPi library privides a nice command line interface to the GPIO port - well worth looking at.

Return to “Interfacing (DSI, CSI, I2C, etc.)”