Page 1 of 1

Setting Filters in CAN without init for CAN

Posted: Mon Mar 26, 2012 10:03 am
by r_romeo
I need a macro to setup the filter configuration for the CAN
module other than the init provided by FLOWCODE
(the filter IDs must be provided by other electronic module or DIP configuration)

I know similar is the set up for the TX_ID is the code below,the wich is redundant with the INIT setting, but I am getting
confused converting this code to Filter, since I am not "C" programmer,
can someone help me?



//this is the definition for setting the TX ID variable

static void FCD_CAN0_SetTxID(char buffer, char hi, char lo);

//-------------------------------------------------------------------------------------------

// this is the definition of the component macro FCD_CAN0_SetTxID


static void FCD_CAN0_SetTxID(char buffer, char hi, char lo)
{

// Code_SetTxID
if (buffer > CAN_MAX_TX_BUF)
{
return;
}

#ifdef USE_INT_CAN

switch(buffer)
{
case 0:
C1TX0SID = ((hi << 5) | (lo >> 3)) & 0x00FF; //Transmit Buffer 0 S-ID
C1TX0SID = C1TX0SID | ((hi << 8) & 0xFF00);
break;
case 1:
C1TX1SID = ((hi << 5) | (lo >> 3)) & 0x00FF; //Transmit Buffer 1 S-ID
C1TX1SID = C1TX1SID | ((hi << 8) & 0xFF00);
break;
case 2:
C1TX2SID = ((hi << 5) | (lo >> 3)) & 0x00FF; //Transmit Buffer 2 S-ID
C1TX2SID = C1TX2SID | ((hi << 8) & 0xFF00);
break;
}

#else

char i;
char id_addr = TXBxSIDH(buffer);

//enable SPI
clear_bit(MX_CAN_CS_PORT, CAN_CHIPSEL);

FCD_CAN0_SPI_SendByte(CAN_WRITE); //CAN write mode
FCD_CAN0_SPI_SendByte(id_addr); //start writting at hi id address
FCD_CAN0_SPI_SendByte(hi); //send the Hi ID value
FCD_CAN0_SPI_SendByte(lo); //send the Lo ID value

//disable SPI
set_bit(MX_CAN_CS_PORT, CAN_CHIPSEL);

#endif

}


//-------------------------------------------------------------------------------------------
// then we call the component macro after in MAIN


FCD_CAN0_SetTxID(0, 86, 64);

Re: Setting Filters in CAN without init for CAN

Posted: Mon Mar 26, 2012 5:03 pm
by Benj
Hello,

Are you using internal or external CAN?

You should be able to do everything using a Flowcode macro and some C icons.

Let me know and I will have a crack at putting together an example.

Re: Setting Filters in CAN without init for CAN

Posted: Mon Mar 26, 2012 5:32 pm
by r_romeo
Hi Ben,

I am using internal CAN with a dsPIC30f4012, I was looking at the code,
but arrived seen that should be pretty similar to the
"set tx id", ie, a redundant code that overwrites the init settings...

Re: Setting Filters in CAN without init for CAN

Posted: Thu Mar 29, 2012 7:15 am
by Mikat
Hi.

So are you looking way to change RX filters and masks without init?
Because the TX "filter"(ID) has macro to change...
If you are try this:

Code: Select all

C1CTRLbits.REQOP = 4; //request to config mode
 while( C1CTRLbits.OPMODE != 4 ); //loop untill config mode NOT TESTED!!
C1RXF2SID = 472 << 2; //filter 2 472
C1RXF3SID = 1626 << 2;
C1RXF4SID = 344 << 2;
C1RXF5SID = 192 << 2;
C1RXM1SID = 2047 << 2; //mask 1 2047
C1CTRLbits.REQOP = 0; //request to normal mode
 while( C1CTRLbits.OPMODE != 0 ); //loop untill normal mode NOT TESTED!! 
