Level control of 485 transceiver control angle of STM32 serial port

Publisher:XiangtanLatest update time:2017-11-07 Source: eefocusKeywords:STM32 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Regarding 485 level control, if the level conversion is performed directly after the transmission interrupt processing, the transmission data will be incomplete. If a certain delay is added and then the level conversion is performed, this problem can be solved, but it is a bit cumbersome. The solution is to enable the transmission completion interrupt: USART_IT_TC (Transmission complete interrupt) can achieve precise control. It should be noted that this interrupt will be generated before a byte is sent, so it is recommended to enable it after the last byte is loaded into the transmission buffer.

void USART1_IRQHandler(void)

{

CPU_INT08U rx_data;

CPU_INT08U tx_data;

    if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET) //Serial port 1 receiving process

    {       

rx_data = (USART_ReceiveData(USART1) & 0xFF);

// Put into channel 1 receive buffer circular queue

if (!COM_CHANNEL_RXByteIn(BSP_RTU_CHANNEL_NO1, rx_data)) 

{

 // Buffer is full, reception failed

}

    }    

    if(USART_GetITStatus(USART1, USART_IT_TXE) != RESET) //Serial port 1 sending process

    {       

if (COM_CHANNEL_TXByteOut(BSP_RTU_CHANNEL_NO1, &tx_data)) 

{

USART_SendData(USART1, tx_data);

  } 

  else 

  {

USART_ITConfig(USART1, USART_IT_TXE, DISABLE); //Disable transmit interrupt


USART_ClearITPendingBit(USART1,USART_IT_TC);

USART_ITConfig(USART1, USART_IT_TC, ENABLE);

}   

    }    


    if(USART_GetITStatus(USART1, USART_IT_TC) != RESET) //Serial port 1 sends and completes processing

    {       

USART_ITConfig(USART1, USART_IT_TC, DISABLE); //Disable transmit interrupt

GPIO_WriteBit(GPIOB, GPIO_Pin_5,Bit_RESET); //RX_ENABLE


    }    


}


Keywords:STM32 Reference address:Level control of 485 transceiver control angle of STM32 serial port

Previous article:STM32 RTC alarm wakes up standby mode
Next article:STM32L151 RTC Summary

Recommended ReadingLatest update time:2024-11-16 22:42

STM32 file system fatfs transplantation notes detailed explanation
1. Introduction to memory and Flash The flash address of stm32 starts at 0x0800 0000 and ends at 0x0800 0000 plus the actual flash size of the chip. The flash size of different chips is different. The RAM start address is 0x2000 0000, and the end address is 0x2000 0000 plus the RAM size of the chip. The RAM of dif
[Microcontroller]
STM32 file system fatfs transplantation notes detailed explanation
STM32 enters low power mode and wakes up (RTC+interrupt)
After confirming the use of the low power consumption function, everyone will certainly look for relevant information through different channels to understand what low power consumption is, what types of low power consumption there are, and the differences between different modes. Finally, there are some program inter
[Microcontroller]
STM32 enters low power mode and wakes up (RTC+interrupt)
A method for STM32 to receive variable-length data using serial port DMA
1.UART initialization function void uart_init(u32 bound){ GPIO_InitTypeDef GPIO_InitStructure; //GPIO port settings USART_InitTypeDef USART_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA,ENABLE); //Enable GPIOA clock RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);
[Microcontroller]
About the problem of STM32 serial port idle interrupt IDEL
1. The idle interrupt is triggered when a byte of high level (idle) appears after receiving data. It does not mean that the idle interrupt will continue. To be precise, it should be a byte after the rising edge (stop bit). If it is always at a low level, the idle interrupt will not be triggered (it will trigger a brea
[Microcontroller]
Simple use of STM32-DAC
Preface: Recently, I have been debugging the DAC function of the STM32L152 chip. This article summarizes the simple use of the STM32L152 chip DAC. Hardware platform: STM32L152 Software platform: keil v5+cubeMX Function library: HAL library How to use DAC accomplish: 1. Initialization of DAC. DAC_HandleType
[Microcontroller]
Detailed explanation of the use of stm32 standard peripheral library
Download the code      The stm32 standard peripheral library is the peripheral driver for the full range of stm32 chips. With it, we can greatly accelerate the development of stm32.     First, download the latest stm32 standard peripheral library from the website of st company. The latest version is v3.5.0 when writi
[Microcontroller]
STM32 Getting Started - Marquee (Based on STM32F103ZET6)
I recently started learning stm32, and I really felt the difference between stm32 and 51, but there is also a connection. I always feel that the biggest difference between 32 and 51 is that before using a peripheral, you need to enable the clock of the peripheral (to reduce power consumption) and related configuration
[Microcontroller]
STM32 Getting Started - Marquee (Based on STM32F103ZET6)
Design of full-color LED display system based on STM32
As a new display device, LED display screen has been widely used in recent years. With the continuous updating of technology, LED display screen is developing towards full color. A LED display screen control system is designed. The system uses the ARMCortex-M3 core chip STM32F103ZET6 as the control center, completes
[Microcontroller]
Design of full-color LED display system based on STM32
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号