RT;
#ifndef rx_len
#define rx_len 256
#endif
static char gps_data_dma[rx_len];
static char gps_data_txt[rx_len];
void usart_dma_init(void)
{
/*********************************************************/
/**************************½á11ì嶨òå*******************************/
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
DMA_InitTypeDef DMA_InitStructure;
/**************************ê±Öóê1Äü*******************************/
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
/**************************′®¿ú¶Ë¿ú3õê¼»ˉ*******************************/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; //PA.9
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/***************************′®¿úÅäÖÃ******************************/
USART_InitStructure.USART_BaudRate = 9600;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_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);
USART_ITConfig(USART1, USART_IT_IDLE, ENABLE);
USART_Cmd(USART1, ENABLE);
USART_ClearFlag(USART1, USART_FLAG_TC);
/***************************DMA13õê¼»ˉÅäÖÃ******************************/
DMA_DeInit(DMA1_Channel5);
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)(&(USART1->DR));
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)gps_data_dma;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;
DMA_InitStructure.DMA_BufferSize = rx_len;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
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);
DMA_ITConfig(DMA1_Channel5, DMA_IT_TC | DMA_IT_TE, ENABLE);
/**************************ÖD¶ÏÅäÖÃ*******************************/
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=3 ;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/****************************′®¿úê1Äü*****************************/
USART_DMACmd(USART1,USART_DMAReq_Rx,ENABLE);
DMA_Cmd(DMA1_Channel5, ENABLE);
}
void USART1_IRQHandler(void) //′®¿ú1ÖD¶Ï·tÎñ3ìDò
{
u16 nlen = 0;
u16 ncount = 0;
char gps_data_mid[rx_len] = {0};
if(USART_GetITStatus(USART1, USART_IT_IDLE) != RESET)
{
DMA_Cmd(DMA1_Channel5, DISABLE);
DMA_ClearITPendingBit(DMA1_IT_TC5);
DMA_ClearITPendingBit(DMA1_IT_TE5);
USART_ClearITPendingBit(USART1, USART_IT_IDLE);
nlen = 256 - DMA_GetCurrDataCounter(DMA1_Channel5);
if(nlen)
{
// SoftwareTimers.Register_fun(led_fun.LED_K, 1, 0);
// SoftwareTimers.Register_fun(led_fun.LED_G, 5, 0);
memcpy(gps_data_mid, gps_data_dma, rx_len);
// g_gps.gps_write(gps_data_mid);
// gps_data_handle(gps_data_mid, nlen);
}
DMA_SetCurrDataCounter(DMA1_Channel5,rx_len);
DMA_Cmd(DMA1_Channel5, ENABLE);
}
}
电路板检查一切正常,有GPS信号进入,但是逐步调试 gps_data_dma 始终为000000
请各位大神看看
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
谢谢原子个 问题已经找出来了
一周热门 更多>