7616 views|9 replies

862

Posts

2

Resources
The OP
 

[GD32F350] Part 4: ModbusRTU protocol implementation [Copy link]

 
1. Following the previous post, this post implements the modbusRTU client for data communication with the Weilun touch screen. The previous post implemented the functions: sending data using the usart DMA method and using the usart IDLE interrupt to receive indefinite length byte data. This post implements basic MODBUS RTU protocol data parsing, data processing and data return. It implements basic coil read and write, register read and write functions, mainly with function codes 0x01, 0x03, 0x05, 0x06, 0x010. Functional test: After sending data to GD32 using the MODBUS RTU protocol format, the debugging information returned by GD32. Use modscan to continuously read GD32 analog coil data. Here, two bytes of bit status are transmitted, that is, 16 bits, of which the upper 8 bits are 0x33 and the lower 8 bits are 0x66. The animated picture shows the process of establishing a connection and reading data. It can be seen that GD32 and modscan communicate normally. The relevant code will be attached when the work is submitted. 2. Use systick query method to implement delay_us() and delay_ms() The systick clock of GD32 is provided by the 8-division of AHB. Initialization of systick:
  1. void delay_init() { fac_us=rcu_clock_freq_get(CK_AHB)/8000000; //1/8 of AHB clock fac_ms=(u32)rcu_clock_freq_get(CK_AHB)/8000; //represents the number of systick clocks required for each ms SysTick->CTRL&=~SysTick_CTRL_ENABLE_Msk; //Turn off the counter }
复制代码
delay_us() function implementation:
  1. void delay_us(u32 nus) { u32 temp; SysTick->LOAD =(u32)nus*fac_us-1; //Time load SysTick->VAL = 0UL; //Clear the counter SysTick->CTRL = SysTick_CTRL_ENABLE_Msk; do { temp=SysTick->CTRL ; } while(temp&0x01&&!(temp&SysTick_CTRL_COUNTFLAG_Msk));//Wait for time to arrive SysTick->CTRL&=~SysTick_CTRL_ENABLE_Msk; //Turn off counter SysTick->VAL =0X00; //Clear counter }
复制代码
delay_ms() implementation:
  1. void delay_ms(u16 nms) { u32 temp; SysTick->LOAD=(u32)((u32)nms*fac_ms-1);//Time loading (SysTick->LOAD is 24bit) SysTick->VAL =0x00; //Clear counter SysTick->CTRL|=SysTick_CTRL_ENABLE_Msk; do { temp=SysTick->CTRL; } while(temp&0x01&&!(temp&(1<<16)));//Wait for time to arrive SysTick->CTRL&=~SysTick_CTRL_ENABLE_Msk; //Turn off counter SysTick->VAL =0X00; //Clear counter }
复制代码
3. About bitband operation of GD32F350 Bitband operation is used in STM32 to set the gpio output state or read the gpio pin input state. After an afternoon of debugging, I found that the gpio_base address of GD32F350 starts at 0x4800 0000, and the on-chip peripherals of GD32F350 can only be bit-bound from 0x40000000 to 0x40100000, while the base address of GPIO is far beyond 0x40100000, that is, GPIO cannot be bit-bound. The next post is the gd32 timer interrupt setting.

This post is from GD32 MCU

Latest reply

The sixth batch of Baidu Netdisk is indeed gg, I wonder if it will be shared on gitee?   Details Published on 2023-8-24 20:41
Personal signature水不撩不知深浅 人不拼怎知输赢
 

862

Posts

2

Resources
2
 
Use modscan to test the communication. There is also a 10us timer interrupt running continuously. The following is the test picture. It takes more than 5k seconds and the communication is normal. The data has not changed because the 16 bits returned in the GD32 program are two bytes of data written in advance and have not been changed.

This post is from GD32 MCU
 
Personal signature水不撩不知深浅 人不拼怎知输赢
 
 

862

Posts

2

Resources
3
 
usart0 is for MODBUS communication, and USART1 is for printing information through the virtual serial port of the onboard debug.
This post is from GD32 MCU
 
Personal signature水不撩不知深浅 人不拼怎知输赢
 
 

1

Posts

0

Resources
4
 

Does the blogger have the source code?

This post is from GD32 MCU
 
 
 

16

Posts

0

Resources
5
 

Could you please package the information and share it with me? I want to learn from it. Thanks in advance.

This post is from GD32 MCU

Comments

In the last post of this board sharing post, there is a download link   Details Published on 2022-2-27 18:57
 
 
 

862

Posts

2

Resources
6
 
tree0429 posted on 2022-1-28 10:52 Could you please package the information and share it with me? I want to learn from it. Thanks in advance.

In the last post of this board sharing post, there is a download link

This post is from GD32 MCU
 
Personal signature水不撩不知深浅 人不拼怎知输赢
 
 

1

Posts

0

Resources
7
 

The last Baidu network disk link in this board sharing post is invalid, and there is no new link.

This post is from GD32 MCU

Comments

If necessary, I will reorganize and upload it to gitee  Details Published on 2022-6-13 18:23
 
 
 

862

Posts

2

Resources
8
 
32535604 Published on 2022-6-11 00:53 The Baidu network disk link of the last post on this board is invalid, and there is no new link

If necessary, I will reorganize and upload it to gitee

This post is from GD32 MCU
 
Personal signature水不撩不知深浅 人不拼怎知输赢
 
 

2

Posts

0

Resources
9
 

Upload it, I need it too

This post is from GD32 MCU
 
 
 

16

Posts

0

Resources
10
 

The sixth batch of Baidu Netdisk is indeed gg, I wonder if it will be shared on gitee?

This post is from GD32 MCU
 
 
 

Find a datasheet?

EEWorld Datasheet Technical Support

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list