久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 8560|回復: 16
收起左側

stm32的modbus協議測試源碼

  [復制鏈接]
ID:311642 發表于 2018-4-30 11:31 | 顯示全部樓層 |閱讀模式
stm32 的modbus協議測試源程序如下:
  1. /**
  2.   ******************************************************************************
  3.   * @文件   :MODBUS RTU通信協議  
  4.   * @作者   :藍照電子科技
  5.   * @版本   :LZKJ_V2.0
  6.   * @概要   : 通信口USART1(PA9\PA10)  9600,8,0,1
  7.   ******************************************************************************
  8.   */  

  9. /* 頭文件                --------------------------------------------------------------*/
  10. #include <stdio.h>
  11. #include "stm32f10x.h"
  12. #include "mb.h"

  13. /* 私有數據類型 --------------------------------------------------------------*/
  14. /* 私有定義         --------------------------------------------------------------*/
  15. /* 私有宏定義         --------------------------------------------------------------*/
  16. #ifdef __GNUC__
  17. #define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
  18. #else
  19. #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
  20. #endif /* __GNUC__ */
  21. /* 私有變量         --------------------------------------------------------------*/
  22. /* 私有函數聲明 --------------------------------------------------------------*/
  23. void LED_Config(void)
  24. {
  25.         GPIO_InitTypeDef GPIO_InitStructure;
  26.         RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
  27.         GPIO_InitStructure.GPIO_Pin          = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5;
  28.         GPIO_InitStructure.GPIO_Mode         = GPIO_Mode_Out_PP;
  29.         GPIO_InitStructure.GPIO_Speed         = GPIO_Speed_50MHz;
  30.         GPIO_Init(GPIOC,&GPIO_InitStructure);
  31. }


  32. /**
  33.   * @brief  Configure the nested vectored interrupt controller.
  34.   * @param  None
  35.   * @retval : None
  36.   */
  37. void NVIC_Configuration(void)
  38. {
  39.   NVIC_InitTypeDef NVIC_InitStructure;

  40.   /* Enable the TIM2 gloabal Interrupt */
  41.   NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;
  42.   NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  43.   NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
  44.   NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

  45.   NVIC_Init(&NVIC_InitStructure);

  46.   /* Enable the TIM2 gloabal Interrupt */
  47.   NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
  48.   NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  49.   NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
  50.   NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

  51.   NVIC_Init(&NVIC_InitStructure);
  52. }

  53. /**
  54.   * @功能
  55.   * @參數
  56.   * @返回值
  57.   */
  58. int main(void)
  59. {
  60.         NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
  61.         NVIC_Configuration();
  62.         LED_Config();
  63.        
  64.         /*模式         從機地址 端口 波特率 校驗位*/
  65.         eMBInit( MB_RTU, 0x01, 0, 9600, MB_PAR_NONE );
  66.        
  67.         /* Enable the Modbus Protocol Stack. */
  68.         eMBEnable(  );
  69.        
  70.         for( ;; )
  71.         {
  72.          ( void )eMBPoll(  );
  73.          /* Here we simply count the number of poll cycles. */
  74.          //usRegInputBuf[0]++;
  75.         }
  76. }

  77. /**
  78.   * @brief  Retargets the C library printf function to the USART.
  79.   * @param  None
  80.   * @retval None
  81.   */
  82. PUTCHAR_PROTOTYPE
  83. {
  84.   /* Place your implementation of fputc here */

  85.   /* Loop until the end of transmission */
  86.   while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET)
  87.   {}
  88.   /* e.g. write a character to the USART */
  89.   USART_SendData(USART1, (uint8_t) ch);       

  90.   return ch;
  91. }

  92. #ifdef  USE_FULL_ASSERT

  93. /**
  94.   * @brief  Reports the name of the source file and the source line number
  95.   *         where the assert_param error has occurred.
  96.   * @param  file: pointer to the source file name
  97.   * @param  line: assert_param error line source number
  98.   * @retval None
  99.   */
  100. void assert_failed(uint8_t* file, uint32_t line)
  101. {
  102.   /* User can add his own implementation to report the file name and line number,
  103.      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */

  104.   /* Infinite loop */
  105.   while (1)
  106.   {
  107.   }
  108. }
  109. #endif
  110. /**
  111.   * @}
  112.   */


  113. /*******************************文件結尾**************************************/


  114. ……………………

  115. …………限于本文篇幅 余下代碼請從51黑下載附件…………
