標(biāo)題:
stm32的modbus協(xié)議測(cè)試源碼
[打印本頁(yè)]
作者:
xsff
時(shí)間:
2018-4-30 11:31
標(biāo)題:
stm32的modbus協(xié)議測(cè)試源碼
stm32 的modbus協(xié)議測(cè)試源程序如下:
/**
******************************************************************************
* @文件 :MODBUS RTU通信協(xié)議
* @作者 :藍(lán)照電子科技
* @版本 :LZKJ_V2.0
* @概要 : 通信口USART1(PA9\PA10) 9600,8,0,1
******************************************************************************
*/
/* 頭文件 --------------------------------------------------------------*/
#include <stdio.h>
#include "stm32f10x.h"
#include "mb.h"
/* 私有數(shù)據(jù)類型 --------------------------------------------------------------*/
/* 私有定義 --------------------------------------------------------------*/
/* 私有宏定義 --------------------------------------------------------------*/
#ifdef __GNUC__
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif /* __GNUC__ */
/* 私有變量 --------------------------------------------------------------*/
/* 私有函數(shù)聲明 --------------------------------------------------------------*/
void LED_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC,&GPIO_InitStructure);
}
/**
* @brief Configure the nested vectored interrupt controller.
* @param None
* @retval : None
*/
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
/* Enable the TIM2 gloabal Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/* Enable the TIM2 gloabal Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
/**
* @功能
* @參數(shù)
* @返回值
*/
int main(void)
{
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
NVIC_Configuration();
LED_Config();
/*模式 從機(jī)地址 端口 波特率 校驗(yàn)位*/
eMBInit( MB_RTU, 0x01, 0, 9600, MB_PAR_NONE );
/* Enable the Modbus Protocol Stack. */
eMBEnable( );
for( ;; )
{
( void )eMBPoll( );
/* Here we simply count the number of poll cycles. */
//usRegInputBuf[0]++;
}
}
/**
* @brief Retargets the C library printf function to the USART.
* @param None
* @retval None
*/
PUTCHAR_PROTOTYPE
{
/* Place your implementation of fputc here */
/* Loop until the end of transmission */
while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET)
{}
/* e.g. write a character to the USART */
USART_SendData(USART1, (uint8_t) ch);
return ch;
}
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t* file, uint32_t line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* Infinite loop */
while (1)
{
}
}
#endif
/**
* @}
*/
/*******************************文件結(jié)尾**************************************/
……………………
…………限于本文篇幅 余下代碼請(qǐng)從51黑下載附件…………
復(fù)制代碼
所有資料51hei提供下載:
STM32-MODBUS標(biāo)準(zhǔn)通信協(xié)議測(cè)試_MY.rar
(321.61 KB, 下載次數(shù): 225)
2018-4-30 15:09 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
作者:
lmwife
時(shí)間:
2018-9-26 09:48
請(qǐng)問(wèn),這個(gè)用的是什么芯片?
作者:
hesan921
時(shí)間:
2018-10-14 19:54
I like it. Thanks
作者:
13456140382
時(shí)間:
2018-11-3 21:54
感謝分享
作者:
rex236
時(shí)間:
2018-11-9 08:46
感謝分享有價(jià)值的東西,正需要,可惜沒有黑幣,誰(shuí)可以發(fā)下我的郵箱嗎?
作者:
assouan
時(shí)間:
2018-11-28 14:00
學(xué)習(xí)下看看
作者:
YZM168
時(shí)間:
2018-12-26 14:53
主站還是從站呢?
作者:
hengihao
時(shí)間:
2019-1-6 18:56
一起學(xué)習(xí)單片機(jī)
作者:
honglang2222
時(shí)間:
2019-2-20 09:50
謝謝!。。。。。!
作者:
計(jì)量王工
時(shí)間:
2019-2-23 14:56
謝謝樓主分享。有點(diǎn)不明白,自由從機(jī)程序就可以通訊了吧,那還要主機(jī)程序干嘛
作者:
xo37
時(shí)間:
2019-2-24 07:04
lmwife 發(fā)表于 2018-9-26 09:48
請(qǐng)問(wèn),這個(gè)用的是什么芯片?
看引腳定義STM32F103系列均可
作者:
koethen
時(shí)間:
2019-2-28 08:12
非常棒!正準(zhǔn)備學(xué)習(xí)!
作者:
pm1981
時(shí)間:
2019-2-28 09:36
有點(diǎn)看不明白
作者:
huyangzxh
時(shí)間:
2019-4-12 14:50
感謝分享
作者:
irisice008
時(shí)間:
2019-5-17 22:24
感謝分享
作者:
heabin
時(shí)間:
2019-5-20 21:31
感謝分享
作者:
lx5831
時(shí)間:
2019-11-18 08:00
感謝分享
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1