中级会员
- 积分
- 233
- 金钱
- 233
- 注册时间
- 2014-4-29
- 在线时间
- 6 小时
|
5金钱
usart1.c
#include"usart1.h"
void usart1_init(u32 bound, u32 k)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
DMA_InitTypeDef DMA_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_USART1, ENABLE);
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; //PA9-TX  A10-RX
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP ; //串口1的GPIO设置
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
USART_InitStructure.USART_BaudRate = bound;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1; //串口1的配置
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(USART1, &USART_InitStructure);
DMA_DeInit(DMA1_Channel5);
DMA_InitStructure.DMA_PeripheralBaseAddr = (u32)&USART1->DR; //0x40013804; //
DMA_InitStructure.DMA_MemoryBaseAddr = k;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
DMA_InitStructure.DMA_BufferSize = 160;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; //串口1发送对应的DMA通道
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte; //配置
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
DMA_InitStructure.DMA_Priority = DMA_Priority_Medium;
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
DMA_Init(DMA1_Channel5, &DMA_InitStructure);
USART_Cmd(USART1, ENABLE);
}
void MYDMA_Enable(void)
{
DMA_Cmd(DMA1_Channel5, DISABLE );
DMA_SetCurrDataCounter(DMA1_Channel5,160);
DMA_Cmd(DMA1_Channel5, ENABLE);
}
main.c
#include"includes.h"
#include"usart1.h"
int main(void)
{
u8 t;
u8 TxBuffer1[20] ;
usart1_init(115200, (u32)TxBuffer1);
USART_DMACmd(USART1, USART_DMAReq_Rx, ENABLE);
MYDMA_Enable();
while(USART_GetFlagStatus(USART1, USART_FLAG_RXNE) == RESET);
USART_ReceiveData(USART1);
USART_ClearFlag(USART1, USART_FLAG_RXNE);
if(DMA_GetFlagStatus(DMA1_FLAG_TC5) == SET)
{
for(t = 0; t< 20; t++)
{
USART_SendData(USART1, TxBuffer1[t]);
while(USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET);
USART_ClearFlag(USART1, USART_FLAG_TC);
}
DMA_ClearFlag(DMA1_FLAG_TC5);
}
}
希望的效果是 串口1 输入能DMA,转到数组中,每个数据是8位,DMA的BUFFERSIZE 是160,传递完20个数据,再依次输出。。。
问题是没有输出。。。。
一定是哪里错了,求指点
|
|