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
CAN Set Rx ID
-
- Valued Contributor
- Posts: 548
- Joined: Tue Jun 26, 2007 11:23 am
- Has thanked: 6 times
- Been thanked: 44 times
Re: CAN Set Rx ID
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
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
Re: CAN Set Rx ID
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?
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?
-
- Valued Contributor
- Posts: 548
- Joined: Tue Jun 26, 2007 11:23 am
- Has thanked: 6 times
- Been thanked: 44 times
Re: CAN Set Rx ID
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)
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)
Re: CAN Set Rx ID
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
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
-
- Valued Contributor
- Posts: 548
- Joined: Tue Jun 26, 2007 11:23 am
- Has thanked: 6 times
- Been thanked: 44 times
Re: CAN Set Rx ID
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);
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);