当前位置:网站首页>USART window communication program of stm32

USART window communication program of stm32

2020-12-08 12:33:47 osc_ cd2qhmfp

One 、USART brief introduction

USART Full duplex is a universal synchronization / Asynchronous serial transceiver module , The interface is a highly flexible serial communication device .
The main features :

  1. Full duplex operation ( Receiving and sending data independently of each other );
  2. Synchronous operation , The host clock can be synchronized , The slave clock can also be synchronized ;
  3. Independent high precision baud rate generator , It doesn't take up time / Counter ;
  4. Support 5、6、7、8 and 9 Digit bit ,1 or 2 Serial data frame structure of bit stop bit ;
  5. Hardware supported parity bit generation and verification ;
  6. Data overflow detection ;
  7. Frame error detection ;
  8. Including the error start bit detection noise filter and digital low-pass filter ;
  9. Three completely independent interrupts ,TX Send complete 、TX Send data register empty 、RX Completion of reception ;
  10. Support multi machine communication mode ;
  11. Support double speed asynchronous communication mode .

Structural components :
USART The transceiver module is generally divided into three parts : Clock generator 、 Data transmitters and receivers . Control registers are shared by all modules .
The clock generator consists of synchronous logic circuits ( Driven by external clock input in synchronous slave mode ) And baud rate generator . Send clock pin XCK In synchronous mode only , The transmitter section consists of a separate write buffer ( send out UDR)、 A serial shift register 、 Check bit generator and control logic circuit for processing different frame structures . Using the write buffer , The system can transmit multi frame data continuously without delay .
The receiver is USART The most complex part of the module , The most important is the clock and data receiving unit . The data receiving unit is used for receiving asynchronous data . Except for the receiving unit , The receiver also includes a parity checker 、 Control logic 、 Shift register and two-stage receive buffer ( receive UDR). The receiver supports the same frame structure as the transmitter , At the same time support frame error 、 Detection of data overflow and verification errors .


Two 、USART Icon

 Insert picture description here

3、 ... and 、 Register based and firmware library based stm32 LED Comparison of programming methods of water lamp example :

1、 Based on the characteristics of register development :
(1) The specific parameters are more intuitive ;
(2) It takes less resources to run the program .
But its defects should not be ignored , as follows :
(1) Slow development ;
(2) Program readability is poor ;
(3) Maintenance complexity .
These defects directly affect the development efficiency , Program maintenance costs , Communication costs . Usually , Only when the interrupt service function is called frequently, the way of directly configuring registers is used .
2、 Based on solid-state library development , The function library is called directly , Characteristic is :
(1) It is convenient to communicate with the peripheral devices ;
(2) Error checking is simple ;
(3) For the main controller STM32 Easy to get started .
In general, it's based on registers : Rich information , Easy to understand , Suitable for beginners to learn .
Based on firmware library : Strong portability , Closer to the bottom , Requires a deep understanding of how it works , Suitable for people with rich experience .












Four 、STM32 Of USART Example of serial communication program

  • Open the downloaded official information package , Install wildfire serial debugging assistant
     Insert picture description here

  • Found in the official database USART1 Under the receiving and sending folder keil Engineering documents , Open the project

 Insert picture description here

  • open stm32f10x_it.c The document is modified as follows :

 Insert picture description here

  • open main.c The document is modified as follows :

 Insert picture description here
The modified code is as follows

  • stm32f10x_it.c:
int i=0;
uint8_t ucTemp[50];
void DEBUG_USART_IRQHandler(void)
{
   
   
	if(USART_GetITStatus(DEBUG_USARTx,USART_IT_RXNE)!=RESET)
	{
   
   
		ucTemp[i] = USART_ReceiveData(USART1);	
	}
  if(ucTemp[i] == '!')
	{
   
   
		if(ucTemp[i-1] == '2'&&ucTemp[i-2] == '3'&&ucTemp[i-3] == 'm'&&ucTemp[i-4] == 't'&&ucTemp[i-5] == 's'&&ucTemp[i-6] == ' ')
			if(ucTemp[i-7] == 'p'&&ucTemp[i-8] == 'o'&&ucTemp[i-9] == 't'&&ucTemp[i-10] == 's')
			{
   
   
				printf(" received !");
        while(1);
			}
	}
	i++;
}

  • main.c:
#include "stm32f10x.h"
#include "bsp_usart.h"


void delay(uint32_t count)
{
   
   
	while(count--);
}
int main(void)
{
   
   	
  USART_Config();
  while(1)
	{
   
   	
		printf("hello windows!\n");
		delay(5000000);
	}	
}

  • After compiling and debugging, it shows that there is no error ,

 Insert picture description here

Click on the wand

 Insert picture description here

Enter and choose debug, stay Use Choose J-Link Connect

 Insert picture description here
setting

 Insert picture description here

 Insert picture description here
Everything is ready. , Click on load Burn the program into the chip
Open wildfire's serial debugging assistant
 Insert picture description here
You can see STM32 The system gives the upper computer (win10) Continuous transmission “hello windows!
When the upper computer gives stm32 send out “Stop,stm32” after ,stm32 Stop sending .
Task to complete !





5、 ... and 、 Reference material

stm32 Serial port communication
STM32 Serial port communication USART Learning notes

版权声明
本文为[osc_ cd2qhmfp]所创,转载请带上原文链接,感谢
https://chowdera.com/2020/12/20201208123300481m.html