View previous topic :: View next topic |
Author |
Message |
georpo
Joined: 18 Nov 2008 Posts: 281 Location: Athens, Greece.
|
dspic33fj64gp804 DMA |
Posted: Sun Jul 22, 2018 5:29 am |
|
|
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
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
|
|
Posted: Sun Jul 22, 2018 6:46 am |
|
|
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
|
|
Posted: Sun Jul 22, 2018 9:47 am |
|
|
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.
|
|
Posted: Sun Jul 22, 2018 10:25 am |
|
|
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.
|
|
Posted: Sun Jul 22, 2018 10:35 am |
|
|
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.
|
|
Posted: Sun Jul 22, 2018 10:39 am |
|
|
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
|
|
Posted: Sun Jul 22, 2018 10:42 am |
|
|
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.
|
|
Posted: Sun Jul 22, 2018 10:49 am |
|
|
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. _________________ George. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19537
|
|
Posted: Sun Jul 22, 2018 10:55 am |
|
|
OK. Sounds as if they were too late in the code.
Glad it works now. |
|
|
|