的通信程序SP芯片中斷接收_第1頁(yè)
的通信程序SP芯片中斷接收_第2頁(yè)
的通信程序SP芯片中斷接收_第3頁(yè)
的通信程序SP芯片中斷接收_第4頁(yè)
的通信程序SP芯片中斷接收_第5頁(yè)
全文預(yù)覽已結(jié)束

下載本文檔

版權(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ì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論