UART using DMA on FRDM-KL25Z128

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

UART using DMA on FRDM-KL25Z128

1,158 Views
yadhukrishnanvm
Contributor III

Hi,

I have completed uart transmission on FRDM-KL25Z  using DMAChannel_LDD and Init_UART components in code warrier.I am using UART0 of the kl25z, the pins are setup as PTA1 and PTA2 which are connect to OpenSDA port. I got the correct output using the below code.

/* Including needed modules to compile this module/procedure */

#include "Cpu.h"
#include "Events.h"
#include "DMACH1.h"
#include "DMA1.h"
#include "UART0.h"
/* Including shared modules, which are used for whole project */
#include "PE_Types.h"
#include "PE_Error.h"
#include "PE_Const.h"
#include "IO_Map.h"

void StartApp(void);


uint8_t dmaSrc[]="\fHello Yadu Bro\r\n ";/* array used as source for DMA to set uart */

void StartApp(void) {

DMA_PDD_SetSourceAddress(DMA_BASE_PTR, DMA_PDD_CHANNEL_0, (uint32_t)&dmaSrc[0]); /* set destination address */
DMA_PDD_SetSourceAddressModulo(DMA_BASE_PTR, DMA_PDD_CHANNEL_0, DMA_PDD_CIRCULAR_BUFFER_16_BYTES); /* circular buffer with 32 bytes */
DMA_PDD_EnableSourceAddressIncrement(DMA_BASE_PTR, DMA_PDD_CHANNEL_0, PDD_ENABLE); /* source address will be incremented by transfer size */
DMA_PDD_SetSourceDataTransferSize(DMA_BASE_PTR, DMA_PDD_CHANNEL_0, DMA_PDD_8_BIT); /* Transfer from source size is 16bit */

DMA_PDD_SetDestinationAddress(DMA_BASE_PTR, DMA_PDD_CHANNEL_0, (uint32_t)&UART0_D); /* set destination address */
DMA_PDD_SetDestinationAddressModulo(DMA_BASE_PTR, DMA_PDD_CHANNEL_0, DMA_PDD_CIRCULAR_BUFFER_DISABLED); /* no circular buffer */
DMA_PDD_EnableDestinationAddressIncrement(DMA_BASE_PTR, DMA_PDD_CHANNEL_0, PDD_DISABLE); /* no auto-increment for destination address */
DMA_PDD_SetDestinationDataTransferSize(DMA_BASE_PTR, DMA_PDD_CHANNEL_0, DMA_PDD_8_BIT); /* Transfer to destination size is 16bit */

DMA_PDD_SetByteCount(DMA_BASE_PTR, DMA_PDD_CHANNEL_0, sizeof(dmaSrc)); /* set number of bytes to transfer */
DMA_PDD_EnableTransferCompleteInterrupt(DMA_BASE_PTR, DMA_PDD_CHANNEL_0, PDD_ENABLE); /* request interrupt at the end of the DMA transfer to set new byte count */
DMA_PDD_EnablePeripheralRequest(DMA_BASE_PTR, DMA_PDD_CHANNEL_0, PDD_ENABLE); /* enable request from peripheral */

Cpu_EnableInt(); /* enable interrupts */

for(;;) {
/* just wait here, DMA will do the work.... */
}
}

int main(void)

{

PE_low_level_init();

StartApp();

#ifdef PEX_RTOS_START
PEX_RTOS_START();
#endif

for(;;){}
}

Now I want to receive the data through the receiver when I type letters in keyboard. What changes I have to made on above code to receive the characters. Please help! 

0 Kudos
4 Replies

745 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Yadhukrishnan V M,

    About the UART DMA receive code in the KL25, please refer to my attached code.

   This code is using the DMA put the uart received data to the SRAM.

   Actually, you just need to configure the DMA source address as UART0_D, the destination address as the SRAM, and  destination address will be incremented after each transfer.

Wish it helps you!


Have a great day,
Kerry

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

745 Views
yadhukrishnanvm
Contributor III

Thanks for the help. Do you have spi code using DMAChannel_LDD component?

0 Kudos

745 Views
kerryzhou
NXP TechSupport
NXP TechSupport

No, I don't have it, I just have the bare bone code which I already give you.

You can refer to my code and write it in your project.


Have a great day,
Kerry

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

745 Views
yadhukrishnanvm
Contributor III

Its okay..anyway thanks...

0 Kudos