DMA/USART transmit data [STM32F4] halfcooked library function operation

Recommended for you: Get network issues from WhatsUp Gold. Not end users.

Life: because a data

Stranger: because do not understand. Only a few simple things

DMA configuration steps are as follows:

1,Turn the clock.

RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2,ENABLE);

2,The configuration of DMA data structure

There are a few points clear: sending data through USART1, the ST F4 reference manual inside can find USART1 said the corresponding channel: DMA2-Channel4-Stream7.

Data transfer direction is Memory2Peripheral. That memory to peripheral.

Do not use FIFO, the data to be transmitted in the array usart_tx_buf[20], USART1 sends the data register address is: USART1_BASE+0x04, memory and peripherals word width is 1Byte.

A single transmission, transmission of a need to manually restart. Peripheral address is fixed, the memory address increment.

Therefore:

DMA_DeInit(DMA2_Stream7);

RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2,ENABLE);

DMA_StructInit(&DMA_InitStructure);

DMA_InitStructure.DMA_Priority = DMA_Priority_Medium;

DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;

DMA_InitStructure.DMA_Channel = DMA_Channel_4;

DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral;

DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable;

DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)usart_tx_buf;

DMA_InitStructure.DMA_PeripheralBaseAddr = USART1_BASE+0x04;

DMA_InitStructure.DMA_BufferSize = BufSize;

DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;

DMA_InitStructure.DMA_MemoryDataSize = DMA_PeripheralDataSize_Byte;

DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;

DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;

Then, using DMA_Init to initialize the DMA. Finally, DMA_Cmd enabled DMA.

After each transmitted data should use DMA_Cmd to enable a DMA. I didn't find any other way. . . . .

Live function call:


while(1)

{

while(RESET == USART_GetFlagStatus(USART1,USART_FLAG_TXE));

USART_SendData(USART1,'b');

while(RESET == USART_GetFlagStatus(USART1,USART_FLAG_TXE));

USART_SendData(USART1,'a');

delay_ms(1000);

printf("argjiarjfgio\r\n");

if(SET == DMA_GetFlagStatus(DMA2_Stream7,DMA_FLAG_TCIF7))

{

DMA_ClearFlag(DMA2_Stream7,DMA_FLAG_TCIF7);

//DMA_Cmd(DMA2_Stream7,DISABLE);

for(i = 0;i<20;i++)

usart_tx_buf[i] = i+51;

DMA_Cmd(DMA2_Stream7,ENABLE);

}

}

Technorati tag: STM32F4,DMA,USART

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Reg at November 14, 2013 - 12:10 AM