dsPIC33 ECAN Peripheral config - Page 1
Forum section: electronics / general

author: fdalla
author_rank: Newbie
timestamp: September 21, 2018, 03:30:05 pm
content: Hi there,Can somebody help me with the configuration of the Enhanced CAN peripheral of dsPIC33FJ128GP804 ?I'm using a CAN driver (unfortunately i'm obliged to use it) that realizes communication with messages that use standard ID (11bits).For the purpose of making the application compatible to other stuff, i have to handle also extended ID messages. So I figured out that the quickest way for me to sort it would be to initialize another filter in the can peripheral, which would be dedicated to extended ID messages.To do so, i tried to modify the Can_Init() function, in which i could find already the settings of the other filters which were already used for standard messages.Here the part of code related to the filters and masks of the peripheral:Code:// Assign Number of Buffers Used by ECAN Module in DMA Memory SpaceC1FCTRLbits.DMABS=0b010;// 4 CAN Messages to be buffered in DMA RAM and// FIFO Start Area TX/RX buffer TRB0C1CTRL1bits.WIN=0b1;// enable window to access the filter configuration registers// ------------------------------ Set Up Filters and Masks -------------------------------C1FMSKSEL1bits.F0MSK=0;// select acceptance mask 0 filter 0C1RXM0SID=CAN_FILTERMASK2REG_SID(0x7FF);w = (FILTRO_NMT_ERR_CTRL << 7) + id;C1RXF0SID = CAN_FILTERMASK2REG_SID(w);C1RXM0SID=CAN_SETMIDE(C1RXM0SID);// set filter to check for standard ID and accept standard id onlyC1RXF0SID=CAN_FILTERSTD(C1RXF0SID);C1BUFPNT1bits.F0BP=0b0001;// acceptance filter to use buffer 1 for incoming messagesC1FEN1bits.FLTEN0=1;// enable filter 0C1FMSKSEL1bits.F1MSK=0;// select acceptance mask 0 filter 1w = (FILTRO_RSDO1 << 7) + id;C1RXF1SID=CAN_FILTERMASK2REG_SID(w);C1RXM1SID=CAN_SETMIDE(C1RXM1SID);// set filter to check for standard ID and accept standard id onlyC1RXF1SID=CAN_FILTERSTD(C1RXF1SID);C1BUFPNT1bits.F1BP=0b0010;// acceptance filter to use buffer 2 for incoming messagesC1FEN1bits.FLTEN1=1;// enable filter 1C1FMSKSEL1bits.F2MSK=0;// select acceptance mask 0 filter 2//w = (FILTRO_NMT << 7) + id;w = (FILTRO_NMT << 7);C1RXF2SID=CAN_FILTERMASK2REG_SID(w);C1RXM2SID=CAN_SETMIDE(C1RXM2SID);// set filter to check for standard ID and accept standard id onlyC1RXF2SID=CAN_FILTERSTD(C1RXF2SID);C1BUFPNT1bits.F2BP=0b0011;// acceptance filter to use buffer 3 for incoming messagesC1FEN1bits.FLTEN2=1;// enable filter 2After i saw this bunch of code, i tried adding mine in a similar way to the other filters, to configure filter 3, that was not used already.Unfortunately, even if the code was practically identical, i could not find a way to modify SFRs: C1RXF3SID and C1RXF3EID (simply assigning random values to them did not affect them) .I am sure of what i am saying because i can look at the memory while executing the code, with ICD 3 debugger.Can somebody help me?

author: NorthGuy
author_rank: Super Contributor
timestamp: September 21, 2018, 04:32:31 pm
content: Quote from: fdalla on September 21, 2018, 03:30:05 pmThere's a WIN bit which switches register spaces. Are you sure it is still set when you watch the filters in the debugger?

author: JPortici
author_rank: Super Contributor
timestamp: September 22, 2018, 09:17:29 am
content: Try to post your whole code

author: fdalla
author_rank: Newbie
timestamp: September 22, 2018, 04:54:39 pm
content: Quote from: NorthGuy on September 21, 2018, 04:32:31 pmYes, i know that, in fact i put a few nops before clearing WIN bit to prevent not being able to read correctly the registers. And i stopped the program counter at those nops to read the memory.

author: fdalla
author_rank: Newbie
timestamp: September 22, 2018, 05:01:23 pm
content: Quote from: JPortici on September 22, 2018, 09:17:29 amAt the moment I don't have access to my code, as i'm not in office.Imagine that after the code i posted there were these few lines:Code:C1RXF3SID |= 0x1000; //i try to set a bit of the register of filter id 3asm("NOP");asm("NOP"); //here i stop the debuggerasm("NOP");after stopping the debugger i look at filter 3's id register and I don't see it change.For masks registers it is different, I can edit them.One other thing that i realized, is that the problem it is not only about filter 3: i tried editing the filter 15 id register, and i could not do it either.Really don't know why.

author: NorthGuy
author_rank: Super Contributor
timestamp: September 22, 2018, 07:21:12 pm
content: Might be a bug in the debugger. Try reading the register and light up a LED if the bit is set.

author: fdalla
author_rank: Newbie
timestamp: September 24, 2018, 07:15:56 am
content: Yep. Bug in the debugger. See photo attached.Thanks!