Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp59601pxy; Wed, 21 Apr 2021 18:29:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwejmj05vlUH+lN5QMgrV4b5R5cEkoeDZXCzRma1OXCApPwmrrx/eIOichDB0rkoF2hUqXF X-Received: by 2002:a65:468d:: with SMTP id h13mr929093pgr.373.1619054942386; Wed, 21 Apr 2021 18:29:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619054942; cv=none; d=google.com; s=arc-20160816; b=F11I83UNX/DodrvHPTcxfPa073niTB86oGrdrHrdXwbpplJWTd8hbh0BGxGv7LaHzS 5DYsfRSnzlHtr7bKXnBM4OgBX4CnhuZJV6FXJM9dhw4B4VzJaMR+51Di5rEl2V8cRzOc VXk5+q5JoCBjnO68cO+V7y8l0qvL3s/YB/Zn85lJYSx5KprQukShl79lSx2rr5THm3kZ 4UaT6eTcS/Tgv9RzoQXSrvkTs70F3x9DSeKrz3Pm+D1Jr07nvEFhO8CYvQG8qANscN0n DMXFZiCwm9zAq1iM8tgErdy++ApKz5MTD+0eKY21SeOw3+rfAIGzik5hdYwa7ZXNc5m2 dtCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=ihwBbr0wDU/pkGia8qTBJOVfFxizBeK/hnkFTc8CCWU=; b=LekEBWaPZVP093Gz3qnMOHrpEKB7fnpo0wG0sLXBUMdIGk88PzND7emFkLfYIrETtp e5hixwSNfq6Rp9lAcW326zEy3Z87JffPdSwN0nzGimab4zlGrjoviunF0SxsJJurtJ1w CJjXZ1m8fmYo9v4JYMsg+htfNjqftwOsHqvznX9dfbVgfbVPIMkdDxzLsoFfzzVwqYDs YWjZ2rOSOm1RzzxiwavCwt8DWcpjaX/XfqLfy13oiTquxhB2WwEVAVBEJjX0XW5aMIn0 LVpUwt28I2tm/lSicbt4PoSyu6KJUb3au08xZo8zxxILjtA5KJBi2BytIBSj4eC829nT Jguw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IZ3haLM5; 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=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r20si1399288pgv.32.2021.04.21.18.28.49; Wed, 21 Apr 2021 18:29:02 -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=@linaro.org header.s=google header.b=IZ3haLM5; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234888AbhDUXJU (ORCPT + 99 others); Wed, 21 Apr 2021 19:09:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59550 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234826AbhDUXJT (ORCPT ); Wed, 21 Apr 2021 19:09:19 -0400 Received: from mail-lf1-x132.google.com (mail-lf1-x132.google.com [IPv6:2a00:1450:4864:20::132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 777D5C06174A for ; Wed, 21 Apr 2021 16:08:45 -0700 (PDT) Received: by mail-lf1-x132.google.com with SMTP id x19so38827367lfa.2 for ; Wed, 21 Apr 2021 16:08:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=ihwBbr0wDU/pkGia8qTBJOVfFxizBeK/hnkFTc8CCWU=; b=IZ3haLM5tJgi14Jfg0jJ1v5/78eVhgD8eIYJUrR9Izelrt74oysMKCUZZLkwfJo5oF TV3VkBNz1mJ/1bePKD+xFSmIUYZP4B/qVg/n4GSkyARswtHbOWvFkiqg5WRNl1Pq5rnT gd0sHo1zYzyORfqIbFghSzcX7RqDUNmKaErsomEZ1aUxcC2+CQ20SeA5IYQ1jmt2sICi D/3//l0flWRzR7DdvSbmYWTZO8xfO5dPSbTiU0YQjCpqtkAkSuBKWz/Z7Nnq1Guws7ik w9fVyVM456cSTZVssMxCnDz3sRxLlsObrr3w0nGRNyIC5JkJBM1Y5ZqnvaT+MONX8S+I Kc1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=ihwBbr0wDU/pkGia8qTBJOVfFxizBeK/hnkFTc8CCWU=; b=joZzhsmWVfDqYkmT4QWgZ7AOEbCaKV0Zf5R3f5Rh/ORWHPHjkWpxfsZLjAOo9Wzfjo saDF2YPQINdkaBLeE6JPwXNgUkVuxpOuMG/mrXcPr9UEx3r5FRdLUuF61PFp+uZTd6tX jIn3gjNJ43U+c5qaYtWwKCbD+hYys2l1XJ1W1Y0Gv+dP6iF0pPyxtHdvtMdnCKOlvJ7i 51Pj0uibhS8Jq0iHKBhO50nEnTQCuAg2gdPGLc2HZL3/6x4h7YB80cOpXSuPo5p0F5RA ZnAJ5zO1Qe9SpLhMEnxS9CfmmF1B3mVVDiITz51VJ0AwdGrLRU6dbKOumXdKBZsLAe9P b67w== X-Gm-Message-State: AOAM530Mjy11pXvWGvQKn/szUUpFESRot5/r4Ad8xpXeANqIyL48v/Qw /Q0SEXmRS0JYmQodhqW3b9Z1Pwu3QrP/AG0sUSxqe5R0B90= X-Received: by 2002:a05:6512:3a85:: with SMTP id q5mr347706lfu.465.1619046151567; Wed, 21 Apr 2021 16:02:31 -0700 (PDT) MIME-Version: 1.0 References: <483ac17b-705a-38c3-54ee-7f0089262c03@gmail.com> In-Reply-To: From: Linus Walleij Date: Thu, 22 Apr 2021 01:02:20 +0200 Message-ID: Subject: Re: BUG: iio: mpu3050: Wrong temperature scale To: Lars-Peter Clausen Cc: Andy Shevchenko , Dmitry Osipenko , Jonathan Cameron , "linux-iio@vger.kernel.org" , Linux Kernel Mailing List , Svyatoslav Ryhel , Nathan Royer , Jean-Baptiste Maneyrol Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Apr 21, 2021 at 10:00 PM Lars-Peter Clausen wrote= : > 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 w= rote: > >>> > >>>> 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 val= ue > >>>> as a signed integer, while upstream assumes it's unsigned. > >>>> > >>>> [1] > >>>> https://github.com/blaisejarrett/Arduino-Lib.MPU3050/blob/master/MPU= 3050lib.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= =C2=B0C. > >> > >> Range: -30=C2=B0C .. +85=C2=B0C > >> Sensitivity: 280 LSB/=C2=B0C > >> Room temperature offset: 35=C2=B0C =3D -13200 LSB > >> > >> [1]: https://www.cdiweb.com/datasheets/invensense/mpu-3000a.pdf Oh nice find! > > So, if I'm reading this and the register description right the value > > is in the range > > -32768..32767. > > -13200 defines 35=C2=B0C > > > > 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 =3D (23000 + x)/280, which is what is in the driver. > So the only bit missing is the cast to s16. Yup there is the bug. (I am guilty.) Dmitry will you test & send a patch? Yours, Linus Walleij