欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136
標(biāo)題:
基于STM32的串口5協(xié)議測(cè)試源碼
[打印本頁(yè)]
作者:
1820732662@qq.c
時(shí)間:
2018-3-13 19:29
標(biāo)題:
基于STM32的串口5協(xié)議測(cè)試源碼
這個(gè)是STM32F103ZET6的串口5測(cè)試代碼,內(nèi)部附帶一個(gè)簡(jiǎn)單的串口協(xié)議測(cè)試。
單片機(jī)源程序如下:
/*-------------------------------------------------------------------------------
文件名稱(chēng):main.c
文件描述:通過(guò)串口5,使用printf函數(shù)打印信息,編譯時(shí)需勾選Use MicroLIB
硬件平臺(tái):尼莫M3S開(kāi)發(fā)板
編寫(xiě)整理:shifang
固件庫(kù) :V3.5
備 注:通過(guò)簡(jiǎn)單修改可以移植到其他開(kāi)發(fā)板,部分資料來(lái)源于網(wǎng)絡(luò)。
---------------------------------------------------------------------------------*/
#include <stdio.h>
#include "stm32f10x.h"
#include "led.h"
#include "delay.h"
#include "key.h"
#include "timer.h"
#include "beep.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__ */
int main(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC|RCC_APB2Periph_GPIOD, ENABLE); //使能PORTC,PORTD時(shí)鐘
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART5,ENABLE); //使能UART5
USART_DeInit(UART5); //復(fù)位串口5
//UART5_TX PC.12
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12; //PC.12
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //復(fù)用推挽輸出
GPIO_Init(GPIOC, &GPIO_InitStructure); //初始化PC12
//UART5_RX PD.2
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;//浮空輸入
GPIO_Init(GPIOD, &GPIO_InitStructure); //初始化PD2
//UART5 NVIC 配置
NVIC_InitStructure.NVIC_IRQChannel = UART5_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=3 ;//搶占優(yōu)先級(jí)3
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; //子優(yōu)先級(jí)3
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ通道使能
NVIC_Init(&NVIC_InitStructure); //根據(jù)指定的參數(shù)初始化VIC寄存器
/* USARTx configured as follow:
- BaudRate = 9600 baud 波特率
- Word Length = 8 Bits 數(shù)據(jù)長(zhǎng)度
- One Stop Bit 停止位
- No parity 校驗(yàn)方式
- Hardware flow control disabled (RTS and CTS signals) 硬件控制流
- Receive and transmit enabled 使能發(fā)送和接收
*/
USART_InitStructure.USART_BaudRate = 9600;
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(UART5, &USART_InitStructure);
USART_ITConfig(UART5, USART_IT_RXNE, ENABLE);//開(kāi)啟中斷
USART_Cmd(UART5, ENABLE); //使能串口
LED_Init();//LED初始化
KEY_Init();//按鍵初始化
SysTick_Init();//延時(shí)初始化
BEEP_Init(); //蜂鳴器初始化
printf("\n\rUSART Printf Example: (德飛萊)尼莫M3S開(kāi)發(fā)板串口測(cè)試程序\r輸入任何信息發(fā)送,接收到同樣信息");
while (1)
{
//使用printf函數(shù)循環(huán)發(fā)送固定信息
Delay_ms(500);
LED2_REV;
}
}
PUTCHAR_PROTOTYPE
{
/* Place your implementation of fputc here */
/* e.g. write a character to the USART */
USART_SendData(UART5, (uint8_t) ch);
/* 循環(huán)等待直到發(fā)送結(jié)束*/
while (USART_GetFlagStatus(UART5, USART_FLAG_TC) == RESET)
{}
return ch;
}
復(fù)制代碼
所有資料51hei提供下載:
串口5測(cè)試協(xié)議.zip
(310.8 KB, 下載次數(shù): 19)
2018-3-13 19:28 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
作者:
linuxcso
時(shí)間:
2018-5-4 19:51
請(qǐng)問(wèn)程序包括 接收中斷處理嗎?
歡迎光臨 (http://m.raoushi.com/bbs/)
Powered by Discuz! X3.1