Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp57232pxy; Wed, 21 Apr 2021 18:24:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzqI/LnGM/p4y68wA6R9tkx/g7pYxCSRzn6cA3HsKuOsiGRjzBxBST47NdlTZyAnPbl7SDt X-Received: by 2002:a62:9283:0:b029:25d:4039:cac1 with SMTP id o125-20020a6292830000b029025d4039cac1mr902660pfd.77.1619054640701; Wed, 21 Apr 2021 18:24:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619054640; cv=none; d=google.com; s=arc-20160816; b=LaKaq4YvDYnJWrIEhZPlpwxQSG3XBu6guEWjtgSmbbOW6KzN5ycXU0YoQA/acY2muS FEMeKTs4Fk2beZmsQvEGuqDRqZ9pXGLRvh5x5NHpkFWABYysTZ7bO0xGQ1FhTpYqHYMR pZjjwRg0mzSLoeQpAOu9OZNpuAmJGQhRYb+YnQroIIONUv1VYJg31UAciAyGCjJpCfd0 Y1pYVmJ1HMHjXaI2aWSrjlqt+LYZWH2ExvE2yo50QciamriNebqK3J4r7Uj1Pqs7sR9M f6vhJxKI6R2Y7PjVztlZX0Qm1I6nzrV064qiSfu/voqmOWFCRD9XGOu95DuR75MjskqL Vr7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-language:content-transfer-encoding :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=yt70wR24IFvvxPRHHqNJYfo+rlOehQs+hl0UuMrdIUw=; b=teMRyBfrz6fOgEga3+2vCD2XAWK74vzFFyt9pgCPGYNKM2QtwZ1Yx7nkHqQMYWIKtc PQebivQf/Yyfph+LO5b96skVWpffr8YV6lxw97keJzgMAp81M35RmIvMxHlB7Dd0HYRk bWlg2We/HTITZNgOTofoiRkmrkt+8+QmIiEpcz6Q2KXunD74WijM1AxhHP9UjGIlFJu1 5l9eeI9M+I/+mA6Xp2x/J8BaZcfasiKYdikDQ+bXw8qqvRVwsZkOpOFLh+bi4HVSdMx3 ehmRdfvqnieqidaVnc1TEtWayq9MlcxkzXJXL1MVcsUjHgQeNj5FslXFN+y7SwOBP0gC plkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@metafoo.de header.s=default2002 header.b=UKYaeUrV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=metafoo.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r10si1459732pgd.28.2021.04.21.18.23.49; Wed, 21 Apr 2021 18:24:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@metafoo.de header.s=default2002 header.b=UKYaeUrV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=metafoo.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245601AbhDUUA6 (ORCPT + 99 others); Wed, 21 Apr 2021 16:00:58 -0400 Received: from www381.your-server.de ([78.46.137.84]:43904 "EHLO www381.your-server.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236019AbhDUUA5 (ORCPT ); Wed, 21 Apr 2021 16:00:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=metafoo.de; s=default2002; h=Content-Transfer-Encoding:Content-Type:In-Reply-To: MIME-Version:Date:Message-ID:From:References:Cc:To:Subject:Sender:Reply-To: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID; bh=yt70wR24IFvvxPRHHqNJYfo+rlOehQs+hl0UuMrdIUw=; b=UKYaeUrVOsbtJyT4RDME2ixy+y MM8Iblj/3FdDkK/vGZLJ0dr/mPsm1XJlkn3ldDDM9n53Uem+FyoE2jp0LeRj4oTCidXFK8l/Xxnl9 /xTWzTbmZnwQxoo0yBfNawbULL9hRmq4hEvPBC4un72CHSRKm9qvCTpSR146VB9wUm0EhF+uu209m EwZ0ipm9hlNSzN8zdc6FOo3IWuC0Gy8GvwEA59bZrkTf6c8douPur6BU9d7ePReVBXP+AnFswRuHb 127L9G7agYVKVAGuD3VJAgl+5YHn9oUzvjLNnUOaVKKiD6UvyOd96D4ABubO1WZuQ4t/3Uaxk0Z1P e9eNIdEg==; Received: from sslproxy01.your-server.de ([78.46.139.224]) by www381.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92.3) (envelope-from ) id 1lZJ1J-000GXC-3t; Wed, 21 Apr 2021 22:00:21 +0200 Received: from [2001:a61:2a42:9501:9e5c:8eff:fe01:8578] by sslproxy01.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lZJ1I-000RA3-Qk; Wed, 21 Apr 2021 22:00:20 +0200 Subject: Re: BUG: iio: mpu3050: Wrong temperature scale To: Andy Shevchenko , Linus Walleij Cc: Dmitry Osipenko , Jonathan Cameron , "linux-iio@vger.kernel.org" , Linux Kernel Mailing List , Svyatoslav Ryhel , Nathan Royer , Jean-Baptiste Maneyrol References: <483ac17b-705a-38c3-54ee-7f0089262c03@gmail.com> From: Lars-Peter Clausen Message-ID: Date: Wed, 21 Apr 2021 22:00:20 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.9.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-Authenticated-Sender: lars@metafoo.de X-Virus-Scanned: Clear (ClamAV 0.102.4/26147/Wed Apr 21 13:06:05 2021) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 4/21/21 9:41 PM, Andy Shevchenko wrote: > On Wed, Apr 21, 2021 at 10:05 PM Andy Shevchenko > wrote: >> On Wed, Apr 21, 2021 at 1:14 PM Linus Walleij wrote: >>> On Tue, Apr 20, 2021 at 11:26 PM Dmitry Osipenko wrote: >>> >>>> I found a non-kernel example >>>> which uses a similar equation [1], but in a different form. The main >>>> difference is that the Arduino code interprets a raw temperature value >>>> as a signed integer, while upstream assumes it's unsigned. >>>> >>>> [1] >>>> https://github.com/blaisejarrett/Arduino-Lib.MPU3050/blob/master/MPU3050lib.cpp#L111 >>> Oh that's nice. Room temperature as mentioned is 20 deg C >>> I think? >>> >>> The divide by 280 part seems coherent in all examples. >>> >>>> Still, even if assume that the raw temperature is a signed s16 value, it >>>> gives us ~35C in a result, which should be off by ~10C. >> Actually here [1] it says in chapter 3.1 that room temperature is 35°C. >> >> Range: -30°C .. +85°C >> Sensitivity: 280 LSB/°C >> Room temperature offset: 35°C = -13200 LSB >> >> [1]: https://www.cdiweb.com/datasheets/invensense/mpu-3000a.pdf > > So, if I'm reading this and the register description right the value > is in the range > -32768..32767. > -13200 defines 35°C > > 50000 as mentioned by Dmitry is actually -15536. So, it means that the > more negative a value is the higher temperature is shown. > > Since it's linearized scale, now we can see that > > (13200 -15536)/280 + 35 gives us 26.66. > > Does it make sense? (13200 + x)/280 + 35 = (23000 + x)/280, which is what is in the driver. So the only bit missing is the cast to s16.