STM32F429 DMA serial port data transmission

Publisher:as8849402Latest update time:2019-04-09 Source: eefocusKeywords:STM32F429 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Serial port data configuration


void macUART4_Config(void)

{

    GPIO_InitTypeDef GPIO_InitStructure;

  USART_InitTypeDef USART_InitStructure;


    RCC_AHB1PeriphClockCmd(macUART4_RX_GPIO_CLK|macUART4_TX_GPIO_CLK,ENABLE);

  RCC_APB1PeriphClockCmd(macUART4_CLK, ENABLE);


  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;  

  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;


  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

  GPIO_InitStructure.GPIO_Pin =  macUART4_TX_PIN  ;  

  GPIO_Init(macUART4_TX_GPIO_PORT, &GPIO_InitStructure);


  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

  GPIO_InitStructure.GPIO_Pin =  macUART4_RX_PIN;

  GPIO_Init(macUART4_RX_GPIO_PORT, &GPIO_InitStructure);


GPIO_PinAFConfig(macUART4_RX_GPIO_PORT,macUART4_RX_SOURCE,macUART4_RX_AF);

  GPIO_PinAFConfig(macUART4_TX_GPIO_PORT,macUART4_TX_SOURCE,macUART4_TX_AF); 


  USART_InitStructure.USART_BaudRate = macUART4_BAUDRATE;

  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(macUART4, &USART_InitStructure); 

  USART_Cmd(macUART4, ENABLE);

}


DMA configuration function, please compare with DMA serial port receiving data configuration function


void DMA_Config(void)

{

    DMA_InitTypeDef DMA_InitStructure;                //

    RCC_AHB1PeriphClockCmd(macUART4_DMA_CLK, ENABLE); //

    DMA_DeInit(macUART4_TX_DMA_STREAM);               //


  while (DMA_GetCmdStatus(macUART4_TX_DMA_STREAM) != DISABLE){

  } 


    DMA_InitStructure.DMA_Channel = macUART4_TX_DMA_CHANNEL;             //

  DMA_InitStructure.DMA_PeripheralBaseAddr = macUART4_DR_BASE;         //

  DMA_InitStructure.DMA_Memory0BaseAddr = (u32)SendBuff;               //


  DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral;                //

  DMA_InitStructure.DMA_BufferSize = macUART4_SEND_BUFF_SIZE;          //

  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_Medium;                //

  DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable;               // 

  DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_Full;        //  

  DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;          //

  DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;  //


  DMA_Init(macUART4_TX_DMA_STREAM, &DMA_InitStructure);                   //     

  DMA_Cmd(macUART4_TX_DMA_STREAM, ENABLE);                                 


    while(DMA_GetCmdStatus(macUART4_TX_DMA_STREAM) != ENABLE)

  {

  }

}

Main function, debug serial port and UART4 send data at the same time, without affecting each other


int main(void)

{

    int i;

    SysTick_Init();

    NVIC_Configuration();

    Debug_USART_Config();

    macUART4_Config();

    DMA_Config();

    printf("Hello World!nn");


    for(i=0;i

  {

    SendBuff[i]  = 'A';

  }


    USART_DMACmd(macUART4, USART_DMAReq_Tx, ENABLE);


    while(1)

    {

        printf("Hello World!n");

    }

}


There is no interrupt routine involved in this program, and the use of DMA should avoid interrupts as much as possible.


Keywords:STM32F429 Reference address:STM32F429 DMA serial port data transmission

Previous article:STM32 uses HAL library to realize serial communication - detailed explanation of theoretical principles
Next article:STM32F407 Hal Library Serial Port Usage Guide

Latest Microcontroller Articles
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号