復制代碼

所有資料51hei提供下載:
STM32-MODBUS標準通信協議測試_MY.rar (321.61 KB, 下載次數: 225)

評分

參與人數 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎勵!

查看全部評分

回復

使用道具 舉報

ID:389528 發表于 2018-9-26 09:48 | 顯示全部樓層
請問,這個用的是什么芯片?
回復

使用道具 舉報

ID:409584 發表于 2018-10-14 19:54 | 顯示全部樓層
I like it. Thanks
回復

使用道具 舉報

ID:281916 發表于 2018-11-3 21:54 | 顯示全部樓層
感謝分享
回復

使用道具 舉報

ID:423388 發表于 2018-11-9 08:46 | 顯示全部樓層
感謝分享有價值的東西,正需要,可惜沒有黑幣,誰可以發下我的郵箱嗎?
回復

使用道具 舉報

ID:434920 發表于 2018-11-28 14:00 | 顯示全部樓層
學習下看看
回復

使用道具 舉報

ID:81365 發表于 2018-12-26 14:53 | 顯示全部樓層
主站還是從站呢?
回復

使用道具 舉報

ID:463235 發表于 2019-1-6 18:56 | 顯示全部樓層
一起學習單片機
回復

使用道具 舉報

ID:478360 發表于 2019-2-20 09:50 | 顯示全部樓層
謝謝!!!!!!!!
回復

使用道具 舉報

ID:471398 發表于 2019-2-23 14:56 | 顯示全部樓層
謝謝樓主分享。有點不明白,自由從機程序就可以通訊了吧,那還要主機程序干嘛
回復

使用道具 舉報

ID:280298 發表于 2019-2-24 07:04 | 顯示全部樓層
lmwife 發表于 2018-9-26 09:48
請問,這個用的是什么芯片?

看引腳定義STM32F103系列均可
回復

使用道具 舉報

ID:479575 發表于 2019-2-28 08:12 | 顯示全部樓層
非常棒!正準備學習!
回復

使用道具 舉報

ID:223999 發表于 2019-2-28 09:36 | 顯示全部樓層
有點看不明白
回復

使用道具 舉報

ID:373064 發表于 2019-4-12 14:50 | 顯示全部樓層

感謝分享
回復

使用道具 舉報

ID:346927 發表于 2019-5-17 22:24 | 顯示全部樓層
感謝分享
回復

使用道具 舉報

ID:460450 發表于 2019-5-20 21:31 | 顯示全部樓層

感謝分享
回復

使用道具 舉報

ID:644025 發表于 2019-11-18 08:00 | 顯示全部樓層
感謝分享
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 欧美精品一区二区蜜桃 | 国产免费一区二区 | 一区二区三区国产好 | 国产一区三区在线 | 国产欧美精品在线 | 亚洲黄色视屏 | 国产一级视频在线 | 涩涩视频网站在线观看 | 日韩激情免费 | www久久爱| 亚洲精品在线视频 | 成人免费大片黄在线播放 | 美女一级黄 | 婷婷午夜天 | 亚洲人人 | 尤物在线精品视频 | 亚洲一区久久 | 看特级黄色片 | 成年人网站免费 | 婷婷在线免费 | 久久一区二区三区免费 | 91精品中文字幕一区二区三区 | 欧美性乱 | 丁香婷婷久久久综合精品国产 | 免费观看www7722午夜电影 | 亚洲激情网站 | 激情av在线 | 欧美在线视频一区 | 91久久国产精品 | 亚洲444kkkk在线观看最新 | 99精品国产一区二区三区 | av免费网址 | 网页av | 国产精品一区二区三区四区五区 | 精品亚洲一区二区 | 午夜精品一区二区三区三上悠亚 | 国产区在线观看 | 午夜视频在线免费观看 | 麻豆久久久9性大片 | 国产在线一区二区三区 | 成人在线视频免费观看 |