完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
#include "FreeRTOS.h"
#include "STM32f4xx.h" #include "stm32f4xx_dma.h" #include "queue.h" #include "task.h" #include "zigbee_task.h" #include "bsp_zigbee.h" unsigned char gcav_Usart1DmaRxBuffer[2][1024]; unsigned char gcav_Usart1DmaTxBuffer[2][1024] = {{1},{'+','+','+',}}; void zigbee_usart1_init() { GPIO_InitTypeDef GPIO_InitStruct; USART_InitTypeDef UART_InitStruct; NVIC_InitTypeDef NVIC_InitStruct; DMA_InitTypeDef DMA_InitStruct; /*浣胯兘GPIOB&USART&DMA2*/ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE); RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2,ENABLE); /*GPIO閰嶇疆*/ /*澶嶇敤GPIO*/ GPIO_PinAFConfig(GPIOB,GPIO_PinSource6,GPIO_AF_USART1); GPIO_PinAFConfig(GPIOB,GPIO_PinSource7,GPIO_AF_USART1); GPIO_InitStruct.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7; GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStruct.GPIO_Speed = GPIO_Speed_100MHz; GPIO_InitStruct.GPIO_OType = GPIO_OType_PP; GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_UP; GPIO_Init(GPIOB,&GPIO_InitStruct); USART_DeInit(USART1); UART_InitStruct.USART_BaudRate = 115200; UART_InitStruct.USART_StopBits = USART_StopBits_1; UART_InitStruct.USART_Parity = USART_Parity_No; UART_InitStruct.USART_WordLength = USART_WordLength_8b; UART_InitStruct.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; UART_InitStruct.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_Init(USART1, &UART_InitStruct); /*涓柇閰嶇疆*/ NVIC_InitStruct.NVIC_IRQChannel = USART1_IRQn; NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 5; NVIC_InitStruct.NVIC_IRQChannelSubPriority = 0; NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStruct); /*涓柇浣胯兘*/ USART_ITConfig(USART1, USART_IT_RXNE, ENABLE); /*涓插彛浣胯兘*/ USART_Cmd(USART1, ENABLE); /*RX*/ /*鍏抽棴DMA閫氶亾*/ DMA_DeInit(DMA2_Stream5); while(DMA_GetCmdStatus(DMA2_Stream5) != DISABLE); DMA_InitStruct.DMA_Channel = DMA_Channel_4; DMA_InitStruct.DMA_PeripheralBaseAddr = (uint32_t)&USART1->DR; DMA_InitStruct.DMA_Memory0BaseAddr = (uint32_t)&gcav_Usart1DmaRxBuffer[0]; DMA_InitStruct.DMA_DIR = DMA_DIR_PeripheralToMemory; DMA_InitStruct.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte; DMA_InitStruct.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte; DMA_InitStruct.DMA_BufferSize = 1024; DMA_InitStruct.DMA_PeripheralInc = DMA_PeripheralInc_Disable; DMA_InitStruct.DMA_MemoryInc = DMA_MemoryInc_Enable; DMA_InitStruct.DMA_Mode = DMA_Mode_Circular; DMA_InitStruct.DMA_Priority = DMA_Priority_VeryHigh; DMA_InitStruct.DMA_FIFOMode = DMA_FIFOMode_Disable; DMA_InitStruct.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull; DMA_InitStruct.DMA_MemoryBurst = DMA_MemoryBurst_Single; DMA_InitStruct.DMA_PeripheralBurst = DMA_PeripheralBurst_Single; DMA_DoubleBufferModeConfig(DMA2_Stream5, (uint32_t)&gcav_Usart1DmaRxBuffer[1], DMA_Memory_0); DMA_DoubleBufferModeCmd(DMA2_Stream5, ENABLE); DMA_Init(DMA2_Stream5, &DMA_InitStruct); /*涓柇浣胯兘*/ // DMA_ITConfig(DMA2_Stream5, DMA_IT_TC, ENABLE); /*TX*/ DMA_DeInit(DMA2_Stream7); while(DMA_GetCmdStatus(DMA2_Stream7) != DISABLE); DMA_InitStruct.DMA_Memory0BaseAddr = (uint32_t)&gcav_Usart1DmaTxBuffer[0]; DMA_InitStruct.DMA_DIR = DMA_DIR_MemoryToPeripheral; DMA_DoubleBufferModeConfig(DMA2_Stream7, (uint32_t)&gcav_Usart1DmaTxBuffer[1], DMA_Memory_0); DMA_DoubleBufferModeCmd(DMA2_Stream7, ENABLE); DMA_Init(DMA2_Stream7, &DMA_InitStruct); /*DMA TX*/ NVIC_InitStruct.NVIC_IRQChannel = DMA2_Stream7_IRQn; NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 1; NVIC_InitStruct.NVIC_IRQChannelSubPriority = 2; NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStruct); /*涓柇浣胯兘*/ DMA_ITConfig(DMA2_Stream7, DMA_IT_TC, ENABLE); /*DMA浣胯兘*/ DMA_Cmd(DMA2_Stream5, ENABLE); USART_DMACmd(USART1, USART_DMAReq_Rx, ENABLE); USART_DMACmd(USART1, USART_DMAReq_Tx, ENABLE); } /** USART1 中断函数 **/ void USART1_IRQHandler(void) { zigbee_msg_st ltv_Msg; BaseType_t ltv_HigherPriorityTaskWoken; if(USART_GetITStatus(USART1, USART_IT_IDLE) != RESET){ //关闭,防干扰 DMA_Cmd(DMA2_Stream5, DISABLE); /*获取当前正在使用的buff*/ ltv_Msg.mcv_RxIndex = DMA_GetCurrentMemoryTarget(DMA2_Stream5); ltv_Msg.mcv_TxIndex = DMA_GetCurrentMemoryTarget(DMA2_Stream7); /*切换buff*/ DMA_DoubleBufferModeCmd(DMA2_Stream5, DISABLE); if(!ltv_Msg.mcv_RxIndex) { DMA_DoubleBufferModeConfig(DMA2_Stream5, (uint32_t)&gcav_Usart1DmaRxBuffer[0], DMA_Memory_1); } else { DMA_DoubleBufferModeConfig(DMA2_Stream5, (uint32_t)&gcav_Usart1DmaRxBuffer[1], DMA_Memory_0); } DMA_DoubleBufferModeCmd(DMA2_Stream5, ENABLE); ltv_Msg.msv_RcvLen=1024-DMA_GetCurrDataCounter(DMA2_Stream5); /**重新定义长度 下次接收**/ DMA_SetCurrDataCounter(DMA2_Stream5, 1024); DMA_Cmd(DMA2_Stream5, ENABLE); USART1->SR; USART1->DR; /*Send Msg*/ xQueueSendFromISR(gtv_ZigbeeTaskMsgQueueHandle, } /** * @brief DMA1 Usart1 Tx 涓柇鍑芥暟 * @param None * @retval None */ void DMA2_Stream7_IRQHandler(void) { if(DMA_GetITStatus(DMA2_Stream7, DMA_IT_TCIF7) != RESET) { DMA_Cmd(DMA2_Stream7, DISABLE); DMA_ClearFlag(DMA2_Stream7, DMA_IT_TCIF7); } } /** * @brief USART1 鏁版嵁鍙戦 |
|
相关推荐
1个回答
|
|
中断进不去,发送不了数据!
|
|
|
|
只有小组成员才能发言,加入小组>>
如何使用STM32+nrf24l01架构把有线USB设备无线化?
2547 浏览 7 评论
请问能利用51单片机和nRF24L01模块实现实时语音无线传输吗?
2332 浏览 5 评论
3161 浏览 3 评论
2804 浏览 8 评论
为什么ucosii上移植lwip后系统进入了HardFault_Handler?
2762 浏览 4 评论
请教各位大咖:有没有接收频率32M左右的芯片推荐的?先感谢啦!
611浏览 1评论
857浏览 0评论
971浏览 0评论
625浏览 0评论
452浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-25 05:07 , Processed in 1.030399 second(s), Total 49, Slave 42 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号