I have done with memory to uart but not able to do uart to memory. Here is my code for memory to uart transfer.
/**************************************************************************** * $Id:: udmatest.c 6098 2011-01-08 02:26:20Z nxp12832 $ * Project: NXP LPC17xx UART DMA example * * Description: * This file contains UART test modules, main entry, to test UART APIs. * **************************************************************************** * Software that is described herein is for illustrative purposes only * which provides customers with programming information regarding the * products. This software is supplied "AS IS" without any warranties. * NXP Semiconductors assumes no responsibility or liability for the * use of the software, conveys no license or title under any patent, * copyright, or mask work right to the product. NXP Semiconductors * reserves the right to make changes in the software without * notification. NXP Semiconductors also make no representation or * warranty that such application will be suitable for the specified * use without further testing or modification. ****************************************************************************/ #include "LPC17xx.h" #include "uart_dma.h" #include "dma.h" #include "stdio.h"
#define MSEC_CNT 36000 /*!< 1msec with 60 MHz*/
extern uint32_t UARTDMA0Done; extern uint32_t UARTDMA1Done; extern uint32_t UARTDMA2Done; extern uint32_t UARTDMA3Done; uint8_t *u0_src, *u0_dst, *u1_src, *u1_dst;
/****************************************************************************** ** Main Function main() ******************************************************************************/ int main (void) { uint32_t i; uint8_t hex[17] = "Welcome..!!";
/* SystemClockUpdate() updates the SystemFrequency variable */ SystemClockUpdate();
UARTInit(0, 57600);
u0_src = (uint8_t *)UART0_DMA_TX_SRC; u0_dst = (uint8_t *)UART0_DMA_RX_DST; //*u0_src++ = 'J';
for ( i = 0; i < UART_DMA_SIZE; i++ ) // Put data in Memory (u0_src) { *u0_src++ =hex[i]; *u0_dst++ = 0; }
DMA_Init();
/* Connect UART0 and UART1 via a RS232 cable. The sequence is, UART DMA starts from UART0 TX, lookback to UART1 RX using channel 0 and 1. Then, UART DMA starts from UART1 TX, lookback to UART0 RX using channel 2 and 3. So, both M2P+P2M on UART0 and UART1 are tested. */
/* DMA from UART0 TX to UART1 RX using channel 0 and 1. */ DMAChannel_Init( 0, M2P);
/* Destination Peripheral - (DMA_UART0_TX<<6) Transfer Type - Memory to peripheral (0x01 << 11)
LPC_GPDMACH0->CConfig |= 0x0C001|(0x00<<1)|(DMA_UART0_TX<<6)|(0x01 << 11); LPC_UART0->FCR |= 0x08;
/* DMA request was sent inside DMA ISR when DMA is done. The data should arrive at UART0 RX already. */
while ( 1 ); }
void DMA_IRQHandler(void) { uint32_t regVal; regVal = LPC_GPDMA->IntTCStat; if ( regVal ) { DMATCCount++; LPC_GPDMA->IntTCClear = regVal; if ( regVal & (0x01<<0) ) { DMAChannel_Init( 1, P2M ); LPC_GPDMACH1->CConfig |= 0x0C001|(DMA_UART0_RX<<1)|(0x00<6)|(0x02<<11); //LPC_UART1->FCR |= 0x08; UARTDMA0Done = 1;
}
regVal = LPC_GPDMA->IntErrStat; if ( regVal ) { DMAErrCount++; LPC_GPDMA->IntErrClr = regVal; } return; }
void DMA_Init( void ) { /* Enable CLOCK into GPDMA controller */ LPC_SC->PCONP |= (1 << 29);
/* Select primary function(UART0/1/2/3) in DMA channels, secondary is timer 0/1/2/3. */ LPC_SC->DMAREQSEL = 0x0000; // UART0 TX is selected
LPC_GPDMA->IntTCClear = 0x03; //Interrupt Terminal Count Request Clear register LPC_GPDMA->IntErrClr = 0x03; //Interrupt Error Clear register
LPC_GPDMA->Config = 0x01; /* Enable DMA channels, little endian */ while ( !(LPC_GPDMA->Config & 0x01) );
NVIC_EnableIRQ(DMA_IRQn); return; }
uint32_t DMAChannel_Init( uint32_t ChannelNum, uint32_t DMAMode ) { if ( ChannelNum == 0 ) { UARTDMA0Done = 0; LPC_GPDMA->IntTCClear = 0x01<<0; LPC_GPDMA->IntErrClr = 0x01<<0; if ( DMAMode == M2P ) { /* Ch0 set for M2P transfer from mempry to UART. */ LPC_GPDMACH0->CSrcAddr = UART0_DMA_TX_SRC; LPC_GPDMACH0->CDestAddr = UART0_DMA_TX_DST; /* The burst size is set to 1, source and dest transfer width is 32 bits(word), Terminal Count Int enable */ LPC_GPDMACH0->CControl = (13 & 0x0FFF)|(0x02 << 12) |(0x02 << 15)|(0x00 << 18)|(0x00 << 21)|(1 << 26)|0x80000000; } else if ( DMAMode == P2M ) { /* Ch0 set for P2M transfer from UART to memory. */ LPC_GPDMACH0->CSrcAddr = UART0_DMA_RX_SRC; LPC_GPDMACH0->CDestAddr = UART0_DMA_RX_DST;
/* The burst size is set to 1. Terminal Count Int enable. */ LPC_GPDMACH0->CControl = (UART_DMA_SIZE & 0x0FFF)|(0x00 << 12) |(0x00 << 15)|(0x00 << 18)|(0x00 << 21)|(1 << 27)|0x80000000; } else { return ( FALSE ); } }
else { return ( FALSE ); } return( TRUE ); }
Some people just don't deserve assistance.
Those who understand this code please reply.
If you want people to read your code, it's up to you to present it clearly and in an easy-to-read format.
Does the code, as you've posted it, really look clear and easy-to-read to you? Would you be happy if someone presented you with code looking like that?
Do you not thing that indentation is worthwhile?
So you took the already broken code - after the forum thought it was normal flowing text and moved the position of line breaks - and reposted that code again instead of returning to your editor to get a copy of the original.
We don't read your code, if you don't spend enough time to read your code so you spot issues like:
} else { return ( FALSE ); } }
If you don't find it worth your time to make sure the post is good, then no one else in the world will spend any time either. It's way less important to us than it is to you - and it's obviously not important to you...