Unable to do the 1-wire temperature test with GRiSP 2

I’ve got a grisp2 running the original firmware, trying to do the basic 1-wire test: reading temperature from a DS18S20+. These are allegedly a drop-in replacement for the DS18B20, but I’ve tried a handful of them and don’t get expected results.

Via owread -C -s 127.0.0.1:4304 /10.71394A030800/temperature I get a very reasonable 16.8125 degrees, which feels about right. This one is embedded in another system and its not so easy to extract, so I’ve tried with another 3 probes, all with similar incorrect results on the grisp2.

What are the 1-wire plug alignments for the grisp2? I couldnt find this anywhere, so I experimented but don’t know if I got it correct or not. I can at least read the bus for devices.

(shell@grisp-001016)1> [D] = grisp_onewire:transaction(fun grisp_onewire:search/0).
[[16,8,168,74,3,8,0,62]]

%% room temperature

(shell@grisp-001016)2> onewire_ds18b20:temp(D).
3.875

(shell@grisp-001016)3> onewire_ds18b20:convert(D, 1000).  onewire_ds18b20:temp(D).
ok
(shell@grisp-001016)21> 3.5
(shell@grisp-001016)22> onewire_ds18b20:convert(D, 1000).  onewire_ds18b20:temp(D).
ok
(shell@grisp-001016)23> 3.125
(shell@grisp-001016)24> onewire_ds18b20:convert(D, 1000).  onewire_ds18b20:temp(D).
ok

These temperatures should return something around 16 and 40 or so.

grisp2 full boot log

barebox 2019.01.0-bsp-yocto-i.mx6ul-pd19.1.1 #10 Thu Dec 16 05:23:35 PST 2021


Board: PHYTEC phyCORE-i.MX6 Ultra Light SOM with eMMC
detected i.MX6 ULL revision 1.1
i.MX reset reason POR (SRSR: 0x00000001)
i.MX6 ULL unique ID: 5988f5404138c9d7
mdio_bus: miibus0: probed
eth0: got preset MAC address: 50:2d:f4:27:09:0d
imx-usb 2184200.usb@2184200.of: USB EHCI 1.00
imx-esdhc 2190000.usdhc@2190000.of: registered as mmc0
imx-esdhc 2194000.usdhc@2194000.of: registered as mmc1
state: New state registered 'state'
state: Using bucket 0@0x00000000
netconsole: registered as netconsole-1
NOTICE: phySOM-i.MX6: Using environment in MMC
malloc space: 0x8fefcfa0 -> 0x9fdf9f3f (size 255 MiB)
mmc1: detected MMC card version 5.0
mmc1: registered mmc1.boot0
mmc1: registered mmc1.boot1
mmc1: registered mmc1
envfs: no envfs (magic mismatch) - envfs never written?
running /env/bin/init...

Hit m for menu or any key to stop autoboot:    1
booting 'sdcard'
Cannot set parameter mmc0.probe: Connection timed out
Nothing bootable found on 'mmc0'
Nothing bootable found
Running /env/boot/sdcard failed
booting 'sdcard' failed: error -1
booting 'system'
Selecting active system0
booting 'system0'
booting 'grisp_demo'
blspec: booting grisp_demo from mmc1
   Image Name:   RTEMS
   Created:      2022-01-03  11:34:07 UTC
   OS:           Linux
   Architecture: ARM
   Type:         Kernel Image
   Compression:  gzip compressed
   Data Size:    3522766 Bytes = 3.4 MiB
   Load Address: 80200000
   Entry Point:  80200000

