STM32 internal temperature sensor experiment - serial port delphi host computer

Publisher:RadiantRiverLatest update time:2016-08-21 Source: eefocusKeywords:STM32 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
The temperature at home is 15 degrees. I blew hard at the chip and raised it to 20 degrees.

  STM32 internal temperature sensor experiment - serial port delphi host computer - liuyunqian@yeah - Embedded Learning

Key code of the lower computer 
int main(void)
{
double v,temp,Value;

/* System clocks configuration ---------------------------------------------*/
RCC_Configuration();

/* GPIO configuration ------------------------------------------------------*/
GPIO_Configuration();

/* USARTx configured as follow:
- BaudRate = 9600 baud  
- Word Length = 8 Bits
- One Stop Bit
- No parity
- Hardware flow control disabled (RTS and CTS signals)
- Receive and transmit enabled
*/
USART_InitStructure.USART_BaudRate = 9600;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;

USART_Init(USART1, &USART_InitStructure);
/* Enable USART1 */
USART_Cmd(USART1, ENABLE);

/* DMA1 channel1 configuration --------------------------------------------------*/
DMA_DeInit(DMA1_Channel1);
DMA_InitStructure.DMA_PeripheralBaseAddr = ADC1_DR_Address;
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&ADCConvertedValue;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
DMA_InitStructure.DMA_Buffer Size = 1;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Disable;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
DMA_InitStructure.DMA_Priority = DMA_Priority_High;
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
DMA_Init(DMA1_Channel1, &DMA_InitStructure);

/* Enable DMA1 channel 1 */
DMA_Cmd(DMA1_Channel1, ENABLE );

/* ADC1 configuration ------------------------------------------------------*/
ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
ADC_InitStructure.ADC_ScanConvMode = ENABLE;
ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStructure.ADC_NbrOfChannel = 1;
ADC_Init(ADC1, &ADC_InitStructure);

/* ADC1 regular channel 14 configuration */ 
//################changed to Channel 10 (potentiometer)###### internal temperature sensor changed to Channel 16 ####################
ADC_RegularChannelConfig(ADC1, ADC_Channel_16, 1, ADC_SampleTime_55Cycles5);
//内部温度传感器  添加这一句 
/* Enable the temperature sensor and vref internal channel */
ADC_TempSensorVrefintCmd(ENABLE);

/* Enable ADC1 DMA */
ADC_DMACmd(ADC1, ENABLE);

/* Enable ADC1 */
ADC_Cmd(ADC1, ENABLE);

/* Enable ADC1 reset calibaration register */   //使用之前一定要校准
ADC_ResetCalibration(ADC1);
/* Check the end of ADC1 reset calibration register */
while(ADC_GetResetCalibrationStatus(ADC1));

/* Start ADC1 calibaration */
ADC_StartCalibration(ADC1);
/* Check the end of ADC1 calibration */
while(ADC_GetCalibrationStatus(ADC1));

/* Start ADC1 Software Conversion */ 
ADC_SoftwareStartConvCmd(ADC1, ENABLE);

while (1)
{


//printf("The ADC1 Converted Value is %d \r\n",ADCConvertedValue);
//v=    ADCConvertedValue*3.30/4096;
//printf("The Voltage is %f \r\n",v );


Value=ADC_Filter();
//printf("The ADC_Filter Value is %d \r\n",(int)Value);

temp=(1.42 - Value*3.3/4096)*1000/4.35 + 25;
//printf("The Temperature is %f \r\n",temp );
printf("%s%c%c%c%c%c%s","#**",(int)Value/256,(int)Value%256,'&',(int)((temp-(int)temp)*100),(int)temp,"**%");

for(v=0;v<5000;v++);for(v=0;v<5000;v++);for(v=0;v<5000;v++);
}
}
-------------------------------------------------------------------
上位机关键代码
procedure TMainForm.Comm1ReceiveData(Sender: TObject; Buffer: Pointer;
BufferLength: Word);
var
//iq  :Integer;
p  :Pchar;

begin
viewstring:=' ';

move(buffer^,pchar(@rbuf)^,bufferlength);


p := StrPos(pchar(@rbuf), '#**');




//if (p <> nil) and   (p[9]='*') and ( p[10]='*') and (p[11]='%') then  //
if (p <> nil) and (p[5]='&') and  (p[8]='*') and ( p[9]='*') and (p[10]='%') then
begin


