2021-09-06 09:13:12 索煒達電子 777
項目編號:E815
文件大?。?M
源碼說明:帶中文注釋
開發(fā)環(huán)境:C編譯器
簡要概述:
MODBUS RTU,是現(xiàn)在工控行業(yè)非常重要的一個現(xiàn)場應用協(xié)議。相信做工控現(xiàn)場的師兄都知道。我也因需要,做了個從站,方便大家使用。
經自己3個星期的努力,終于把MODBUS RTU在STM32F407控制器上成功實現(xiàn)了,每句話都加注了詳細的說明。
有需要的小伙伴可以選用
截圖如下
主機配置如下
1 modbus poll主機不斷給從機1發(fā)送03讀寄存器命令:
Tx:066-01 03 00 00 00 0A C5 CD
Modbus RTU 03碼解析
MODBUS應答
示例-03碼.主機Modbus poll軟件命令如下
主站發(fā)出/命令:讀地址006B(十進制107)開始的0003(3)個寄存器地址。
從站返回/應答:03碼,返回06(十進制6)個字節(jié)寄存器,022B(555),0000(0),0064(100)
STM32F407從機回答如下
Tx:066-01 03 00 00 00 0A C5 CD
命令解析:讀1號(01)從站寄存器(03),從00(00 00)開始,共10(00 0A)個寄存器。
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
應答解析:01:地址;03:功能碼;14:字節(jié)數(shù)量10個(2進制14=10進制20)
05 4B :2進制054B=10進制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 :校驗碼-5112
目錄│文件列表:
├ MODBUS協(xié)議報文解析
│ │ commdata.txt
│ │ MODBUS協(xié)議(功能碼及報文解析).pdf
│ └ Modbus通訊說明.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碼下寫正確.png
│ │ 微信截圖_20200509093959.png
│ │ 微信截圖_20200509094219.png
│ │ 微信截圖_20200509100030.png
│ │ 微信截圖_20200509100043.png
│ │ 通信1.png
│ │ 通信2.png
│ │ 通信說明.docx
│ │ 配置.png
│ │ 配置2.png
│ │ 默認通信1.txt
│ └ 默認通信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