CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

dspic33fj64gp804 DMA

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
georpo



Joined: 18 Nov 2008
Posts: 281
Location: Athens, Greece.

View user's profile Send private message

dspic33fj64gp804 DMA
PostPosted: Sun Jul 22, 2018 5:29 am     Reply with quote

Hello,

In my latest project I use CAN1 module for reading data from ODBII
which worked fine based on CCS library (can-pic24.c). This library uses DMA channels 0 and 1 and defines the buffer in DMA.

Code:

// Buffer for CAN1
#if CAN_BUFFER_SIZE==4
   #BANK_DMA
   uint16_t ecan1_message_buffer[4][8];
#elif CAN_BUFFER_SIZE==6
   #BANK_DMA
   uint16_t ecan1_message_buffer[6][8];
#elif CAN_BUFFER_SIZE==8
   #BANK_DMA
   uint16_t ecan1_message_buffer[8][8];
#elif CAN_BUFFER_SIZE==12
   #BANK_DMA
   uint16_t ecan1_message_buffer[12][8];
#elif CAN_BUFFER_SIZE==16
   #BANK_DMA
   uint16_t ecan1_message_buffer[16][8];
#elif CAN_BUFFER_SIZE==24
   #BANK_DMA
   uint16_t ecan1_message_buffer[24][8];
#else
   #BANK_DMA
   uint16_t ecan1_message_buffer[32][8];
#endif


All good.

Now, I also want to use DMA for both USART TX modules which also works well for both of them. I am using DMA channels 2 and 3.

My DMA buffers:

Code:

#BANK_DMA unsigned char TX2BUFF[100];      
#BANK_DMA unsigned char TX1BUFF[50];



The problem is that when I define my buffers in DMA then the CAN does not work.

I have to comment out the USART #BANK_DMA for the CAN to operate.

They cannot co-extist Shocked

I also tried to put them under the same #BANK_DMA but no luck.

What am I doing wrong???

Thanks in advance.
_________________
George.
Ttelmah



Joined: 11 Mar 2010
Posts: 19537

View user's profile Send private message

PostPosted: Sun Jul 22, 2018 6:46 am     Reply with quote

A #bank_dma expression just puts the next variable in the dma bank. Trying to put multiple variables would not work.
There is no reason that they should interfere, provided the names are different, channels are different, and there is enough DMA area for all variables.

Can2, uses DMA2 & DMA3. I'd suspect this is where your problem lies. You have 8 DMA channels, use DMA4 & 5, rather than 2 & 3.
newguy



Joined: 24 Jun 2004
Posts: 1909

View user's profile Send private message

PostPosted: Sun Jul 22, 2018 9:47 am     Reply with quote

Are you explicitly #locate(ing) the arrays in DMA memory? I have used DMA for CAN, UART, and one other thing I can't remember at the moment with no issues, but I manually placed the arrays in DMA memory using #locate.
georpo



Joined: 18 Nov 2008
Posts: 281
Location: Athens, Greece.

View user's profile Send private message

PostPosted: Sun Jul 22, 2018 10:25 am     Reply with quote

Thanks both for the replies.

Do I have to put all #BANK_DMA expressions in one place in the code?
I will try to use channels 4 & 5, it was the next thing to do anyway even though I comment out the block of code that sets CAN2 to channels 2 & 3.

@newguy, No I do not explicitly #locate the arrays. I do not know how.
_________________
George.
georpo



Joined: 18 Nov 2008
Posts: 281
Location: Athens, Greece.

View user's profile Send private message

PostPosted: Sun Jul 22, 2018 10:35 am     Reply with quote

I just tried using DMA channels 4 & 5 for my USARTs.
Again I have to comment out the expressions below for CAN1 to operate:
Code:

//#BANK_DMA
//unsigned char TX2BUFF[100];      
//#BANK_DMA
//unsigned char TX1BUFF[50];


The expressions above are placed high in my code before my PicInit() and Main() functions and the CAN library exressions for #BANK_DMA are placed and called after the Main(). If this matters...
_________________
George.
georpo



Joined: 18 Nov 2008
Posts: 281
Location: Athens, Greece.

View user's profile Send private message

PostPosted: Sun Jul 22, 2018 10:39 am     Reply with quote

I got it:
You have to place all #BANK_DMA expressions together.

Code:

   #BANK_DMA
   uint16_t ecan1_message_buffer[32][8];
   #BANK_DMA
   unsigned char TX2BUFF[100];      
   #BANK_DMA
   unsigned char TX1BUFF[50];

_________________
George.
Ttelmah



Joined: 11 Mar 2010
Posts: 19537

View user's profile Send private message

PostPosted: Sun Jul 22, 2018 10:42 am     Reply with quote

The bank_dma declarations should be before all code that uses them.
They are like global variable declarations declaring these variables to be in the dma bank.
So you are saying that you don't have to make any declarations using the uart dma at all?. Just adding the bank_dma declarations for the serial buffers results in the CAN not working?.
If so, the first thing to do is a simple string search of the CAN project and verify that it doesn't contain any variable called TX2BUFF or TX1BUFF. It's quite likely that it does. The compiler won't complain if this is the case, since the bank_dma declaration can be used to relocate an existing variable, but then the declaration would cause problems....
georpo



Joined: 18 Nov 2008
Posts: 281
Location: Athens, Greece.

View user's profile Send private message

PostPosted: Sun Jul 22, 2018 10:49 am     Reply with quote

Quote:

Just adding the bank_dma declarations for the serial buffers results in the CAN not working?.

Yes exactly!
I even commented out the setup_dma commands for for UARTS and again CAN did not work. Actually it works but sends garbage.

I searched all the project for variable called TX2BUFF or TX1BUFF.
I only found the ones that I declare and use. Nothing more.

Now, after placing them all together, everything is OK. Cool
_________________
George.
Ttelmah



Joined: 11 Mar 2010
Posts: 19537

View user's profile Send private message

PostPosted: Sun Jul 22, 2018 10:55 am     Reply with quote

OK. Sounds as if they were too late in the code.
Glad it works now. Smile
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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