Setting Filters in CAN without init for CAN

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

Post Reply
r_romeo
Posts: 54
Joined: Wed Nov 02, 2011 3:57 pm
Has thanked: 14 times
Been thanked: 3 times
Contact:

Setting Filters in CAN without init for CAN

Post 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);

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Setting Filters in CAN without init for CAN

Post 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.

r_romeo
Posts: 54
Joined: Wed Nov 02, 2011 3:57 pm
Has thanked: 14 times
Been thanked: 3 times
Contact:

Re: Setting Filters in CAN without init for CAN

Post 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...

Mikat
Posts: 258
Joined: Wed Nov 29, 2006 6:32 pm
Location: Finland
Has thanked: 7 times
Been thanked: 36 times
Contact:

Re: Setting Filters in CAN without init for CAN

Post 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

r_romeo
Posts: 54
Joined: Wed Nov 02, 2011 3:57 pm
Has thanked: 14 times
Been thanked: 3 times
Contact:

Re: Setting Filters in CAN without init for CAN

Post 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.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Setting Filters in CAN without init for CAN

Post 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.

r_romeo
Posts: 54
Joined: Wed Nov 02, 2011 3:57 pm
Has thanked: 14 times
Been thanked: 3 times
Contact:

Re: Setting Filters in CAN without init for CAN

Post by r_romeo »

I am just testing the Compile to chip
here it goes:
TEST CAN FILTER CHANGE.fcf_pic16
(7.5 KiB) Downloaded 252 times

Mikat
Posts: 258
Joined: Wed Nov 29, 2006 6:32 pm
Location: Finland
Has thanked: 7 times
Been thanked: 36 times
Contact:

Re: Setting Filters in CAN without init for CAN

Post by Mikat »

Hi.
You need to check the use internal can box in the can ext properties menu...
Then the code compiles fine...

Mika

r_romeo
Posts: 54
Joined: Wed Nov 02, 2011 3:57 pm
Has thanked: 14 times
Been thanked: 3 times
Contact:

Re: Setting Filters in CAN without init for CAN

Post by r_romeo »

Those are the details that make me a really bad programmer
thanks Mikat!!

Post Reply