S3C2440 Mini 2440 DMA mode to achieve Uart (serial port) communication

Publisher:upsilon30Latest update time:2016-07-11 Source: eefocusKeywords:S3C2440 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
After a long time, I finally completed the DMA method to realize serial communication. Using DMA is not very difficult, but the configuration of DCONn is more complicated and the understanding of several modes is more difficult.

 

DMA service mode: single service & whole service. In the former mode, a DMA request completes an atomic operation, and the value of the transfer count decreases by 1. In the latter mode, a DMA request completes a batch of atomic operations until the transfer count equals 0, indicating that the whole service is completed. Specifically corresponds to DCON[27].

 

DMA DREQ/DACK PROTOCOL: There are two protocols for DMA request and response, Demond mode and Handshake mode. The timing definitions of Request and Ack are different between the two:

In Demond mode, if Request is still valid after DMA completes a request, DMA considers it as the next DMA request and starts the next transfer immediately.

In Handshake mode, after DMA completes a request, it waits for the Request signal to be invalid. If the Request is invalid, DMA will invalidate ACK for two clock cycles and then wait for the next Request.

 


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

Function: Use DMA to realize serial port transmission,
        pass string data to UTXH0 through DMA0 channel, and then
        display it on the terminal. After the data is transmitted, DMA0 generates an interrupt and LED1 lights up.
************************************************************************
Mini2440 Debug Pass
2012-08-05      
*****************************************************************/
#include "2440addr.h"
#define MDIV 92
#define SDIV 1
#define PDIV 1
#define HDIVN 2
#define PDIVN 1
#define PCLK_ 50000000
#define Led1_on() {rGPBDAT&=(~(1<<5)); }


char *SendBuffer = "Hello world!" ; //source data


/*****************LED Initialization************************************/
void Led_init()
{ rGPBCON     &
    =~((3<<10) | (3<<12) | (3<<14) | (3<<16)|(3<<0));
|=((1<<10) | (1<<12) | (1<<14) | (1<<16)|(1<<0));
    rGPBUP &=~((1<<5) | (1<<6) | (1<<7) | (1<<8)|(1<<0));
    rGPBDAT =0xfffe;
}


/*******************UART0 io port initialization******************************/
void Uart0_ io_init() //uart io port
{
    rGPHCON =0xa0; //gph2,gph3 used for txd0,rxd0.
    rGPHUP=0x0; //enable the pull up function 
}


/******************************UART0 configuration****************************/
void Uart0_init(int bandrate)
{
    rULCON0 |=0x3; //8-bit data ,1bit stop
    rUCON0 |=((1<<0) | (1<<3) | (2<<10) ); //used pclk as the clock, transmit use DMA mode , receive use polling mode
    rUBRDIV0=(int)(PCLK_/(bandrate*16))-1 ; //bandrate is 115200


}


/******************************Clock configuration******************************************/
void Clk_init( )
{
    rCLKCON |=(1<<10 ); //enable uart0 used pclk
    rLOCKTIME=0xffff; //locktime
    rCLKCON |=(1<<13); //gpio enable pclk                          
    rCLKDIVN =((PDIVN<<0) | (HDIVN<<1)); //1:4:8
    rMPLLCON |=((MDIV<<12) | (PDIV<<4) | (SDIV<<0)); f_out=400MHZ
 //__asm{
                // mrc p15, 0, r1, c1, c0, 0
               // orr r1, r1, #0xc0000000
                  //mcr p15, 0, r1, c1, c0, 0
        // }
}


/****************************DMA initialization****************************************/
void Dma_init()
{
    rGPBCON |=((1<<19)| (1<<21)); //GPB9,10 used for nXDACK0,nXDREQ0
    rDISRC0=(U32)SendBuffer; //source data address
    rDISRCC0 |=((0<<1)|(0<<0)); //address increment , the source is in the AHB
    rDIDST0=(U32)UTXH0; //destination is UTXH0
    rDIDSTC0 |=((0<< 2)|(1<<1)|(1<<0)); //address not change , APB , enable interrupt
   
  
    rDCON0 |=(1<<31)|(0<<30)|(1<<29 )|(0<<28)|(0<<27)|(1<<24)|(1<<23)|(1<<22)|(0<<20)|(12);   
   // Handshake mode, PCLK synchronization ,enable dma interrupt , unit transfer , single service , 
   //UART0 is the request source, H/W request mode ,disable auto reload , Byte transmit ,12 Byte data
    rDMASKTRIG0=(0<<2)|(1<<1)|(0<<0); //start dma transmit
}


/******************** **DMA interrupt initialization******************************************/
void Dma_eint()
{
  rINTMSK &=~(1<<17); //open the dma0 interrupt
}


/************************DMA interrupt service function*** ******************************/
void __irq Dma_isr()
{
    rSRCPND|=(1<<17); //clear the srcpnd
    rINTPND |=(1<<17); //clear the int pnd
    Led1_on();
}



int Main()
{     
      Clk_init();  
      Led_init();
      Uart0_io_init();
      Uart0_init(115200);
      Dma_eint();
      pISR_DMA0 =(U32) Dma_isr;
      Dma_init();    
      while(1)
      {
       ;
      }  
      return 0;
}
Keywords:S3C2440 Reference address:S3C2440 Mini 2440 DMA mode to achieve Uart (serial port) communication

Previous article:Summary of reading NAND Flash from S3C2440
Next article:2440 Initialization Memory Principle (Continued from the previous article)

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号