CAN Set Rx ID

For C and ASSEMBLY users to post questions and code snippets for programming in C and ASSEMBLY. And for any other C or ASM course related questions.

Moderators: Benj, Mods

Post Reply
63rjb
Posts: 4
Joined: Wed Oct 05, 2011 12:53 pm
Has thanked: 1 time
Contact:

CAN Set Rx ID

Post by 63rjb »

Hello,

In flowcode you can ad the CAN macro SetTxID, now i also want to do this with the Rx ID.
Is this possible to do? i think it can be done with C code i have looked ad it and tried some butt i don't get it working.
I think its complex to do, any one who has done this before or can help me with this?

Thanks, Regards,
Ronny

Sean
Valued Contributor
Valued Contributor
Posts: 548
Joined: Tue Jun 26, 2007 11:23 am
Has thanked: 6 times
Been thanked: 44 times
Contact:

Re: CAN Set Rx ID

Post by Sean »

The thread linked below shows how receive filters can be reprogrammed using C after the Flowcode component has initialized the CAN controller with default values. The new filter values can be based on calculations and changed on-the-fly.

This technique can also be used to change other settings (masks, data rate, etc.). The C code generated by Flowcode (particularly the CAN initialization functions) can be used to show how the CAN controller registers are programmed.

http://www.matrixmultimedia.com/mmforum ... f=6&t=8925

63rjb
Posts: 4
Joined: Wed Oct 05, 2011 12:53 pm
Has thanked: 1 time
Contact:

Re: CAN Set Rx ID

Post by 63rjb »

Thanks Sean,

I tried a bit with it, butt i'm not so good with C code.
Where in the code i can change the Rx ID?
Can you give a example C code for changing the RX ID into 200?

Sean
Valued Contributor
Valued Contributor
Posts: 548
Joined: Tue Jun 26, 2007 11:23 am
Has thanked: 6 times
Been thanked: 44 times
Contact:

Re: CAN Set Rx ID

Post by Sean »

There is no specific Rx ID. The controller chip contains several filters and filter masks that allow individual message IDs, or groups of IDs, to accepted by individual Rx buffers.

The example in the linked thread should do what you need. The section upto and including the first delay_10us command reprograms the first filter from a Flowcode variable. The last section (from the final //disable SPI comment) completes the operation.

The Flowcode CAN component must already be loaded and setup for the appropriate filter operation (the C code uses some functions from the CAN component).

The main Flowcode program must contain a variable called Mod_req (automatically converted to FCV_MOD_REQ in the Flowcode C file). This is used in the C code program to change the receive filter value.

The register configuration of the CAN controller chip requires the filter value to be set as the required CAN ID multiplied by 32.

Example:
Required ID = 200 (0xc8)
Value of Mod_req = 6400 (0x1900)

63rjb
Posts: 4
Joined: Wed Oct 05, 2011 12:53 pm
Has thanked: 1 time
Contact:

Re: CAN Set Rx ID

Post by 63rjb »

I'm get the following error's? if i try to send the flowcode to the chip.
i have the variable Mod_req

Flowcode2.c(1866:25): error: unknown identifier 'FCV_MOD_INT'
Flowcode2.c(1866:25): error: invalid operand 'FCV_MOD_INT'
Flowcode2.c(1866:37): error: failed to generate expression
Flowcode2.c(1866:23): error: arguments of 'FCD_CAN0_SPI_SendByte' don't match the parameters of call
Flowcode2.c(1866:2): error: failed to generate expression
Flowcode2.c(1867:24): error: unknown identifier 'FCV_MOD_INT'
Flowcode2.c(1867:23): error: arguments of 'FCD_CAN0_SPI_SendByte' don't match the parameters of call
Flowcode2.c(1867:2): error: failed to generate expression

Sean
Valued Contributor
Valued Contributor
Posts: 548
Joined: Tue Jun 26, 2007 11:23 am
Has thanked: 6 times
Been thanked: 44 times
Contact:

Re: CAN Set Rx ID

Post by Sean »

The code is a generic example and will need to be modified to suit your own requirements.

Removing the unnecessary code for the second filter and interrupt flags allows the program to compile.
Alternatively, a Flowcode variable called Mod_int can be declared. This will allow the first filter of Rx buffer 1 to be reprogrammed in the same way.

The correct operating configuration for the chip (active filters, masks etc.) must be set using the CAN copmonent properties and initialisation macro. The code below only reprograms filter 0 (Message ID 0 in Rx buffer 0)

// Request config mode.
FCD_CAN0_CAN_Config(REQOP_CONFIG);

//Initialise all the CAN device registers
//enable SPI
clear_bit(MX_CAN_CS_PORT, CAN_CHIPSEL);

FCD_CAN0_SPI_SendByte(CAN_WRITE); //CAN write mode
FCD_CAN0_SPI_SendByte(0x00); //Address of filter 0 0x00

//Reprogram the CAN comms Filters
FCD_CAN0_SPI_SendByte( FCV_MOD_REQ >> 8 ); // RXF0SIDH 0x00
FCD_CAN0_SPI_SendByte(FCV_MOD_REQ); // RXF0SIDL 0x01

//disable SPI
set_bit(MX_CAN_CS_PORT, CAN_CHIPSEL);

delay_us(10);

//Put the CAN device into normal mode
FCD_CAN0_CAN_Config(REQOP_NORMAL);

63rjb
Posts: 4
Joined: Wed Oct 05, 2011 12:53 pm
Has thanked: 1 time
Contact:

Re: CAN Set Rx ID

Post by 63rjb »

Thanks Sean for your help!, it works fine now!

Regards,
Ronny

Post Reply