Internal temperature sensor

How to use the Internal temperature sensor? do you have an API ?

You can use Analog to read, it will return raw value, then you have to do some convert, there is no API.

What channel? Do we have it in the pins NuGet?

1 Like

it is in ADC3, channel 18.

 var adc3 = AdcController.FromName(SC20100.AdcChannel.Controller3.Id);

 var adcChannel18 = adc3.OpenChannel(18);

while (true)
   var v = adcChannel18.ReadValue() ;

   Debug.WriteLine("raw value: " + v);

We should have this in pins NuGet I think

I completely agree

Calculate the actual temperature using the following formula:
((110°C - 30°C) / (TS_CAL2 - TS_CAL1)) * (TS_DATA - TS_CAL1) + 30°C
• TS_CAL2 is the temperature sensor calibration value acquired at 110°C
• TS_CAL1 is the temperature sensor calibration value acquired at 30°C
• TS_DATA is the actual temperature sensor output value converted by ADC

But I can not read TS_CAL1 and TS_CAL2 ( Marshal.ReadInt32((IntPtr)0x1FF1E820) -> exception OR Marshal.ReadInt16((IntPtr)0x1FF1E820) -> 0).
And need Set the TSEN bit in the ADCx_CCR register (24 bit) to wake up the temperature sensor from power - down mode.

We see, these registers are not ADC registers, also not in any public peripherals so can’t read.

How about if we give you TS_CAL1 and TS_CAL2 value?

ok, but this refers to ADC indirectly
better let me read and writeTS_CAL1 and TS_CAL2 value

Right, we will change this but this is just for now.

We cook / heat the board up from range ~30°C to ~120°C and see that TS_CAL1 and TS_CAL2 don’t change their values. Each board has a bit different, but not much far from those numbers.

TS_CAL1 = 0x3058;
TS_CAL2 = 0x4006;

TS_CAL1 = 0x2FB4;
TS_CAL2 = 0x3F71;

base on that, we have internal processor temperature around ~38°C.

Hope code below help

            const uint PERIPH_BASE = 0x40000000;
            const uint D3_AHB1PERIPH_BASE = (PERIPH_BASE +0x18020000);
            const uint ADC3_COMMON_BASE = (D3_AHB1PERIPH_BASE + 0x6300);

            var reTempetureWakup = (IntPtr)(ADC3_COMMON_BASE + 8);

            var reTempetureWakupValue = Marshal.ReadInt32(reTempetureWakup);

            reTempetureWakupValue |= (1 << 23);

            Marshal.WriteInt32(reTempetureWakup, reTempetureWakupValue);

            while (true)
                var v = adcChannel18.ReadValue();

                var ts1 = 0x3058; // Marshal.ReadInt32(regTS_CAL1);
                var ts2 = 0x4006; // Marshal.ReadInt32(regTS_CAL2);

                var t1 = (110 - 30) * 1.0;
                var t2 = (ts2 - ts1) * 1.0;
                var t3 = (v - ts1) * 1.0;
                var temp = t1 / t2 * t3 + 30;

                Debug.WriteLine("temp " + temp);

For me, the code above returns 12°C on the SC20100S, at a room temperature of approximately 23°C. Could the calibration values TS_CAL1 and TS_CAL2 be obtained via interop (Runtime Loadable Interops)? By the way, where did the interop from TinyCLR 2.0 go? I can’t find it in libraries and documentation.

What device are you testing on? FEZ Bit, stick, Dev… so we can try?

SC20100S Dev Rev B

Does it go up or keep 12°C all the time?

It is kept between 12°C and 13°C for several hours.

Weird, if we are using same number TS1 and TS2, only TS_DATA is different which is actual analog value. Not sure why yours is far way.

please check ts1 = 0x3058 (Hex), not 3058… and enabled temperature wake up sensor.

I use the same published code as you, I copied it. Moreover, now I come to one crazy thing. When I insert Thread.Sleep(x) before adcChannel18.ReadValue, for different x it returns a different temperature.

x = 0, temp = 54°C
x = 1, temp = 50°C
x = 2, temp = 46°C
x = 3, temp = 42°C
x = 4, temp = 39°C
x = 5, temp = 35°C
x = 10, temp = 22°C
x = 15, temp = 13°C
x > 17, temp = 12°C

No sleep, heavy => hot?
Sleep => idle => cold ?


The real temperature is still 38°C, I measured it.

Please tell me something about missing interop in TinyCLR 2.0. I would like to test it at a lower level.