Re-learning STM32---(vi) dac+dma+tim

Source: Internet
Author: User

These two days reviewed the DAC,DMA plus put the basic timer TIM6 and TIM7 looked, intends to write a comprehensive point of the program,, on the internet to find some about the DAC,DMA and timer related procedures, the final intention to write the output sine Wave program ...

Because there is no oscilloscope, it will not show the effect, it is intended to use software debugging to see the effect, but TIM6 always problems, CNT does not self-increase, but I really can not find out what error TIM6,, and later on the internet found many friends encounter the same problem, some people say TIM6 does not support software debugging, Do not know is not so,, no way, no oscilloscope, software debugging and not, oneself do not want to delay the process of review, it is not entangled in this

It's supposed to be right on the whole.

Program:

#include "dac.h"
#include "stm32f10x.h"

void Dac1_init ()
{
Rcc->apb2enr |= 1 << 2; //

GPIOA->CRL &= 0xfff0ffff; PA4 Analog Input

DAC->CR &= 0x00000000; Clear Zero
DAC->CR |= 1 << 12; DMA Enable
DAC->CR |= 0 << 6; TIM6 Trgo Trigger
DAC->CR |= 1 << 2; Turn on trigger to enable
DAC->CR |= 1 << 1; Turn off output caching
DAC->CR |= 1 << 0; Open DAC1

}

#include "Dma.h"
#include "stm32f10x.h"

Pscadr Peripheral Address
MEMADDR memory Address
Numbyte bytes of transmission
void Dma_init (u32 pscadr,u16 memaddr,u16 numbyte)
{
Rcc->ahbenr |= 1 << 0; Turn on the DMA1 clock

DMA1_CHANNEL1->CCR &= 0xffff0000;
DMA1_CHANNEL1->CCR |= 3 << 12; Highest priority level
DMA1_CHANNEL1->CCR |= 1 << 10; Memory 16-bit data
DMA1_CHANNEL1->CCR |= 1 << 8;//Peripheral 16-bit data
DMA1_CHANNEL1->CCR |= 1 << 7; Memory self-increment
DMA1_CHANNEL1->CCR |= 0 << 6; Peripheral not self-increasing
DMA1_CHANNEL1->CCR |= 1 << 5;//cycle
DMA1_CHANNEL1->CCR |= 1 << 4;//read from memory

DMA1_CHANNEL1->CNDTR |= Numbyte;

Dma1_channel1->cmar |= memaddr;
Dma1_channel1->cpar |= Pscadr;


DMA1_CHANNEL1->CCR |= 1 << 0; Channel Open
}

void Tim6_init (U16 arr,u16 PSC)
{
Rcc->apb1enr |= 1 << 4;

TIM6->CR1 &= 0xff00;
TIM1->CR1 |= 1 << 7; Auto Reload
TIM6->CR1 |= 0 << 3; Non-single pulse mode

TIM6->CR2 |= 2 << 3; Update event used as Trgo

TIM6->PSC |= PSC;
Tim6->arr |= ARR;

TIM6->CR1 |= 1 << 0;
}

#include "Timer.h"
#include "exti.h"
#include "Dma.h"
#include "dac.h"

/* Waveform Data---------------------------------------------------------*/
Const unsigned short sine12bit[32] = {
2448,2832,3186,3496,3751,3940,4057,4095,4057,3940,
3751,3496,3186,2832,2448,2048,1648,1264,910,600,345,
156,39,0,39,156,345,600,910,1264,1648,2048};

#define DAC_DHR12R1_ADDR Dac_base + 8//DAC_DHR12R1 Register address

int main ()
{
Led_init ();
Delay_init (72);
Tim6_init (19,0);
Dac1_init ();
Dma_init (Dac_dhr12r1_addr, (unsigned short) sine12bit,32);
while (1);
}

Re-learning STM32---(vi) dac+dma+tim

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.