2021-09-06 09:13:12 索煒達(dá)電子 771
項(xiàng)目編號(hào):E815
文件大?。?M
源碼說(shuō)明:帶中文注釋
開(kāi)發(fā)環(huán)境:C編譯器
簡(jiǎn)要概述:
MODBUS RTU,是現(xiàn)在工控行業(yè)非常重要的一個(gè)現(xiàn)場(chǎng)應(yīng)用協(xié)議。相信做工控現(xiàn)場(chǎng)的師兄都知道。我也因需要,做了個(gè)從站,方便大家使用。
經(jīng)自己3個(gè)星期的努力,終于把MODBUS RTU在STM32F407控制器上成功實(shí)現(xiàn)了,每句話(huà)都加注了詳細(xì)的說(shuō)明。
有需要的小伙伴可以選用
截圖如下
主機(jī)配置如下
1 modbus poll主機(jī)不斷給從機(jī)1發(fā)送03讀寄存器命令:
Tx:066-01 03 00 00 00 0A C5 CD
Modbus RTU 03碼解析
MODBUS應(yīng)答
示例-03碼.主機(jī)Modbus poll軟件命令如下
主站發(fā)出/命令:讀地址006B(十進(jìn)制107)開(kāi)始的0003(3)個(gè)寄存器地址。
從站返回/應(yīng)答:03碼,返回06(十進(jìn)制6)個(gè)字節(jié)寄存器,022B(555),0000(0),0064(100)
STM32F407從機(jī)回答如下
Tx:066-01 03 00 00 00 0A C5 CD
命令解析:讀1號(hào)(01)從站寄存器(03),從00(00 00)開(kāi)始,共10(00 0A)個(gè)寄存器。
Rx:067-01 03 14 05 4B 03 EA 08 FF 20 0C 05 4B 03 EA 08 FF 2D 00 2D 00 2D 00 EC 08
應(yīng)答解析:01:地址;03:功能碼;14:字節(jié)數(shù)量10個(gè)(2進(jìn)制14=10進(jìn)制20)
05 4B :2進(jìn)制054B=10進(jìn)制1355; 03 EA :1002; 08 FF:2303; 20 0C:8204; 05 4B:1355;
03 EA :1002; 08 FF :2303; 2D 00:115200; 2D 00 :115200;2D 00:115200;
EC 08 :校驗(yàn)碼-5112
目錄│文件列表:
├ MODBUS協(xié)議報(bào)文解析
│ │ commdata.txt
│ │ MODBUS協(xié)議(功能碼及報(bào)文解析).pdf
│ └ Modbus通訊說(shuō)明.txt
├ Modbus通訊
│ └ Modbus通訊
│ │ keilkilll.bat
│ │ readme.txt
│ ├ CORE
│ │ │ core_cm4.h
│ │ │ core_cm4_simd.h
│ │ │ core_cmFunc.h
│ │ │ core_cmInstr.h
│ │ └ startup_stm32f40_41xxx.s
│ ├ FWLIB
│ │ ├ inc
│ │ │ │ misc.h
│ │ │ │ stm32f4xx_adc.h
│ │ │ │ stm32f4xx_can.h
│ │ │ │ stm32f4xx_crc.h
│ │ │ │ stm32f4xx_cryp.h
│ │ │ │ stm32f4xx_dac.h
│ │ │ │ stm32f4xx_dbgmcu.h
│ │ │ │ stm32f4xx_dcmi.h
│ │ │ │ stm32f4xx_dma.h
│ │ │ │ stm32f4xx_dma2d.h
│ │ │ │ stm32f4xx_exti.h
│ │ │ │ stm32f4xx_flash.h
│ │ │ │ stm32f4xx_flash_ramfunc.h
│ │ │ │ stm32f4xx_fmc.h
│ │ │ │ stm32f4xx_fsmc.h
│ │ │ │ stm32f4xx_gpio.h
│ │ │ │ stm32f4xx_hash.h
│ │ │ │ stm32f4xx_i2c.h
│ │ │ │ stm32f4xx_iwdg.h
│ │ │ │ stm32f4xx_ltdc.h
│ │ │ │ stm32f4xx_pwr.h
│ │ │ │ stm32f4xx_rcc.h
│ │ │ │ stm32f4xx_rng.h
│ │ │ │ stm32f4xx_rtc.h
│ │ │ │ stm32f4xx_sai.h
│ │ │ │ stm32f4xx_sdio.h
│ │ │ │ stm32f4xx_spi.h
│ │ │ │ stm32f4xx_syscfg.h
│ │ │ │ stm32f4xx_tim.h
│ │ │ │ stm32f4xx_usart.h
│ │ │ └ stm32f4xx_wwdg.h
│ │ └ src
│ │ │ misc.c
│ │ │ stm32f4xx_adc.c
│ │ │ stm32f4xx_can.c
│ │ │ stm32f4xx_crc.c
│ │ │ stm32f4xx_cryp.c
│ │ │ stm32f4xx_cryp_aes.c
│ │ │ stm32f4xx_cryp_des.c
│ │ │ stm32f4xx_cryp_tdes.c
│ │ │ stm32f4xx_dac.c
│ │ │ stm32f4xx_dbgmcu.c
│ │ │ stm32f4xx_dcmi.c
│ │ │ stm32f4xx_dma.c
│ │ │ stm32f4xx_dma2d.c
│ │ │ stm32f4xx_exti.c
│ │ │ stm32f4xx_flash.c
│ │ │ stm32f4xx_flash_ramfunc.c
│ │ │ stm32f4xx_fmc.c
│ │ │ stm32f4xx_fsmc.c
│ │ │ stm32f4xx_gpio.c
│ │ │ stm32f4xx_hash.c
│ │ │ stm32f4xx_hash_md5.c
│ │ │ stm32f4xx_hash_sha1.c
│ │ │ stm32f4xx_i2c.c
│ │ │ stm32f4xx_iwdg.c
│ │ │ stm32f4xx_ltdc.c
│ │ │ stm32f4xx_pwr.c
│ │ │ stm32f4xx_rcc.c
│ │ │ stm32f4xx_rng.c
│ │ │ stm32f4xx_rtc.c
│ │ │ stm32f4xx_sai.c
│ │ │ stm32f4xx_sdio.c
│ │ │ stm32f4xx_spi.c
│ │ │ stm32f4xx_syscfg.c
│ │ │ stm32f4xx_tim.c
│ │ │ stm32f4xx_usart.c
│ │ └ stm32f4xx_wwdg.c
│ ├ HARDWARE
│ │ ├ KEY
│ │ │ │ key.c
│ │ │ └ key.h
│ │ ├ LED
│ │ │ │ led.c
│ │ │ └ led.h
│ │ └ modbus
│ │ │ modbus.c
│ │ └ modbus.h
│ ├ OBJ
│ │ └ Template.hex
│ ├ README
│ │ └ README.txt
│ ├ SYSTEM
│ │ ├ delay
│ │ │ │ delay.c
│ │ │ └ delay.h
│ │ ├ sys
│ │ │ │ sys.c
│ │ │ └ sys.h
│ │ └ usart
│ │ │ usart.c
│ │ └ usart.h
│ └ USER
│ │ JLinkSettings.ini
│ │ main.c
│ │ modbus.uvguix.Administrator
│ │ modbus.uvoptx
│ │ modbus.uvprojx
│ │ stm32f4xx.h
│ │ stm32f4xx_conf.h
│ │ stm32f4xx_it.c
│ │ stm32f4xx_it.h
│ │ system_stm32f4xx.c
│ │ system_stm32f4xx.h
│ │ Template.uvguix.Administrator
│ └ Template.uvoptx
├ Modbus通訊改1圖片
│ └ Modbus通訊改1圖片
│ │ 06碼下寫(xiě)正確.png
│ │ 微信截圖_20200509093959.png
│ │ 微信截圖_20200509094219.png
│ │ 微信截圖_20200509100030.png
│ │ 微信截圖_20200509100043.png
│ │ 通信1.png
│ │ 通信2.png
│ │ 通信說(shuō)明.docx
│ │ 配置.png
│ │ 配置2.png
│ │ 默認(rèn)通信1.txt
│ └ 默認(rèn)通信2.png
└ Modbus通訊改2
└ Modbus通訊改2
│ keilkilll.bat
│ readme.txt
├ CORE
│ │ core_cm4.h
│ │ core_cm4_simd.h
│ │ core_cmFunc.h
│ │ core_cmInstr.h
│ └ startup_stm32f40_41xxx.s
├ FWLIB
│ ├ inc
│ │ │ misc.h
│ │ │ stm32f4xx_adc.h
│ │ │ stm32f4xx_can.h
│ │ │ stm32f4xx_crc.h
│ │ │ stm32f4xx_cryp.h
│ │ │ stm32f4xx_dac.h
│ │ │ stm32f4xx_dbgmcu.h
│ │ │ stm32f4xx_dcmi.h
│ │ │ stm32f4xx_dma.h
│ │ │ stm32f4xx_dma2d.h
│ │ │ stm32f4xx_exti.h
│ │ │ stm32f4xx_flash.h
│ │ │ stm32f4xx_flash_ramfunc.h
│ │ │ stm32f4xx_fmc.h
│ │ │ stm32f4xx_fsmc.h
│ │ │ stm32f4xx_gpio.h
│ │ │ stm32f4xx_hash.h
│ │ │ stm32f4xx_i2c.h
│ │ │ stm32f4xx_iwdg.h
│ │ │ stm32f4xx_ltdc.h
│ │ │ stm32f4xx_pwr.h
│ │ │ stm32f4xx_rcc.h
│ │ │ stm32f4xx_rng.h
│ │ │ stm32f4xx_rtc.h
│ │ │ stm32f4xx_sai.h
│ │ │ stm32f4xx_sdio.h
│ │ │ stm32f4xx_spi.h
│ │ │ stm32f4xx_syscfg.h
│ │ │ stm32f4xx_tim.h
│ │ │ stm32f4xx_usart.h
│ │ └ stm32f4xx_wwdg.h
│ └ src
│ │ misc.c
│ │ stm32f4xx_adc.c
│ │ stm32f4xx_can.c
│ │ stm32f4xx_crc.c
│ │ stm32f4xx_cryp.c
│ │ stm32f4xx_cryp_aes.c
│ │ stm32f4xx_cryp_des.c
│ │ stm32f4xx_cryp_tdes.c
│ │ stm32f4xx_dac.c
│ │ stm32f4xx_dbgmcu.c
│ │ stm32f4xx_dcmi.c
│ │ stm32f4xx_dma.c
│ │ stm32f4xx_dma2d.c
│ │ stm32f4xx_exti.c
│ │ stm32f4xx_flash.c
│ │ stm32f4xx_flash_ramfunc.c
│ │ stm32f4xx_fmc.c
│ │ stm32f4xx_fsmc.c
│ │ stm32f4xx_gpio.c
│ │ stm32f4xx_hash.c
│ │ stm32f4xx_hash_md5.c
│ │ stm32f4xx_hash_sha1.c
│ │ stm32f4xx_i2c.c
│ │ stm32f4xx_iwdg.c
│ │ stm32f4xx_ltdc.c
│ │ stm32f4xx_pwr.c
│ │ stm32f4xx_rcc.c
│ │ stm32f4xx_rng.c
│ │ stm32f4xx_rtc.c
│ │ stm32f4xx_sai.c
│ │ stm32f4xx_sdio.c
│ │ stm32f4xx_spi.c
│ │ stm32f4xx_syscfg.c
│ │ stm32f4xx_tim.c
│ │ stm32f4xx_usart.c
│ └ stm32f4xx_wwdg.c
├ HARDWARE
│ ├ KEY
│ │ │ key.c
│ │ └ key.h
│ ├ LED
│ │ │ led.c
│ │ └ led.h
│ ├ modbus
│ │ │ modbus.c
│ │ └ modbus.h
│ └ OLED
│ │ bmp.h
│ │ oled.c
│ │ oled.h
│ └ oledfont.h
├ OBJ
│ └ Template.hex
├ README
│ └ README.txt
├ SYSTEM
│ ├ delay
│ │ │ delay.c
│ │ └ delay.h
│ ├ sys
│ │ │ sys.c
│ │ └ sys.h
│ └ usart
│ │ usart.c
│ └ usart.h
└ USER
│ JLinkSettings.ini
│ main.c
│ modbus.uvguix.Administrator
│ modbus.uvoptx
│ modbus.uvprojx
│ stm32f4xx.h
│ stm32f4xx_conf.h
│ stm32f4xx_it.c
│ stm32f4xx_it.h
│ system_stm32f4xx.c
│ system_stm32f4xx.h
│ Template.uvguix.Administrator
│ Template.uvoptx
└ DebugConfig
└ Modbus_STM32F407ZG.dbgconf