Loading U-Boot uImage '/mnt/mmc1.0//grisp_demo/erts-11.2.2.9/bin/beam.zImage'
Loading devicetree from '/mnt/mmc1.0//grisp_demo/erts-11.2.2.9/bin/imx6ul-grisp2.dtb'
commandline:  console=ttymxc0,115200n8
Starting kernel in secure mode
[ERL] Initializing
[ERL] Initializing buses
[ERL] Initializing EEPROM
sig_version: 1
serial: 1016
batch_nr: 1
prod_year: 2022
prod_month: 1
prod_day: 26
vers_major: 33
vers_minor: 2
ass_var: 1
mac_addr: 00:00:00:00:00:00
crc16: a88b
[ERL] Mounting SD card asynchronously
[ERL] Lowering self priority
[ERL] Initializing libbsd
nexus0: <RTEMS Nexus device>
ofwbus0: <Open Firmware Device Tree> on nexus0
simplebus0: <Flattened device tree simple bus> on ofwbus0
simplebus1: <Flattened device tree simple bus> mem 0x2000000-0x20fffff on simplebus0
simplebus2: <Flattened device tree simple bus> mem 0x2000000-0x203ffff on simplebus1
simplebus3: <Flattened device tree simple bus> mem 0x2100000-0x21fffff on simplebus0
regfix0: <Fixed Regulator> on ofwbus0
regfix1: <Fixed Regulator> on ofwbus0
ccm0: <Freescale i.MX6 Clock Control Module> mem 0x20c4000-0x20c7fff irq 119,120 on simplebus1
gpio0: <Freescale i.MX GPIO Controller (RTEMS)> mem 0x209c000-0x209ffff irq 98,99 on simplebus1
gpiobus0: <GPIO bus> on gpio0
gpio1: <Freescale i.MX GPIO Controller (RTEMS)> mem 0x20a0000-0x20a3fff irq 100,101 on simplebus1
gpiobus1: <GPIO bus> on gpio1
gpio2: <Freescale i.MX GPIO Controller (RTEMS)> mem 0x20a4000-0x20a7fff irq 102,103 on simplebus1
gpiobus2: <GPIO bus> on gpio2
gpio3: <Freescale i.MX GPIO Controller (RTEMS)> mem 0x20a8000-0x20abfff irq 104,105 on simplebus1
gpiobus3: <GPIO bus> on gpio3
gpio4: <Freescale i.MX GPIO Controller (RTEMS)> mem 0x20ac000-0x20affff irq 106,107 on simplebus1
gpiobus4: <GPIO bus> on gpio4
usbphy0: <Freescale i.MX6 USB PHY> mem 0x20c9000-0x20c9fff irq 76 on simplebus1
usbphy1: <Freescale i.MX6 USB PHY> mem 0x20ca000-0x20cafff irq 77 on simplebus1
imx_usbmisc0: <i.MX USB Misc Control> mem 0x2184800-0x21849ff on simplebus3
ehci0: <Freescale i.MX integrated USB controller> mem 0x2184000-0x21841ff irq 75 on simplebus3
usbus0: EHCI version 1.0
usbus0: stop timeout
usbus0 on ehci0
ehci1: <Freescale i.MX integrated USB controller> mem 0x2184200-0x21843ff irq 74 on simplebus3
usbus1: EHCI version 1.0
usbus1 on ehci1
ffec0: <Freescale Gigabit Ethernet Controller> mem 0x2188000-0x218bfff irq 150,151 on simplebus3
miibus0: <MII bus> on ffec0
ksz8091rnb0: <Microchip KSZ8091RNB with 50MHz clock> PHY 1 on miibus0
ksz8091rnb0:  10baseT, 10baseT-FDX, 100baseTX, 100baseTX-FDX, auto
info: ffec0: Ethernet address: 50:2d:f4:27:09:0d
sdhci_fsl0: <Freescale uSDHC controller> mem 0x2194000-0x2197fff irq 55 on simplebus3
mmc0: <MMC/SD bus> on sdhci_fsl0
sdhci_fsl1: <Freescale uSDHC controller> mem 0x2190000-0x2193fff irq 54 on simplebus3
media listener: event = DISK ATTACH, state = INQUIRY, src = mmcsd
media listener: event = DISK ATTACH, state = SUCCESS, src = mmcsd, dest = /dev/mmcsd-0
mmedia listener: event = MOUNT, state = INQUIRY, src = /dev/mmcsd-0
mcsd0: 8GB <MMCHC Q2J55L 1.0 SN 10DDA330 MFG 08/2020 by 19 0x004e> at mmc0 45.0MHz/8bit/65535-block
media listener: event = MOUNT, state = FAILED, src = /dev/mmcsd-0
mmedia listener: event = PARTITION INQUIRY, state = INQUIRY, src = /dev/mmcsd-0
mmedia listener: event = PARTITION INQUIRY, state = SUCCESS, src = /dev/mmcsd-0
cmedia listener: event = PARTITION ATTACH, state = INQUIRY, src = /dev/mmcsd-0
smedia listener: event = PARTITION ATTACH, state = SUCCESS, src = /dev/mmcsd-0, dest = /dev/mmcsd-0-0
dmedia listener: event = MOUNT, state = INQUIRY, src = /dev/mmcsd-0-0
0boot: Additional partition. This is currently not supported in RTEMS.mmcsd0boot0: 17MB partition 1 at mmcsd0
media listener: event = MOUNT, state = SUCCESS, src = /dev/mmcsd-0-0, dest = /media/mmcsd-0-0
mmedia listener: event = PARTITION ATTACH, state = INQUIRY, src = /dev/mmcsd-0
mmedia listener: event = PARTITION ATTACH, state = SUCCESS, src = /dev/mmcsd-0, dest = /dev/mmcsd-0-1
cmedia listener: event = MOUNT, state = INQUIRY, src = /dev/mmcsd-0-1
sd0boot: Additional partition. This is currently not supported in RTEMS.mmcsd0boot1: 17MB partition 2 at mmcsd0
media listener: event = MOUNT, state = FAILED, src = /dev/mmcsd-0-1
mmcsd0rpmb: 4MB partition 3 at mmcsd0
usbus0: 480Mbps High Speed USB v2.0
usbus1: [zone: unpcb] kern.ipc.maxsockets limit reached
480Mbps High Speed USB v2.0
[ERL] Running ifconfig on lo0
info: lo0: link state changed to UP
waiting for SD...

