DMA Asn Data Transmission

Source: Internet
Author: User
// The timer overflow interrupt is used as the trigger source. One byte is sent each time an overflow occurs. # Include "../dma_driver.h" # include "../avr_compiler.h"
// The I/O ports connected by the switch and LED lights are defined in board. h. This header file is specially configured for xmega A1 xplained. # Include "../board. H"
# Define sample_count 9 // Number of LED states. Uint8_t samples [sample_count] = {0xff> 0, 0xff> 1, 0xff> 2, 0xff> 3, 0xff> 4, 0xff> 5, 0xff> 6, 0xff> 7, 0xff> 8 };

// The DMA channel will be triggered by the timer overflow interrupt mark and will be continuously triggered as long as the overflow interrupt mark is set. // When an overflow occurs, we only perform data transmission once. Therefore, we need to enable overflow interruption and automatically clear the overflow interruption mark when the interrupted service program is executed.
ISR (tcc0_ovf_vect) // only used to clear the overflow interrupt flag {Nop ();}

// Set the channel parameter to write the LED value. The source address is reloaded when the data block transmission is complete. // Enable single-shot to transmit one byte of data every overflow. Void setupwritechannel (dma_ch_t * dmachannel) {dma_setupblock (dmachannel, samples, dma_ch_srcreload_block_gc, expires, (void *) & (ledport. out), dma_ch_destreload_none_gc, samples, sample_count, counts, 0, false // No repeated transmission); dma_enablesingleshot (dmachannel); dma_settriggersource (dmachannel, kernel ); // tcc0 overflow is used as the trigger source .}
// Set the timer to cause overflow interruption at a specific sampling frequency. 2 MHz/2 ^ 16 void setupsampletimer (void) {tcc0.ctrla = idle; tcc0.per = 0 xFFFF; tcc0.intctrla = idle; PMIC. CTRL | = pmic_lolvlen_bm ;}

// Display purpose void blinkleds (void) {ledport. Out = 0x00; delay_us (1000000); // wait for one second for ledport. Out = 0xff ;}

Int main (void) {// used for data to the led dma channeldma_ch_t * writechannel = & DMA. memory;
// Set it to pull up input. Portcfg. mpcmask = switchportl_mask_gc; switchportl. pin0ctrl = port_opc_pullup_gc; switchportl. dir = ~ Switchportl_mask_gc; // enter ledport. dir = 0xff; // output dma_enable (); // enable dmasetupwritechannel (writechannel); setupsampletimer (); SEI (); // enable global interruption while (1) {// keep writing data to the led until the data is written. Dma_enablechannel (writechannel); do {} while (switchportl. In | pin6_bm | pin7_bm) = 0xff); dma_disablechannel (writechannel); // restart the write channel. Setupwritechannel (writechannel );}}

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.