DMA idle interrupt data configuration of stm32

Publisher:ww313618Latest update time:2016-10-05 Source: eefocusKeywords:stm32 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
For example for serial port 2:

void USART2_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
DMA_InitTypeDef DMA_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 ;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
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(USART2, &USART_InitStructure);
//////////////////中断的相关配置////////////////////////////
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
//USART_ITConfig(USART2, USART_IT_RXNE, ENABLE); //允许中断方式
USART_Cmd(USART2, ENABLE);

DMA_DeInit(DMA1_Channel6);
DMA_InitStructure.DMA_PeripheralBaseAddr = 0x40004404;
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)USART2_RECEIVE_DATA;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
DMA_InitStructure.DMA_BufferSize = 512;
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_Circular;
DMA_InitStructure.DMA_Priority = DMA_Priority_High;
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
DMA_Init(DMA1_Channel6, &DMA_InitStructure);
USART_DMACmd(USART2, USART_DMAReq_Rx, ENABLE);
DMA_Cmd(DMA1_Channel6, ENABLE);
USART_ITConfig(USART2, USART_IT_IDLE , ENABLE);
}

Interrupt section:

void USART2_IRQHandler(void)
{
// uint8_t data;
int i = 0;
// static u8 usart2_i;
int DATA_LEN;
OSIntEnter();
// if(USART_GetITStatus(USART2, USART_IT_RXNE) != RESET)
// {
// USART_ClearITPendingBit(USART2,USART_IT_RXNE);
// data = USART_ReceiveData ( USART2 ) ;
// // USART_SendData(USART1, data);
// // printf("%c",data);
// // usart2_buffer[usart2_i] = data;
// }
if(USART_GetITStatus(USART2, USART_IT_IDLE) != RESET)
{
DMA_Cmd(DMA1_Channel6, DISABLE);
i = USART2->DR;

//防止不必要的错误出现
if( DMA_GetCurrDataCounter(DMA1_Channel6) > 512)
{
return;
}

DATA_LEN = 512 - DMA_GetCurrDataCounter(DMA1_Channel6);

for(i=0;i < DATA_LEN;i ++ )
{
USART2_SEND_DATA[i] = USART2_RECEIVE_DATA[i];
}
usart2_received_data(USART2_SEND_DATA);
//printf("%s",USART2_SEND_DATA);
DMA1_Channel6->CNDTR = 512;
DMA_Cmd(DMA1_Channel6, ENABLE);
USART_ClearITPendingBit(USART2, USART_IT_IDLE);
}
memset(USART2_SEND_DATA,'\0' ,sizeof(USART2_SEND_DATA));
memset(USART2_RECEIVE_DATA,'\0' ,sizeof(USART2_RECEIVE_DATA));
OSIntExit();
}

 

Keywords:stm32 Reference address:DMA idle interrupt data configuration of stm32

Previous article:RTC operation of stm32
Next article:The stm32 function is placed in the section

Recommended ReadingLatest update time:2024-11-16 14:41

6 steps to teach you how to add printf function in STM32 program
The premise is that you have a complete Keil project such as ADC   When debugging, the serial port is often used. Here we teach you how to use the Printf function. Add Printf to the program 1, #include stdio.h 2, /* Private functions ---------------------------------------------------------*/ Add void USART
[Microcontroller]
STM32_TEST.axf: Error: L6218E: Undefi
        The error message of this problem has clearly told you where the error is, Undefined symbol SystemInit, which means: SystemInit symbol is not defined. The small brackets that follow tell you that it is mentioned in the startup_stm32f10x_md.o file. This .o file does not exist in the project. It is generated acco
[Microcontroller]
About stm32 HardFault_Handler exception handling crash
When developing the system, the HardFault_Handler hardware exception occurs, that is, the system crashes. Especially for a system that calls the OS, the program volume is large, and the stack overflow and array overflow detection are detected. After searching for a long time and finding nothing, I probably want to die
[Microcontroller]
About stm32 HardFault_Handler exception handling crash
STM32 system clock detailed explanation && transplantation
Reason for writing: Today I took over a project developed with the stm32f100xx chip. Previously, I used stm8s and stm32f103xx chips. Because I did two developments based on someone else's project code, I found that there was no function related to the system clock setting in the main function of that code. I was puzzl
[Microcontroller]
STM32 system clock detailed explanation && transplantation
Redirect printf to stm32 serial port
1. What is redirection? In the process of debugging a program, in addition to those advanced debugging methods, printf is undoubtedly the most familiar and convenient debugging method. By using printf, we can easily and intuitively obtain the running status of the current program. The printf() function is a formatted
[Microcontroller]
Detailed explanation of STM32 clock configuration method
1. In STM32, there are five clock sources: HSI, HSE, LSI, LSE, and PLL. ①HSI is a high-speed internal clock, RC oscillator, with a frequency of 8MHz. ②HSE is a high-speed external clock that can be connected to a quartz/ceramic resonator or an external clock source with a frequency range of 4MHz~16MHz. ③LSI is a low-s
[Microcontroller]
[Lianshengde W806 Hands-on Notes] 9. DMA
Windows 10 20H2 HLK-W806-V1.0-KIT WM_SDK_W806_v0.6.0        Excerpted from "W806 MCU Chip Specification V2.0", "WM_W800_Register Manual V2.1" DMA Controller        Supports up to 8 channels, 16 DMA request sources, and supports linked list structure and register control. Amba2.0 standard bus interface, 8 DMA cha
[Microcontroller]
[Lianshengde W806 Hands-on Notes] 9. DMA
Power industry, Mir STM32MP135 development board IEC61850 protocol transplantation notes
1. Overview IEC61850 is an international standard for communication systems and distributed energy (DER) management in substation automation systems (SAS). Through the implementation of the standard, it has achieved the standardization of engineering operations of smart substations. It makes the engin
[Embedded]
Power industry, Mir STM32MP135 development board IEC61850 protocol transplantation notes
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号