欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136
標題:
基于STM32f103C8T6的485通訊參考源碼有問題 求幫助
[打印本頁]
作者:
liude
時間:
2018-9-17 10:17
標題:
基于STM32f103C8T6的485通訊參考源碼有問題 求幫助
1、該例程為RS485例程。
2、使用說明
(1)工程文件路徑:例程目錄\RS485\MDK-ARM\Project.uvproj。
(2)請使用MDK 4.0以上版本打開,MDK版本過低會導(dǎo)致無法識別工程。
(3)下載調(diào)試工具為ULINK。
(4)請將RS485A、RS485B連接RS485轉(zhuǎn)RS232,并打開超級終端或串口助手,配置波特率115200,8位,一個停止位,無校驗位。
(5)HEX文件下載到板子后,使用超級終端或串口調(diào)試助手可以看到調(diào)試信息,表明例程運行正確。
3、注意事項
請務(wù)必在下載、調(diào)試、運行過程中,保持板子上電、ULINK連接并插在電腦上。
單片機源程序如下:
/****************************************Copyright (c)****************************************************
**--------------File Info---------------------------------------------------------------------------------
** File name: main.c
** Descriptions: The RS485 application function
**
**--------------------------------------------------------------------------------------------------------
** Created by: AVRman
** Created date: 2010-10-30
** Version: v1.0
** Descriptions: The original version
**
**--------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
** Version:
** Descriptions:
**
*********************************************************************************************************/
/* Includes ------------------------------------------------------------------*/
#include "stm32f10x.h"
#include <stdio.h>
#ifdef __GNUC__
/* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf
set to 'Yes') calls __io_putchar() */
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif /* __GNUC__ */
#define DIR485_Receive() GPIO_ResetBits(GPIOB,GPIO_Pin_2)
#define DIR485_Send() GPIO_SetBits(GPIOB,GPIO_Pin_2)
/* Private function prototypes -----------------------------------------------*/
void USART_Configuration(void);
/*******************************************************************************
* Function Name : Delay
* Description : Delay Time
* Input : - nCount: Delay Time
* Output : None
* Return : None
* Attention : None
*******************************************************************************/
void Delay (uint32_t nCount)
{
for(; nCount != 0; nCount--);
}
/*******************************************************************************
* Function Name : main
* Description : Main program
* Input : None
* Output : None
* Return : None
* Attention : None
*******************************************************************************/
int main(void)
{
uint8_t ch;
USART_Configuration();
printf("*****************************************************************\r\n");
printf("* *\r\n");
printf("* Thank you for using HY-RedBull V3.0 Development Board ! ^_^ *\r\n");
printf("* *\r\n");
printf("*****************************************************************\r\n");
printf("\r\nPlease input any word :\r\n");
/* Infinite loop */
while (1){
/* Loop until RXNE = 1 */
while (USART_GetFlagStatus(USART3, USART_FLAG_RXNE) == RESET);
ch = USART_ReceiveData(USART3);
Delay(10000);
printf("%c",ch);
}
}
/*******************************************************************************
* Function Name : USART_Configuration
* Description : Configure USART3
* Input : None
* Output : None
* Return : None
* Attention : None
*******************************************************************************/
void USART_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB , ENABLE);
RCC_APB1PeriphClockCmd( RCC_APB1Periph_USART3 , ENABLE);
/*
* USART3_TX -> PB10 , USART3_RX -> PB11 , 485_DIR -> PB2
*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
USART_InitStructure.USART_BaudRate = 115200;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(USART3, &USART_InitStructure);
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
USART_ClearFlag(USART3,USART_FLAG_TC);
USART_Cmd(USART3, ENABLE);
}
/**
* @brief Retargets the C library printf function to the USART.
* @param None
* @retval None
*/
PUTCHAR_PROTOTYPE
{
DIR485_Send();
/* Place your implementation of fputc here */
/* e.g. write a character to the USART */
USART_SendData(USART3, (uint8_t) ch);
/* Loop until the end of transmission */
while (USART_GetFlagStatus(USART3, USART_FLAG_TC) == RESET)
{}
DIR485_Receive();
return ch;
}
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
……………………
…………限于本文篇幅 余下代碼請從51黑下載附件…………
復(fù)制代碼
所有資料51hei提供下載:
RS485.rar
(336.45 KB, 下載次數(shù): 141)
2018-9-17 10:16 上傳
點擊文件名下載附件
stm32 485
作者:
1203162053
時間:
2019-7-5 13:54
程序不能用
作者:
D-偉
時間:
2019-10-19 17:53
有原理圖 嗎?
作者:
linmiaomiaoa
時間:
2019-12-19 13:56
不知道行不行 先看看
作者:
ws0564
時間:
2021-6-6 17:10
不能用,已驗證!
歡迎光臨 (http://m.raoushi.com/bbs/)
Powered by Discuz! X3.1