{
printf("%s%c%c%c%c%c%s",
"#**",
(int)Value/256,(int)Value%256,
'&',
(int)((temp-(int)temp)*100),(int)temp,
"**%");
}

Value     :=Ord(p[3])*256 + Ord(p[4])  ; //Ord()  字符-->ASCII码

//Temp:=   Float( Ord(p[7]) ) +Float( Ord(p[6]) ) /Float(100.0) ;
Temp:=(1.42 - (Value)*3.3/4096)*1000/4.35 + 25;

viewstring:='The ADC_Filter Value is:';
viewstring:=viewstring+IntToStr(Value);
viewstring:=viewstring+'   '+'The Temperature is:';
viewstring:=viewstring+FloatToStr(Temp);

memo1.lines.add(viewstring);
memo1.lines.add(' ');

RzLEDDisplay.Caption := inttostr(Value)+' ';
Temp:=int(Temp*1000)/1000;
RzLEDDisplay1.Caption := floattostr(Temp);

end;
end;
Keywords:STM32 Reference address:STM32 internal temperature sensor experiment - serial port delphi host computer

Previous article:STM32 Product Unique Identification Register (96 bits) Flash Capacity Register
Next article:STM32 internal temperature sensor

Recommended ReadingLatest update time:2024-11-16 13:56

List of DMA1 channels of stm32, related operations of stm32 using DMA
DMA (Direct Memory Access) is often translated as "direct memory access". DMA applications have been available as early as Intel's 8086 platform. A complete microcontroller usually consists of components such as CPU, memory and peripherals. These components are generally independent in structure and function, and th
[Microcontroller]
List of DMA1 channels of stm32, related operations of stm32 using DMA
The STM32 serial port DMA sends two frames continuously, resulting in partial data overwriting
Problem Description When using the STM32 serial port for DMA transmission (Noraml mode), the transmission function log_printf() is called twice in a task, but the data sent back is not consistent with the expected display on the serial port debugging assistant. Part of the data sent for the first time is overwritten
[Microcontroller]
Solution to STM32 JTAG/SWD disabling causing failure to program
Since STM32 has many pin functions, multiplexing and remapping are often used to facilitate the use of hardware. Here we mainly mention the problem of pin correspondence between SWD and JTAG ports. In order to enable TIM2 to be remapped to PA15 and PB3, TIM2 must be remapped, but this is not enough, because the downlo
[Microcontroller]
STM32 FSMC study notes + supplement (FSMC configuration of LCD)
FSMC stands for "Static Memory Controller". After using the FSMC controller, the FSMC_A provided by the FSMC can be used as the address line, and the FSMC_D provided by the FSMC can be used as the data bus. (1) When the storage data is set to 8 bits, (FSMC_NANDInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidt
[Microcontroller]
STM32 FSMC study notes + supplement (FSMC configuration of LCD)
What does the STM32 series suffix mean?
For example: STM32 F 103 C 8 T 6  The "F" refers to the product type. Now it seems that there is only the general type, namely "F". The "103" refers to the product sub-series, 101 = basic type, 102 = USB basic type, USB 2.0 full-speed device, 103 = enhanced type, 105 or 107 = interconnect type. The "C" refers to the
[Microcontroller]
STM32 custom frequency and duty cycle PWM output method
Figure 1 Figure II PWM is widely used, but different projects have special requirements for the output PWM. To meet these requirements, we need more experiments to verify. Next, we will describe the output method steps of the waveform shown in Figure 1 (Figure 2 is an abnormal waveform). 1. Resources used in this
[Microcontroller]
Simple analysis of STM32 startup file
Simple analysis of STM32 startup file (applicable scope of STM32F10x.s) Timer, model, name in STM32 incomplete manual , all our routines use a startup file called STM32F10x.s, which defines the stack size of STM32 and the names of various interrupts and entry function names, as well as startup-related assembly code.
[Microcontroller]
How to debug STM32 in ram and flash under ulink-Jlink
Keil MDK3.20 debug stm32 method under ULINK 1. Programs run in RAM Key points: (1) Change the download address of the program to the RAM space (2) Before debugging the program, set the SP and PC pointers to the Ram space. Create a new project and select the specific model of STM32. I bought Wanli
[Microcontroller]
How to debug STM32 in ram and flash under ulink-Jlink
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号