我的想法是使用DMA进行USART1的Rx外设和Tx进行数据的交互,但是我使用printf却没有输出。我想知道是代码问题还是我的想法是错误的,**大神纠正。
DMA.c
#include "DMA.h"
#define DTRD 5000 /*可传输最大数据65535字节*/
void USART1_Rx_DMA_Init(u8 buff)
{
RCC->AHBENR |= 1;/*开启DMA1时钟*/
DMA1_Channel5->CCR = 0x00000000;
/*意思是从USART1->DR处获取数据,后放到buff上*/
DMA1_Channel5->CPAR = (uint32_t)(&USART1->DR);/*源*/
DMA1_Channel5->CMAR = (uint32_t)buff;/*目标*/
DMA1_Channel5->CNDTR = DTRD;
DMA1_Channel5->CCR |= 2<<12;
DMA1_Channel5->CCR |= 1<<7;
DMA1_Channel5->CCR |= 1<<5;
DMA1_Channel5->CCR &= 1<<4;/*数据传输方向由USART1->DR到buff,因此是从外设读*/
//DMA1_Channel5->CCR |= 1<<1;
DMA1_Channel5->CCR |= 1;
}
void USART1_Tx_DMA_Init(u8 Send_Buff)
{
RCC->AHBENR |= 1;
DMA1_Channel4->CCR = 0x00000000;
DMA1_Channel4->CPAR = (uint32_t)(&USART1->DR);/*目标*/
DMA1_Channel4->CMAR = (uint32_t)Send_Buff;/*源*/
DMA1_Channel4->CNDTR = DTRD;
DMA1_Channel4->CCR |= 2<<12;
DMA1_Channel4->CCR |= 1<<7;
DMA1_Channel4->CCR |= 1<<5;
DMA1_Channel4->CCR |= 1<<4;/*数据方向由Send_Buff到USART1->DR,因此是从存储器读*/
DMA1_Channel5->CCR |= 1;
}
==========================================
DMA.h
#ifndef __DMA_H
#define __DMA_H
#include
#include "STM32f10x.h"
#include "USART.h"
void USART1_Rx_DMA_Init(u8 buff);
void USART1_Tx_DMA_Init(u8 Send_Buff);
#endif
===========================================
main.c
#include "stm32f10x.h"
#include
#include "LED_Init.h"
#include "USART.h"
#include "DMA.h"
u8 SendBuff = 'a';
u8 handBuff;
int main(void)
{
Usart1_Init(72,4800);
LED_Setup();
USART1_Tx_DMA_Init(SendBuff);
USART1_Rx_DMA_Init(handBuff);
printf("%cn",handBuff);
while (1)
{
}
}
====================================
根据我的理解printf应该会输出字符 'a' 才对但是并没有。**大神解答 |