1071 views|7 replies

1w

Posts

16

Resources
The OP
 

【Jihai APM32F407】5. Run the internal temperature sensor example [Copy link]

 

This chip from Jiuhai also has a temperature sensor in ADC1.

And the DMA function is enabled in the routine:

void DMA_Init(uint32_t* Buf)
{
    /* DMA Configure */
    DMA_Config_T dmaConfig;

    /* Enable DMA clock */
    RCM_EnableAHB1PeriphClock(RCM_AHB1_PERIPH_DMA2);

    /* size of buffer*/
    dmaConfig.bufferSize = 1;
    /* set memory Data Size*/
    dmaConfig.memoryDataSize = DMA_MEMORY_DATA_SIZE_HALFWORD;
    /* Set peripheral Data Size*/
    dmaConfig.peripheralDataSize = DMA_PERIPHERAL_DATA_SIZE_HALFWORD;
    /* Enable Memory Address increase*/
    dmaConfig.memoryInc = DMA_MEMORY_INC_DISABLE;
    /* Disable Peripheral Address increase*/
    dmaConfig.peripheralInc = DMA_PERIPHERAL_INC_DISABLE;
    /* Reset Circular Mode*/
    dmaConfig.loopMode = DMA_MODE_CIRCULAR;
    /* set priority*/
    dmaConfig.priority = DMA_PRIORITY_HIGH;
    /* read from peripheral*/
    dmaConfig.dir = DMA_DIR_PERIPHERALTOMEMORY;
    /* Set memory Address*/
    dmaConfig.memoryBaseAddr = (uint32_t)Buf;
    /* Set Peripheral Address*/
    dmaConfig.peripheralBaseAddr = (uint32_t)&ADC1->REGDATA;

    dmaConfig.channel = DMA_CHANNEL_0;
    dmaConfig.fifoMode = DMA_FIFOMODE_DISABLE;
    dmaConfig.fifoThreshold = DMA_FIFOTHRESHOLD_FULL;
    dmaConfig.peripheralBurst = DMA_PERIPHERALBURST_SINGLE;
    dmaConfig.memoryBurst = DMA_MEMORYBURST_SINGLE;

    DMA_Config(DMA2_Stream0, &dmaConfig);
    /* Clear DMA TF flag*/
    DMA_ClearIntFlag(DMA2_Stream0, DMA_INT_TCIFLG0);
    /* Enable DMA Interrupt*/
    DMA_EnableInterrupt(DMA2_Stream0, DMA_INT_TCIFLG);
    DMA_Enable(DMA2_Stream0);
}

Then in the main loop, we just need to determine whether DMA has data, and if so, execute the serial port printing function:

while (1)
    {
        if (DMA_ReadStatusFlag(DMA2_Stream0, DMA_FLAG_TCIFLG0))
        {
            DataBuf = DMA_ConvertedValue;
            VSensorValue = (float)DataBuf/4095*3.3;

            /*!
             * According to actual test data of multiple bathes of chips, 
             * V28 is adopted instead of V25 for this example. And 0.7782v is the voltage for 28
             */
            TSensorValue = (VSensorValue - 0.7782f)/0.0024f + 28;

            printf("\r\n");
            printf("ADC REGDATA = 0x%04X \r\n", DataBuf);
            printf("Volatage    = %f V \r\n", VSensorValue);
            printf("Temperature    = %f  \r\n", TSensorValue);

            Delay(0xFFFFFF);
            DMA_ClearStatusFlag(DMA2_Stream0, DMA_FLAG_TCIFLG0);
        }
    }
}

The following are the results of the operation. Since there is no serial port line, we can only observe it by setting a breakpoint.

This post is from Domestic Chip Exchange

Latest reply

Thank you for the answer, thank you very much!   Details Published on 2023-6-1 22:26
Personal signaturehttp://shop34182318.taobao.com/
https://shop436095304.taobao.com/?spm=a230r.7195193.1997079397.37.69fe60dfT705yr
 
 

6748

Posts

2

Resources
2
 

The internal temperature sensor should be fairly accurate, right?

This post is from Domestic Chip Exchange

Comments

It's OK. It's about 10 degrees when it's powered on. It's about 20 degrees after running.  Details Published on 2023-5-31 09:26
 
 
 

1w

Posts

16

Resources
3
 
wangerxian posted on 2023-5-31 09:11 The internal temperature sensor should be quite accurate, right?

It's OK. It's about 10 degrees when it's powered on. It's about 20 degrees after running.

This post is from Domestic Chip Exchange

Comments

It's only about 10 degrees when powered on? Isn't this detection equal to the ambient temperature?  Details Published on 2023-5-31 09:51
Personal signaturehttp://shop34182318.taobao.com/
https://shop436095304.taobao.com/?spm=a230r.7195193.1997079397.37.69fe60dfT705yr
 
 
 

6748

Posts

2

Resources
4
 
ddllxxrr posted on 2023-5-31 09:26 It's OK, about 10 degrees when it was just powered on, and about 20 degrees after running

It's only about 10 degrees when powered on? Isn't this detection equal to the ambient temperature?

This post is from Domestic Chip Exchange

Comments

Wait until night to have a good look, it should be the chip temperature  Details Published on 2023-5-31 12:46
 
 
 

1w

Posts

16

Resources
5
 
wangerxian posted on 2023-5-31 09:51 It's only about 10 degrees when powered on? This detection is not equal to the ambient temperature?

Wait until night to have a good look, it should be the chip temperature

This post is from Domestic Chip Exchange
Personal signaturehttp://shop34182318.taobao.com/
https://shop436095304.taobao.com/?spm=a230r.7195193.1997079397.37.69fe60dfT705yr
 
 
 

6829

Posts

11

Resources
6
 
Is the temperature difference big compared to the ambient temperature? Can it be used for daily use?
This post is from Domestic Chip Exchange

Comments

It seems that it is not possible. It is very easy to measure the external temperature using NTC, which is a thermistor. The on-chip temperature can only measure the temperature inside the chassis.  Details Published on 2023-6-1 20:29
 
 
 

1w

Posts

16

Resources
7
 
lugl4313820 posted on 2023-6-1 07:49 Is the temperature difference big compared to the ambient temperature? Can it be used for daily temperature measurement?

It seems that it is not possible. It is very easy to measure the external temperature using NTC, which is a thermistor. The on-chip temperature can only measure the temperature inside the chassis.

This post is from Domestic Chip Exchange

Comments

Thank you for the answer, thank you very much!  Details Published on 2023-6-1 22:26
Personal signaturehttp://shop34182318.taobao.com/
https://shop436095304.taobao.com/?spm=a230r.7195193.1997079397.37.69fe60dfT705yr
 
 
 

6829

Posts

11

Resources
8
 
ddllxxrr posted on 2023-6-1 20:29 It seems that it is not possible. It is very easy to measure the external temperature using NTC, which is a thermistor. The on-chip temperature can only measure the temperature inside the chassis

Thank you for the answer, thank you very much!

This post is from Domestic Chip Exchange
 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list