




下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、STM32F407VGT6的485通信程序【SP3485芯片&中斷接收】本例程為STM32F4XX(M4內(nèi)核)的485通信程序,采用串口1發(fā)送和接收數(shù)據(jù),中斷接收,將接收到的數(shù)據(jù)重新發(fā)送出去。主函數(shù)main.c文件如下:#include stm32f4xx.h/* 文 件 名: mian.c * 庫(kù) 版 本: STM32F4xx_DSP_StdPeriph_Lib_V1.0.1 * 工作環(huán)境: RealView MDK-ARM 4.23 * 作 者: 曾有根 * 生成日期: 2012-08-03 * 功 能:RS485 通過串口1發(fā)送,中斷接收!將接收到* *的數(shù)據(jù)通過再次發(fā)送出去 */ext
2、ern void uart_init(void);extern void USART1_SendByte(u8 Data);extern unsigned char UART1_GetByte(u8 GetData);extern void delay(unsigned int dl);void delay(unsigned int dl)unsigned int i,y;for(i = 0; i 5000; i+)for(y = 0; y DR; USART1_SendByte(GetData); /發(fā)送數(shù)據(jù)GPIO_SetBits(GPIOE, GPIO_Pin_8 ); /LED2燈閃爍
3、,表示數(shù)據(jù)接收成功且發(fā)送完成delay(1000);GPIO_ResetBits(GPIOE, GPIO_Pin_8 ); void uart_init(void) USART_InitTypeDef USART_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; GPIO_InitTypeDef GPIO_InitStructure; /* Enable GPIO clock */ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); /* Enable USART clock */ R
4、CC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); /* Connect USART pins to A910 */ GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_USART1); GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_USART1); /* Configure USART Tx and Rx as alternate function push-pull */ GPIO_InitStructure.GPIO_Pin = GP
5、IO_Pin_9; /輸出TX GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; /必須為AF,OUT不行 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; /輸
6、入RX GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; /必須為AF,與M3不同 GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 ; /485使能端配置 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_Ini
7、tStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, &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_I
8、nitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; USART_Init(USART1, &USART_InitStructure); NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); /* Enable USART */ USART_Cmd(USART1, ENABLE); USART
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 果園的合同范本
- 企業(yè)社會(huì)責(zé)任對(duì)員工的影響計(jì)劃
- 陶瓷公司加工合同范本
- 收購(gòu)草莓合同范本
- 2024年12月秦皇島盧龍經(jīng)濟(jì)開發(fā)區(qū)管理委員會(huì)選聘事業(yè)單位工作人員5人筆試歷年典型考題(歷年真題考點(diǎn))解題思路附帶答案詳解-1
- 腫瘤晚期患者臨終護(hù)理
- 構(gòu)建高效的大數(shù)據(jù)客戶服務(wù)處理系統(tǒng)
- 外腳手架的施工方案
- 長(zhǎng)沙醫(yī)學(xué)院《數(shù)據(jù)庫(kù)開發(fā)與應(yīng)用綜合實(shí)訓(xùn)》2023-2024學(xué)年第二學(xué)期期末試卷
- 山西醫(yī)科大學(xué)晉祠學(xué)院《分析方法選擇及方案設(shè)計(jì)》2023-2024學(xué)年第二學(xué)期期末試卷
- 課件:舉手意識(shí)課件講解
- 中考體育培訓(xùn)合同
- 基金應(yīng)知應(yīng)會(huì)專項(xiàng)考試題庫(kù)(證券類190題)附有答案
- 固定式、車載式、便攜式反無人機(jī)實(shí)施方案
- 陜西省2024年高中學(xué)業(yè)水平合格考數(shù)學(xué)試卷試題(含答案)
- 美術(shù)基礎(chǔ)試題庫(kù)含答案
- 鄉(xiāng)村研學(xué)旅行方案
- 《養(yǎng)老機(jī)構(gòu)認(rèn)知障礙照護(hù)專區(qū)設(shè)置與服務(wù)規(guī)范》
- DLT 5630-2021 輸變電工程防災(zāi)減災(zāi)設(shè)計(jì)規(guī)程-PDF解密
- 輸電線路安全施工培訓(xùn)
- 梅毒螺旋體抗體膠體金法檢測(cè)試劑條生產(chǎn)工藝的優(yōu)化
評(píng)論
0/150
提交評(píng)論