On the serial data receiving process

 

First, the roadmap (analog idle timer interrupt)

  Analyzing received after a complete serial data, a flag is set, this flag determines the main loop processing data.

  How to determine a complete data is received:

    No matter what to do serial communication, data is always a one is transmitted, sending the retransmission another one, there is a time interval between the transmission of each piece of data, the serial data when receiving a control

    Variable timer inside accumulate, while the serial interrupt when receiving data on this variable is cleared! If you have the serial port to receive data this variable will never accumulate less than the desired value, if the serial port to receive

    After the data is no longer receive data, variables accumulated to a desired value, and then determines that a complete data received.

 

Second, since each single-chip serial port configuration different wording, only screenshots instructions

 

 

 

 

 

 

 

 

 

 

 

When serial data is received: Usart1ReadCnt ++; Usart1IdleCnt = 0;

 

Analyzing the timer Usart1ReadCnt! = 0 then DESCRIPTION serial data received Usart1IdleCnt ++

If the serial port has received data can not be accumulated into Usart1IdleCnt Usart1IdleTime (This procedure provided 10) Ms

Serial later after receiving a string of data, stop 10Ms not sent over the data, it will perform

Usart1IdleCnt = 0;
Usart1ReadCntCopy = Usart1ReadCnt;
Usart1ReadCnt = 0;
Usart1ReadFlage = 1;

 

 

 

Third, the main loop calls

 

 

 

 

 

 

Note: If the communication time is too short to 10Ms, you can modify the timer interrupt entry time

or

 

 

 

 

 

 

 

 

Fourth, in fact, comes STM32 idle interrupt detection

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Five test

 

 

 

STM32 comes with free serial interrupt judgment is quite timely! So I do not have it! Because I often need to dynamically free time.

 

Note: The above scheme is not the best way, but apply to all devices

 

My idea is
to send data using memory management + DMA

 

Data sent each time into the memory inside through memory management API, the future will look into the previous data is not sent over, if it is reconfigured to send over the next DMA

 

同时开启DMA发送完成中断,DMA发送完成中断里面也要判断内存里面有没有需要发送的数据,有的话就重新配置DMA,

 

 

 

说完发送,再说接收
我的想法是
数组+DMA+串口空闲中断/定时器

 

 

 

串口空闲中断和定时器的作用都是判断接收到一条完整的数据,空闲中断好说,直接在里面写标志就可以。
如果用定时器就是定时器里面获取DMA接收的数据个数(DMA有API可以获取),如果接收的数据个数在一定时间内不再改变,则置位标志,复位DMA.

 


当然如果为了预防处理慢,接收快的问题,加入内存管理。

内存管理+DMA+串口空闲中断

 

Guess you like

Origin www.cnblogs.com/yangfengwu/p/11669373.html