Just put that code in the c code block.
And if you want to use flowcode variable like "filter2", just replace the 472 at the FCV_FILTER2..
Everything else should work (tested at 30f6012a), but those while loops I haven't tested, just used 10ms delays.

Mika

Re: Setting Filters in CAN without init for CAN

Posted: Fri Mar 30, 2012 9:52 am
by r_romeo
Thanks Mikat, I tried to just open a C code block and paste your code but when I try to compile to the chip I get this errors:
I guess is my lack of C and probably I am doing some silly mistake
Would you attach a file that compiles to a chip? then I will see what I am missing in the flowcode setting.
thanks !!!


Launching the compiler...
C:\Program Files (x86)\Matrix Multimedia\Flowcode PIC24&dsPIC V4\Tools\MX_bats\pic16_C30_comp.bat "TEST CAN TX CHANGE" "C:\Users\Raul\Desktop\FLOWCODE" 30F4012

C:\Users\Raul\Desktop\FLOWCODE>pic30-gcc -c -mcpu=30F4012 -funsigned-char -fno-short-double -Os -I"C:\PROGRA~2\MATRIX~1\FLOWCO~1\Tools\MX_bats\..\C_tools\support\h" -I"C:\PROGRA~2\MATRIX~1\FLOWCO~1\Tools\MX_bats\..\MX_support" -Wall -std=gnu99 "TEST CAN TX CHANGE".c -o "TEST CAN TX CHANGE".o
TEST CAN TX CHANGE.c: In function 'FCD_CAN0_CAN_ReadRX_ID_and_Data':
TEST CAN TX CHANGE.c:1303: warning: array subscript has type 'char'
TEST CAN TX CHANGE.c:1305: warning: array subscript has type 'char'
TEST CAN TX CHANGE.c: In function 'FCD_CAN0_Init':
TEST CAN TX CHANGE.c:1481: warning: large integer implicitly truncated to unsigned type
TEST CAN TX CHANGE.c: In function 'FCD_CAN0_GetRxData':
TEST CAN TX CHANGE.c:1894: warning: array subscript has type 'char'
TEST CAN TX CHANGE.c: In function 'FCD_CAN0_SetTxData':
TEST CAN TX CHANGE.c:2026: warning: unused variable 'i'
TEST CAN TX CHANGE.c: In function 'FCD_CAN0_SetTxID':
TEST CAN TX CHANGE.c:2115: warning: unused variable 'i'
TEST CAN TX CHANGE.c: In function 'main':
TEST CAN TX CHANGE.c:2179: error: syntax error before numeric constant
TEST CAN TX CHANGE.c:2186: error: syntax error before numeric constant

Error returned from [pic30-gcc.exe]

Return code = 1

Flowcode was unable to compile the flowchart's C code due to the following errors:


If your flowchart contains C code, please review this carefully. If your flowchart contains no C-code or you have thoroughly reviewed the code, contact Technical Support.

Re: Setting Filters in CAN without init for CAN

Posted: Fri Mar 30, 2012 12:27 pm
by Benj
Hello,

Could you post up your C file so we can see what line numbers 2179 and 2186 refer to? Flowcode program would also be handy so we can try a test compile here.

Re: Setting Filters in CAN without init for CAN

Posted: Sat Mar 31, 2012 10:54 am
by r_romeo
I am just testing the Compile to chip
here it goes:
TEST CAN FILTER CHANGE.fcf_pic16
(7.5 KiB) Downloaded 312 times

Re: Setting Filters in CAN without init for CAN

Posted: Sat Mar 31, 2012 7:07 pm
by Mikat
Hi.
You need to check the use internal can box in the can ext properties menu...
Then the code compiles fine...

Mika

Re: Setting Filters in CAN without init for CAN

Posted: Sun Apr 01, 2012 1:21 pm
by r_romeo
Those are the details that make me a really bad programmer
thanks Mikat!!