Ynt: Stm32F4 MemoryToPeripheral DMA

Başlatan muhittin_kaplan, 07 Ağustos 2013, 02:40:30

muhittin_kaplan

diğer tarafta Devamlı Mod Onayı Gerekiyordu.
Bazı iletiler taşınırsa dahada şık olur.

mir_as82 soruna gelecek olursam. Aşağıdaki kodlar Klein in serisini Usarttan Gönderiyor. Tabiki DMA ile

#include "stm32f4xx.h"
#include "stm32f4xx_i2c.h"
#include "stm32f4xx_gpio.h"
#include "stm32f4xx_rcc.h"
#include "stm32f4xx_flash.h"
#include "stm32f4xx_usart.h"
#include "stm32f4xx_dma.h"
#include "misc.h"
#include "MPU6050.h"
#include <stdio.h>


const uint16_t SineTable[] ={
        180,183,186,189,192,195,198,201,205,208,211,214,217,220,223,226,229,232,235,238,
        241,244,247,250,253,256,258,261,264,267,270,272,275,278,280,283,285,288,290,293,
        295,298,300,302,305,307,309,311,313,315,317,319,321,323,325,327,329,330,332,334,
        335,337,338,340,341,343,344,345,346,348,349,350,351,352,353,353,354,355,356,356,
        357,357,358,358,359,359,359,359,359,359,360,359,359,359,359,359,359,358,358,357,
        357,356,356,355,354,353,353,352,351,350,349,348,346,345,344,343,341,340,338,337,
        335,334,332,330,329,327,325,323,321,319,317,315,313,311,309,307,305,302,300,298,
        295,293,290,288,285,283,280,278,275,272,270,267,264,261,258,256,253,250,247,244,
        241,238,235,232,229,226,223,220,217,214,211,208,205,201,198,195,192,189,186,183};

/**************************************************************************************/

void RCC_Configuration(void)
{
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1, ENABLE);
}

/**************************************************************************************/



void USART2_Configuration(void)
{
	GPIO_InitTypeDef GPIO_InitStructure;
		USART_InitTypeDef USART_InitStructure;

		RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);


		RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);

		/* GPIOA Configuration:  USART2 TX on PA2 */
		GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
		GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
		GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
		GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
		GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP ;
		GPIO_Init(GPIOA, &GPIO_InitStructure);


		GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_USART2);

		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_Tx;
		USART_Init(USART2, &USART_InitStructure);

		USART_Cmd(USART2, ENABLE); 

}

/**************************************************************************************/


void DMA_Configuration(void)
{
  DMA_InitTypeDef  DMA_InitStructure;

  DMA_DeInit(DMA1_Stream6);

  DMA_InitStructure.DMA_Channel = DMA_Channel_4;
  DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral; // Transmit
  DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)SineTable;
  DMA_InitStructure.DMA_BufferSize = 180; // (uint16_t)sizeof(SineTable) - 1;
  DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&USART2->DR;
  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_FIFOMode = DMA_FIFOMode_Enable;
  DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_Full;
  DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
  DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;

  DMA_Init(DMA1_Stream6, &DMA_InitStructure);

  USART_DMACmd(USART2, USART_DMAReq_Tx, ENABLE);
  DMA_ITConfig(DMA1_Stream6, DMA_IT_TC, ENABLE);
  DMA_Cmd(DMA1_Stream6, ENABLE);
}

/**************************************************************************************/

void DMA1_Stream6_IRQHandler(void)
{

  if (DMA_GetITStatus(DMA1_Stream6, DMA_IT_TCIF6))
  {

    DMA_ClearITPendingBit(DMA1_Stream6, DMA_IT_TCIF6);
  }
}

/**************************************************************************************/

void NVIC_Configuration(void)
{
  NVIC_InitTypeDef NVIC_InitStructure;


  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);


  NVIC_InitStructure.NVIC_IRQChannel = DMA1_Stream6_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
}

/**************************************************************************************/

int main(void)
{
	SystemInit();

	RCC_ClocksTypeDef RCC_ClockFreq;
	RCC_GetClocksFreq(&RCC_ClockFreq);


    RCC_Configuration();

  NVIC_Configuration();


  USART2_Configuration();

  DMA_Configuration();

  while(1);
}

/**************************************************************************************/

#ifdef  USE_FULL_ASSERT
void assert_failed(uint8_t* file, uint32_t line)
{

  while (1)
  {
  }
}
#endif




mesaj birleştirme:: 07 Ağustos 2013, 02:43:47

Bazı dosyalar fazladan include edlmiştir  :-[