TA的每日心情 | 擦汗 2014-8-19 06:31 |
---|
签到天数: 296 天 连续签到: 1 天 [LV.8]以坛为家I
|
用DMA 串口发送数据 但是没反应
找不出问题在哪
/* Includes ------------------------------------------------------------------*/
#include "DMA_USART.h"
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private typedef -----------------------------------------------------------*/
#define USART1_DR_Base 0x40013804 //(uint8_t)(&((USART_TypeDef*)USART1)->DR)
#define SendBuff_Size 5000
/* Private define ------------------------------------------------------------*/
uint8_t SendBuff[SendBuff_Size];
/* Private macro -------------------------------------------------------------*/
static void NVIC_DMA_Config(void);
void DMA_Config(void);
/* Private variables ---------------------------------------------------------*/
/*-----------------------DMA ----USART--------------------------------
------Main-------Main--------Main-------Main--------Main-------Main--*/
void DMA_USART_Main(void)
{
uint16_t i;
DMA_Config();
for(i=0;i<5000;i++)
{
SendBuff[i]=0xff;
}
/* 串口向 DMA 发出请求*/
USART_DMACmd(USART1,USART_DMAReq_Tx,ENABLE);
GPIO_LED_ON(GPIO_Pin_2);
while(1)
{}
}
/*-----------------------------------------------------------------------------*/
/*-----------------------------------------------------------------------------*/
void DMA_Config(void)
{
DMA_InitTypeDef DMA_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1,ENABLE);
NVIC_DMA_Config();
DMA_DeInit(DMA1_Channel4); // 通道4
DMA_InitStructure.DMA_PeripheralBaseAddr=(u32)USART1_DR_Base; // 外设地址
DMA_InitStructure.DMA_MemoryBaseAddr=(u32)SendBuff; // 存储器地址
DMA_InitStructure.DMA_DIR=DMA_DIR_PeripheralDST; // DST->存储器到外设 SRC->外设到存储器
DMA_InitStructure.DMA_BufferSize = SendBuff_Size; // 缓存区长度
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; // 外设地址不自增
DMA_InitStructure.DMA_MemoryInc=DMA_MemoryInc_Enable; // 内存地址自增 ***
DMA_InitStructure.DMA_PeripheralDataSize=DMA_PeripheralDataSize_Byte; // 外设数据单位 word/byte
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte; // 内存数据单位
DMA_InitStructure.DMA_Mode = DMA_Mode_Normal; // 一次传输
DMA_InitStructure.DMA_Priority = DMA_Priority_Medium; // 优先级 High|VeryHigh|Medium|Low
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; // 禁止内存到内存的传输
DMA_Init(DMA1_Channel4,&DMA_InitStructure); // 使能DMA
DMA_ITConfig(DMA1_Channel4,DMA_IT_TC,ENABLE); // 配置DMA发送完成后产生中断
}
static void NVIC_DMA_Config(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
#ifdef VECT_TAB_RAM
NVIC_SetVectorTable(NVIC_VectTab_RAM,0x0);
#else
NVIC_SetVectorTable(NVIC_VectTab_FLASH,0x0); //中断向量表起始地址
#endif
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
NVIC_InitStructure.NVIC_IRQChannel=DMA1_Channel4_IRQn; //异常/中断标识符 后缀 _IRQn
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority=1; //NVIC_Priority_Table 0~15
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
中断函数
void DMA1_Channel4_IROHandler(void)
{
if(DMA_GetFlagStatus(DMA1_FLAG_TC4)==SET)
{
GPIO_LED_OFF(GPIO_Pin_2);
DMA_ClearFlag(DMA1_FLAG_TC4);
}
}
|
|