DMA ram to ram - Page 1
Forum section: electronics / general

author: Nihi
author_rank: Newbie
timestamp: September 08, 2015, 08:59:35 pm
content: Hello everyone,I am trying the dma_led_pattern example on pic32mz ef sk Evaluation board. What it does is basically to load the bytes from the array to the port H every time the Timer goes overflow.It works fine.Now, I want to load this source-array into another Array instead of PORTH but while debugging I can't see any data in the destination array.Here the code that shows what I am trying to accomplish.Original working code:Code:const unsigned charLED_pattern[]={0x01,0x02,0x04,0x01,0x02,0x04,0x01,0x02,0x04,0x01,0x02,0x04,0x01,0x02,0x04,0x01,0x02,0x04,0x01,0x02,0x04,0x01,0x01,0x01};#include "framework/system/dma/sys_dma_static.h"void SYS_DMA_Channel0TransferAdd(void){/* Set the source and destinaton addresses (addresses are converted from virtual to physical) */PLIB_DMA_ChannelXSourceStartAddressSet(DMA_ID_0, DMA_CHANNEL_0, (uint32_t)LED_pattern);PLIB_DMA_ChannelXDestinationStartAddressSet(DMA_ID_0, DMA_CHANNEL_0, (uint32_t)&LATH);/* Set the source and destination sizes */PLIB_DMA_ChannelXSourceSizeSet(DMA_ID_0, DMA_CHANNEL_0, 24);PLIB_DMA_ChannelXDestinationSizeSet(DMA_ID_0, DMA_CHANNEL_0, 2);/* Set the number of bytes per transfer */PLIB_DMA_ChannelXCellSizeSet(DMA_ID_0, DMA_CHANNEL_0, 1);}my code:Code:const unsigned charLED_pattern[]={0x01,0x02,0x04,0x01,0x02,0x04,0x01,0x02,0x04,0x01,0x02,0x04,0x01,0x02,0x04,0x01,0x02,0x04,0x01,0x02,0x04,0x01,0x01,0x01};#include "framework/system/dma/sys_dma_static.h"volatile uint16_t LATHbuffer;void SYS_DMA_Channel0TransferAdd(void){/* Set the source and destinaton addresses (addresses are converted from virtual to physical) */PLIB_DMA_ChannelXSourceStartAddressSet(DMA_ID_0, DMA_CHANNEL_0, (uint32_t)LED_pattern);PLIB_DMA_ChannelXDestinationStartAddressSet(DMA_ID_0, DMA_CHANNEL_0, (uint32_t)&LATHbuffer);/* Set the source and destination sizes */PLIB_DMA_ChannelXSourceSizeSet(DMA_ID_0, DMA_CHANNEL_0, 24);PLIB_DMA_ChannelXDestinationSizeSet(DMA_ID_0, DMA_CHANNEL_0, 24);/* Set the number of bytes per transfer */PLIB_DMA_ChannelXCellSizeSet(DMA_ID_0, DMA_CHANNEL_0, 1);}The LATHbuffer is always empty showing 0x00.What am I doing wrong?I appreciate any help. Thank you in advance.

author: andersm
author_rank: Super Contributor
timestamp: September 09, 2015, 02:45:05 am
content: Try adding a memcmp to verify the contents of the buffer. IIRC MPLAB X has some problems with refreshing memory contents.

author: Nihi
author_rank: Newbie
timestamp: September 09, 2015, 06:46:15 am
content: Thank you for the Suggestion.I tried to check in the main Loop if the content of the destination buffer is ever > 0.But not luck.I am able to see the port H register changing but my buffer is not.

author: AndreasF
author_rank: Frequent Contributor
timestamp: September 09, 2015, 09:48:06 am
content: Quote from: Nihi on September 08, 2015, 08:59:35 pmI know nothing about PICs or the library they are using, but it strikes me as odd that you are using two ways of specifying the addresses of the arrays involved: a)only using the array name without any [], and b) explicitly using &arrayname. Theoretically both are equivalent, of course, and hsould work, but personally I would stick to one of the two options (the first).Also, why are the two arrays of different size/type (assuming unsigned char is an 8-bit value on PICs)?

author: Nihi
author_rank: Newbie
timestamp: September 09, 2015, 11:36:01 am
content: Quote from: AndreasF on September 09, 2015, 09:48:06 amThank you Andreas for your remarks.I know nothing about PICs or the library they are using, but it strikes me as odd that you are using two ways of specifying the addresses of the arrays involved: a)only using the array name without any [], and b) explicitly using &arrayname. Theoretically both are equivalent, of course, and hsould work, but personally I would stick to one of the two options (the first).--> In either ways with or without & + [ ] I get the same address. I have tried both I got the same result.I specified the first element of the array because I saw it in another Pic example provided by microchip.Also, why are the two arrays of different size/type (assuming unsigned char is an 8-bit value on PICs)?--> The elements of LED_pattern are 2-byte so I guess is the same if create an array of 16-bit elements. But let me try if keeping the same type it works out.