[ERL] SD card mounted
[ERL] GRiSP mountpoint from the FDT: /media/mmcsd-0-0/
ugen0.1: <Freescale EHCI root HUB> at usbus0
[ERL] Reading /media/mmcsd-0-0/grisp.iniuhub0: <Freescale EHCI root HUB, class 9/0, rev 2.00/1.00, addr 1> on usbus0
grisp.ini: section "boot", name "image_path", value "/media/mmcsd-0-0/grisp_demo/erts-11.2.2.9/bin/beam"
ugen1.1: <Freescale EHCI root HUB> at usbus1
grisp.ini: section "erlang", name "args", value "erl.rtems -C multi_time_warp -- -mode embedded -home . -pa . -root grisp_demo -boot grisp_demo/releases/0.1.0/start -internal_epmd epmd_sup -kernel inetrc "./erl_inetrc" -sname shell -setcookie grisp -config grisp_demo/releases/0.1.0/sys.config"
uhub1: <Freescale EHCI root HUB, class 9/0, rev 2.00/1.00, addr 1> on usbus1
erl args: section "erlang", name "args", value "erl.rtems -C multi_time_warp -- -mode embedded -home . -pa . -root grisp_demo -boot grisp_demo/releases/0.1.0/start -internal_epmd epmd_sup -kernel inetrc "./erl_inetrc" -sname shell -setcookie grisp -config grisp_demo/releases/0.1.0/sys.config"
grisp.ini: section "network", name "ip_self", value "dhcp"
[ERL] Booting with arg: erl.rtems -C multi_time_warp -- -mode embedded -home . -pa . -root grisp_demo -boot grisp_demo/releases/0.1.0/start -internal_epmd epmd_sup -kernel inetrc "./erl_inetrc" -sname shell -setcookie grisp -config grisp_demo/releases/0.1.0/sys.config
[ERL] hostname: grisp-001016
[ERL] Starting DHCP
[ERL] mkdir /tmp
info: ffec0: link state changed to DOWN
[ERL] mkdir /tmp/log
[ERL] mkdir /home
[ERL] Setting environment
[ERL] chdir(/media/mmcsd-0-0/)
[ERL] getcwd: /media/mmcsd-0-0
[ERL] Starting BEAM
uhub0: 1 port with 1 removable, self powered
uhub1: 1 port with 1 removable, self powered
warning: no interfaces have a carrier
ugen1.2: <Realtek 802.11n NIC> at usbus1
rtwn0: <Realtek 802.11n NIC, class 0/0, rev 2.00/0.00, addr 2> on usbus1
rtwn0: MAC/BB RTL8188EU, RF 6052 1T1R
Eshell V11.2.2.9  (abort with ^G)
(shell@grisp-001016)1>
1 Like

Alas they are not here are the differncenses (courtesy ChatGPT Pro) We only implemented the 18B20. PR wellcome :wink:

  1. Family code

    • DS18B20 has a family code of 0x28.
    • DS18S20 (and the older DS1820) has a family code of 0x10.
      Many 1-Wire libraries check the family code to decide how to interpret the scratchpad data. If you’re using a routine that was written specifically for the DS18B20, it may ignore or misinterpret a 0x10 device, giving the wrong reading.
  2. Resolution and scratchpad layout

    • DS18B20 supports user-selectable resolution from 9 to 12 bits. Typically, people run it at 12-bit resolution, yielding 0.0625°C increments.
    • DS18S20 outputs effectively 9 bits of resolution (0.5°C steps in the basic reading). However, it also uses additional registers (COUNT_PER_C, COUNT_REMAIN) if you want the fractional part (this is the so-called “extended” or “improved” resolution method).
      Because of these differences, the scratchpad (the block of bytes you read over 1-Wire) is laid out differently, and the formula for calculating the final temperature is different.
  3. Data format & calculation

    • DS18B20: The temperature data is in bytes 0 and 1 of the scratchpad, which can be directly interpreted (with some scaling, depending on resolution).
    • DS18S20: It always gives a 9-bit value in the main temperature register (bytes 0 and 1), but then you use bytes 6 and 7 (COUNT_PER_C and COUNT_REMAIN) to get a finer resolution. The standard formula (from the Maxim datasheet) is:
      [
      T = T_\text{reading} - 0.25 + \frac{\text{COUNT_PER_C} - \text{COUNT_REMAIN}}{\text{COUNT_PER_C}}
      ]
      This differs from how you would interpret DS18B20 data directly.
  4. Default resolution

    • DS18B20 is often used at 12-bit resolution (0.0625°C).
    • DS18S20 is fixed 9-bit for the main measurement (0.5°C). You must do extra math with the count registers to improve the resolution.
1 Like