lpcware

UART0 DMA PROBLEM

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by salamlora1 on Sun Aug 25 00:21:00 MST 2013
Hi all
i right a program for UART0 whit DMA it’s not work correctly any one can fine my mistake ???
  



#include <nxp/iolpc1768.h>
#include <stdio.h>
#include "gpio1768.h"
unsigned char h[]="1";
char a[2]="11";
void uart_init(unsigned short baud)
{
  unsigned short div;                                                 //PCONP |= 0x20210048 ;
  CLKOUTCFG = 0;
  div = (unsigned short)(10000000/(baud*16L));
  U0LCR = 0x83;
  U0DLL = (div);
  U0DLM = (div>>8);
  U0LCR &= ~(1<<7);
  PINSEL0 |= (1<<4);
  //U0FCR = 0x87;/* Enable and reset TX and RX FIFO. */
  U0FCR |= 0x87;
 
}

void dmacon(void)
{
  U0FCR = 0x87;
  PCONP = 0xffffffff;
  CCLKCFG = 0;
  PCONP |=(1<<29);
  DMACCONFIGURATION = 0x00000001;
  DMACC0CONFIGURATION = 0x00000001;
  DMACINTTCCLEAR = 0xff ;    //clear all interrupts
  DMACINTERRCLR = 0xff;  //eclear interrupt errors
  DMACC0SRCADDR = ( int ) &a;
  DMACC0DESTADDR = ( int ) &U0THR;
  DMACC0LLI =0;//(unsigned int ) &a[1];
  DMACC0CONTROL = sizeof(a);
  DMACC0CONTROL |= (1<<12);
  DMACC0CONFIGURATION |= (1<<0);
  DMACC0CONFIGURATION |= (1000<<6);
  DMACC0CONFIGURATION |= (1<<11);
  DMACC0CONFIGURATION |= 0x00000001;
  //delay(50000);
         
}
// PLL INIT

void pllinit (void)
{
//((FCCO = (2 × M × FIN) / N))
//"M" is bit of 14:0  PLL0CFG and "N" is bit of 23:16
        SCS = (0x00000001 << 5);          //Enable Main Oscillator
        SCS |= 0x00000020;                //Select the main Oscillator range
        PLL0CON &= ~0x01;                 //Disconnect the PLL
        PLL0FEED = 0xAA;
        PLL0FEED = 0x55;
        PLL0CON &= ~0x01;                 //Disconnect the PLL
        PLL0FEED = 0xAA;
        PLL0FEED = 0x55;                  //Write feed sequence
        while(!(SCS & 0x00000040));       //Wait untill Main Oscillator is stable
        CLKSRCSEL = 0x00000001;           //Select Main Oscillator as PLL Imput
        PLL0CFG = (0x000000A|0x00020000); //Write PLL Multipiler and Divider values
        PLL0FEED = 0xAA;
        PLL0FEED = 0x55;                  //Write Feed Sequence
        PLL0CON = 0x01;                   //Enable PLL
        PLL0FEED = 0xAA;
        PLL0FEED = 0x55;                  //Wriete Feed Sequence
        USBCLKCFG = 0x00000009;           //Write USBSEL Divider value
        CCLKCFG = 0x00000008;             //Write CPU Divider Value
        while(PLL0STAT & 0x000);          //Wait PLL for Lock
        PLL0CON |= 0x02;                  //Connect the PLL
        PLL0FEED = 0xAA;
        PLL0FEED = 0x55;
}
void main()
{ dmacon();
  U0TER = 0x80;
  U0FCR = 0x1;
  U0FCR = 0x87;
  pllinit();
  //dir0(24);
  //set0(24) ;
// PCLKSEL0 |=(1<<6);       //pish taghsim konanad e PCLK
  uart_init(9600);
  //delay(500);
  //delay(500);
//U0THR = '0';
//U0THR = '1';
//U0THR = '2';
//U0THR = '3';
//U0THR = '4';

  //U0FCR |=(1<<0);
  //U0FCR |=(1<<1);
  U0TER |= 0x80;
  while (1)
{
    delay(2);
    while( (U1LSR & (1<<5))== 0);
    uart_init(9600);
    U0TER = 0x80;
    dmacon();
    delay(10000) ;
}

}

Outcomes