Summary-Debug STM32F103ZET6 and peripheral Sensors _maq400 air quality (odor) Digital Display module

Source: Internet
Author: User
1. Overview

Module model is MAQ400 series, UART output, the use of USART1, power after the need to preheat 60s after the output data is stable. 2. Wiring

The positive (pin 2) is connected to 5V, and the negative (pin 1) is connected to the Gnd,txd STM32 rxd (PA10). 3. Debug Key issues (1) Baud rate 9600, data bit 8 bit, stop bit 1 bit, check bit none. (2) Communication for the active upload of 1s per interval to send a concentration value, command line format: Start bit (0xFF) Start bit (0xFF) address bit (0x01) gas name (0x27) gas concentration high gas concentration low point unit parity bit (3) Example: FF FF 01 1 B-BB, DE
Gas concentration value =0X00*256+0XBB = 187, the decimal point is 2 bits, the actual concentration is 1.87mg/m3

(4) Checksum calculation: (uint8_t) (buff[2] + buff[3] + buff[4] + buff[5] + buff[6] + buff[7])

(5) STM32 Usart during reception, the least significant bit of data is first moved from the Rx foot into the receiving shift register, when the 8-bit data is received, the value of the shift register is assigned to the receiving data register (RDR), the data in the Read data register Usart_ Dr Essence is to read the Usart internal RDR register, when the contents of the shift register is transferred to the RDR after the Rxne is set, at this time if the USART_CR1 register in the Rxneie is 1, then an interrupt, the software read USART_DR register to complete the removal of the rxne bit.

(6) Serial port 1 interrupt processing function, return gas concentration value:

Air quality sensor when uploading data will trigger serial 1 interrupt
void Usart1_irqhandler (void)                	//serial 1 Interrupt Service program
{
	//serial Port received 9-bit data: Start bit (0xFF) Start bit ( 0xFF) address bit (0x01) gas name (0x27) gas concentration high gas concentration low point bit unit check digit
	U8 checksum = 0;//checksum
	if (Usart_getitstatus (USART1, Usart_it_ RXNE) = RESET)  //Receive interrupt (the received data must be 0x0d 0x0a end)
		{
		//(USART1->DR);	Read the received data

				usart_rx_buf_1[i++]  = Usart_receivedata (USART1);//read starting bit 0xFF
			if (i = = 9)
				i = 0;// When the 9th character is received, start writing from the beginning of the array usart_rx_buf_1
			checksum = usart_rx_buf_1[2] + usart_rx_buf_1[3] + usart_rx_buf_1[4] 
								 + USART_RX_BUF_1[5] + usart_rx_buf_1[6] + usart_rx_buf_1[7];//checksum
			if (checksum = = Usart_rx_buf_1[8])//prove that the received data is correct
				Gasdata = (usart_rx_buf_1[4] * + usart_rx_buf_1[5])/POW (usart_rx_buf_1[6]);
				
     } 

(7) Code address 4. Attached: MAQ400 information








Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.