Author Topic: dsPIC33 ECAN Peripheral config  (Read 1966 times)

0 Members and 1 Guest are viewing this topic.

Offline fdallaTopic starter

  • Newbie
  • Posts: 4
  • Country: it
dsPIC33 ECAN Peripheral config
« on: September 21, 2018, 03:30:05 pm »
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: [Select]

// Assign Number of Buffers Used by ECAN Module in DMA Memory Space
C1FCTRLbits.DMABS=0b010; // 4 CAN Messages to be buffered in DMA RAM and
// FIFO Start Area TX/RX buffer TRB0

C1CTRL1bits.WIN=0b1; // enable window to access the filter configuration registers

// ------------------------------ Set Up Filters and Masks -------------------------------
C1FMSKSEL1bits.F0MSK=0; // select acceptance mask 0 filter 0
C1RXM0SID=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 only
C1RXF0SID=CAN_FILTERSTD(C1RXF0SID);
C1BUFPNT1bits.F0BP=0b0001; // acceptance filter to use buffer 1 for incoming messages
C1FEN1bits.FLTEN0=1; // enable filter 0

C1FMSKSEL1bits.F1MSK=0; // select acceptance mask 0 filter 1
w = (FILTRO_RSDO1 << 7) + id;
C1RXF1SID=CAN_FILTERMASK2REG_SID(w);
C1RXM1SID=CAN_SETMIDE(C1RXM1SID); // set filter to check for standard ID and accept standard id only
C1RXF1SID=CAN_FILTERSTD(C1RXF1SID);
C1BUFPNT1bits.F1BP=0b0010; // acceptance filter to use buffer 2 for incoming messages
C1FEN1bits.FLTEN1=1; // enable filter 1

C1FMSKSEL1bits.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 only
C1RXF2SID=CAN_FILTERSTD(C1RXF2SID);
C1BUFPNT1bits.F2BP=0b0011; // acceptance filter to use buffer 3 for incoming messages
C1FEN1bits.FLTEN2=1; // enable filter 2


After 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?
 

Offline NorthGuy

  • Super Contributor
  • ***
  • Posts: 3248
  • Country: ca
Re: dsPIC33 ECAN Peripheral config
« Reply #1 on: September 21, 2018, 04:32:31 pm »
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.

There's a WIN bit which switches register spaces. Are you sure it is still set when you watch the filters in the debugger?
 

Offline JPortici

  • Super Contributor
  • ***
  • Posts: 3527
  • Country: it
Re: dsPIC33 ECAN Peripheral config
« Reply #2 on: September 22, 2018, 09:17:29 am »
Try to post your whole code
 

Offline fdallaTopic starter

  • Newbie
  • Posts: 4
  • Country: it
Re: dsPIC33 ECAN Peripheral config
« Reply #3 on: September 22, 2018, 04:54:39 pm »
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.

There's a WIN bit which switches register spaces. Are you sure it is still set when you watch the filters in the debugger?

Yes, 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.
« Last Edit: September 22, 2018, 05:01:57 pm by fdalla »
 

Offline fdallaTopic starter

  • Newbie
  • Posts: 4
  • Country: it
Re: dsPIC33 ECAN Peripheral config
« Reply #4 on: September 22, 2018, 05:01:23 pm »
Try to post your whole code

At 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: [Select]

C1RXF3SID |= 0x1000; //i try to set a bit of the register of filter id 3

asm("NOP");
asm("NOP"); //here i stop the debugger
asm("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.
 

Offline NorthGuy

  • Super Contributor
  • ***
  • Posts: 3248
  • Country: ca
Re: dsPIC33 ECAN Peripheral config
« Reply #5 on: September 22, 2018, 07:21:12 pm »
Might be a bug in the debugger. Try reading the register and light up a LED if the bit is set.
 
The following users thanked this post: fdalla

Offline fdallaTopic starter

  • Newbie
  • Posts: 4
  • Country: it
Re: dsPIC33 ECAN Peripheral config
« Reply #6 on: September 24, 2018, 07:15:56 am »
Yep. Bug in the debugger. See photo attached.

Thanks!
 
The following users thanked this post: JPortici


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf