![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
tripper269
Joined: 06 May 2013 Posts: 33 Location: Toronto
|
dsPIC33 DMA loop back |
Posted: Fri Mar 18, 2016 7:15 am |
|
|
Hi there,
I am working on DSC dsPIC33 starter kit DM330011. I am using CCS v5 in MplabX environment. The Kit comes with WM8510 codec and connected with dsPIC through DCI and I2C. I have already tested generating tone with codec and playing it on speaker. Now I want to read a signal from CODEC and by using DMA (with minimum CPU involvement), loop it back to CODEC. I completed it with copying the signal with for loop
Code: |
for(n=0;n++;n<128)
BufferA[n] = BufferB[n];
|
What I am trying now is read BufferA and write BufferB and then read BufferB and write BufferA. I think the best way to do this is using user flag in DMA interrupts
Code: |
#INT_DMA1
void dma1_isr()
{
clear_interrupt(INT_DMA1);
Rxflag++;
}
#INT_DMA2
void dma2_isr()
{
clear_interrupt(INT_DMA2);
Txflag++;
} |
and then
Code: |
if(Rxflag == 1 && Txflag == 1)
{
dma_start(1, DMA_ONE_SHOT ,BufferB,FRAME_SIZE-1);
dma_start(2, DMA_ONE_SHOT ,BufferA,FRAME_SIZE-1);
}
if(Rxflag == 2 && Txflag == 2)
{
Rxflag = 0;
Txflag = 0;
dma_start(1, DMA_ONE_SHOT ,BufferA,FRAME_SIZE-1);
dma_start(2, DMA_ONE_SHOT ,BufferB,FRAME_SIZE-1);
}
|
Please suggest, Thanks |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19381
|
|
Posted: Fri Mar 18, 2016 8:59 am |
|
|
Get rid of the clear_interrupt calls. Pointless.
Read the CCS manual on interrupts. Understand that unless you tell it not to (NOCLEAR option), the compiler will always clear the interrupt for you.
Simplest solution is to use a toggle:
Code: |
int8 rx_buffer_number=0;
int8 tx_buffer_number=0;
#int_dma1
void dma1_isr()
{
rx_buffer_number ^=1;
}
//etc. for other interrupt
//Then why not have a two dimensional array?.
if (rx_buffer_number==tx_buffer_number)
{
dma_start(1, DMA_ONE_SHOT ,&bufferA[0][rx_buffer_number], FRAME_SIZE-1);
dma_start(2, DMA_ONE_SHOT ,&bufferB[0][tx_buffer_number], FRAME_SIZE-1);
}
|
As a comment though, I'd have expected to want to alternate the value, so you receive to buffer0, toggle this byte to 1, so you start to receive to buffer1, then send buffer0. |
|
![](templates/subSilver/images/spacer.gif) |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|