STM32 上移植 FreeModbus RTU

2020-02-29 10:44发布

解压 freemodbus v1.6 源码 看到如下文件目录结构  
708085e57a1496ee2b.png



友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
20条回答
stm32jy
2020-03-01 11:12
打开 portserial.c 文件,这个是移植串口的,不管是 ASCII 模式还是 RTU 模式都需
要串口支持的, void vMBPortSerialEnable( BOOL xRxEnable, BOOL xTxEnable )函数,使能
或失能串口的,移植代码如下
  1. void
  2. vMBPortSerialEnable( BOOL xRxEnable, BOOL xTxEnable )
  3. {
  4. /* If xRXEnable enable serial receive interrupts. If xTxENable enable* transmitter empty interrupts.
  5. */
  6. if (xRxEnable) //接收使能
  7. {
  8. USART_ITConfig(USART2, USART_IT_RXNE, ENABLE); //使能接收中断
  9. GPIO_ResetBits(GPIOG, GPIO_Pin_8); //设置 RS485 接收
  10. }
  11. else //失能
  12. {
  13. USART_ITConfig(USART2, USART_IT_RXNE, DISABLE); //失能接收中断
  14. GPIO_SetBits(GPIOG, GPIO_Pin_8); //设置 RS485 发送
  15. }
  16. if (xTxEnable) //发送使能
  17. {
  18. USART_ITConfig(USART2, USART_IT_TC, ENABLE); //使能
  19. GPIO_SetBits(GPIOG, GPIO_Pin_8); //设置 RS485 发送
  20. }
  21. else //失能
  22. {
  23. USART_ITConfig(USART2, USART_IT_TC, DISABLE); //失能
  24. GPIO_ResetBits(GPIOG, GPIO_Pin_8); //设置 RS485 接收
  25. }
  26. }
复制代码

一周热门 更多>