I want to send each other packages of about 5 bytes to uart use DMA. while each packet sent 1 I receive confirmation from the uart data using DMA.I change library lpc17xx.cmsis.driver.library \ uart_dma to do this. but the problem I can only send a single packet for the first time and received data packets .I can not be sent next packet I try to create a loop but can not be reset DMA after each send. What is my problem? is there a way to solve it?
#include "lpc17xx_uart.h" #include "lpc17xx_libcfg.h" #include "lpc17xx_gpdma.h" #include "lpc17xx_pinsel.h" #define RX_BUF_SIZE 0x47 /************************** PRIVATE VARIABLES *************************/ uint8_t menu1[] = "Hello NXP Semiconductors \n\r" "UART interrupt mode demo using ring buffer \n\r\t " "MCU LPC17xx - ARM Cortex-M3 \n\r\t " "UART0 - 9600bps \n\r" " This is a long string. It transferred in to DMA memory and transmit through Tx line \n\r" " on UART0 peripheral. To use UART with DMA mode, FIFO function must be enabled \n\r"; uint8_t reset[]={0x56,0x00,0x26,0x00}; uint8_t menu3[] = "UART demo terminated!\n"; uint8_t takepicture[]={0x56,0x00,0x36,0x01,0x00}; // Receive buffer __IO uint8_t rx_buf[RX_BUF_SIZE]; // Terminal Counter flag for Channel 0 __IO uint32_t Channel0_TC; // Error Counter flag for Channel 0 __IO uint32_t Channel0_Err; // Terminal Counter flag for Channel 1 __IO uint32_t Channel1_TC; // Error Counter flag for Channel 1 __IO uint32_t Channel1_Err; void DMA_IRQHandler (void); void print_menu(void); void DMA_IRQHandler (void) { ........like library } int c_entry(void) { uint8_t *rx_char; uint32_t idx,nn=0; // UART Configuration structure variable UART_CFG_Type UARTConfigStruct; // UART FIFO configuration Struct variable UART_FIFO_CFG_Type UARTFIFOConfigStruct; GPDMA_Channel_CFG_Type GPDMACfg; // Pin configuration for UART0 PINSEL_CFG_Type PinCfg; PinCfg.Funcnum = 1; PinCfg.OpenDrain = 0; PinCfg.Pinmode = 0; PinCfg.Pinnum = 2; PinCfg.Portnum = 0; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 3; PINSEL_ConfigPin(&PinCfg); UART_ConfigStructInit(&UARTConfigStruct); // Initialize UART0 peripheral with given to corresponding parameter UART_Init(LPC_UART0, &UARTConfigStruct); UART_FIFOConfigStructInit(&UARTFIFOConfigStruct); UARTFIFOConfigStruct.FIFO_DMAMode = ENABLE; UART_FIFOConfig(LPC_UART0, &UARTFIFOConfigStruct); UART_TxCmd(LPC_UART0, ENABLE); while(1){ // MY LOOP HERE GPDMA_Init(); NVIC_DisableIRQ (DMA_IRQn); NVIC_SetPriority(DMA_IRQn, ((0x01<<3)|0x01)); GPDMACfg.ChannelNum = 0; // Source memory if(nn==0) { #define RX_BUF_SIZE 0x47 GPDMACfg.SrcMemAddr = (uint32_t) &reset; //first package GPDMACfg.DstMemAddr = 0; GPDMACfg.TransferSize = sizeof(reset); } else { #define RX_BUF_SIZE 0x05 GPDMACfg.SrcMemAddr = (uint32_t) &takepicture; //The second package GPDMACfg.TransferSize = sizeof(takepicture); nn=0; } // Transfer width - don't care GPDMACfg.TransferWidth = 0; // Transfer type GPDMACfg.TransferType = GPDMA_TRANSFERTYPE_M2P; // Source connection - don't care GPDMACfg.SrcConn = 0; // Destination connection GPDMACfg.DstConn = GPDMA_CONN_UART0_Tx; // Linker List Item - unused GPDMACfg.DMALLI = 0; // Setup channel with given parameter GPDMA_Setup(&GPDMACfg); // Setup GPDMA channel -------------------------------- // channel 1 GPDMACfg.ChannelNum = 1; // Source memory - don't care GPDMACfg.SrcMemAddr = 0; // Destination memory GPDMACfg.DstMemAddr = (uint32_t) &rx_buf; // Transfer size GPDMACfg.TransferSize = sizeof(rx_buf); // Transfer width - don't care GPDMACfg.TransferWidth = 0; // Transfer type GPDMACfg.TransferType = GPDMA_TRANSFERTYPE_P2M; // Source connection GPDMACfg.SrcConn = GPDMA_CONN_UART0_Rx; // Destination connection - don't care GPDMACfg.DstConn = 0; // Linker List Item - unused GPDMACfg.DMALLI = 0; GPDMA_Setup(&GPDMACfg); /* Reset terminal counter */ Channel0_TC = 0; /* Reset Error counter */ Channel0_Err = 0; // Enable interrupt for DMA NVIC_EnableIRQ (DMA_IRQn); // Enable GPDMA channel 0 GPDMA_ChannelCmd(0, ENABLE); // Make sure GPDMA channel 1 is disabled GPDMA_ChannelCmd(1, DISABLE); /* Wait for GPDMA on UART0 Tx processing complete */ while ((Channel0_TC == 0) && (Channel0_Err == 0)); // Main loop - echos back to the terminal // while (1) { /* Reset terminal counter */ Channel1_TC = 0; /* Reset Error counter */ Channel1_Err = 0; // Setup channel with given parameter GPDMA_Setup(&GPDMACfg); // Enable GPDMA channel 1 GPDMA_ChannelCmd(1, ENABLE); // Clear Rx buffer using DMA for (idx = 0; idx < RX_BUF_SIZE; idx++){ rx_buf[idx] = 0; } // now, start receive character using GPDMA rx_char = (uint8_t *) &rx_buf; while ((Channel1_TC == 0) && (Channel1_Err == 0)) { // Check whether if there's any character received, then print it back if (*rx_char != 0) { if(*rx_char ==0x0A){break;} UART_Send(LPC_UART0, rx_char, 1, BLOCKING); //function character is received on the hyper terminal rx_char++; } } nn++; } } return 1; } int main(void) { return c_entry(); }