i am trying to route a CAN Signal to CAN FD. My problem is that the example 10_CAN_FD does not work. I don't see anythin in PCAN-View. It seems like the if-statement
Code: Select all
if ( CAN_UserRead ( CAN_BUS1, &RxMsg) == CAN_ERR_OK)
Code: Select all
RxMsg.msgtype = CAN_MSGTYPE_FDF | CAN_MSGTYPE_BRS;
CAN_Write ( CAN_BUS2, &RxMsg);
Here is my code:
Code: Select all
#include <stdint.h>
#include "can.h"
#include "can_user.h"
#include "hardware.h"
// abstract:
// Here we will convert a classical CAN message to a CAN-FD message.
// identifier is needed by PEAK-Flash.exe -> do not delete
const char Ident[] __attribute__ ((used)) = { "PCAN-Router_FD"};
// variables for LED toggle
static uint8_t LED_toggleCAN1;
static uint8_t LED_toggleCAN2;
// main_greeting()
// transmit a message at module start
static void main_greeting ( void)
{
CANTxMsg_t Msg;
Msg.bufftype = CAN_BUFFER_TX_MSG;
Msg.dlc = CAN_LEN8_DLC;
Msg.msgtype = CAN_MSGTYPE_STANDARD;
Msg.id = 0x123;
Msg.data32[0] = 0x67452301;
Msg.data32[1] = 0xEFCDAB89;
// overwrite byte 0 with FPGA version
Msg.data8[0] = FPGA_VERSION;
// Send Msg
CAN_Write ( CAN_BUS1, &Msg);
}
// main()
// entry point from startup
int main ( void)
{
// init hardware and timer 0. Timer 0 is free running
// with 1 us resolution without any IRQ.
HW_Init();
// init CAN
CAN_UserInit();
// set green LEDs for CAN1 and CAN2
HW_SetLED ( HW_LED_CAN1, HW_LED_GREEN);
HW_SetLED ( HW_LED_CAN2, HW_LED_GREEN);
// send the greeting message
// main_greeting();
// main loop
while ( 1)
{
main_greeting();
CANRxMsg_t RxMsg;
HW_SetLED ( HW_LED_CAN1, HW_LED_RED);
RxMsg.msgtype = CAN_MSGTYPE_FDF | CAN_MSGTYPE_BRS;
CAN_Write ( CAN_BUS2, &RxMsg);
// process messages from CAN1
if ( CAN_UserRead ( CAN_BUS1, &RxMsg) == CAN_ERR_OK)
{
HW_SetLED ( HW_LED_CAN1, HW_LED_ORANGE);
/*
// message received from CAN1
LED_toggleCAN1 ^= 1;
if ( LED_toggleCAN1)
{
HW_SetLED ( HW_LED_CAN1, HW_LED_ORANGE);
}
else
{
HW_SetLED ( HW_LED_CAN1, HW_LED_GREEN);
}
*/
// catch ID and convert it from classical CAN to CAN-FD
// if ( (RxMsg.id == 0x123 || RxMsg.id == 0x347 || RxMsg.id == 0x346 ) && RxMsg.msgtype == CAN_MSGTYPE_STANDARD)
if ( (RxMsg.id == 0x123) && (RxMsg.msgtype == CAN_MSGTYPE_STANDARD) )
{
HW_SetLED ( HW_LED_CAN1, HW_LED_GREEN);
// overwrite msgtype
// RxMsg.msgtype = CAN_MSGTYPE_FDF | CAN_MSGTYPE_BRS;
RxMsg.msgtype = CAN_MSGTYPE_FDF;
// set dlc to 12 data bytes
// RxMsg.dlc = CAN_LEN12_DLC;
// add some other data
// RxMsg.data8[8] = 0x11;
// RxMsg.data8[9] = 0x22;
// RxMsg.data8[10] = 0x33;
// RxMsg.data8[11] = 0x44;
// forward message to CAN2
CAN_Write ( CAN_BUS2, &RxMsg);
HW_SetLED ( HW_LED_CAN2, HW_LED_GREEN);
}
}
// process messages from CAN2
if ( CAN_UserRead ( CAN_BUS2, &RxMsg) == CAN_ERR_OK)
{
// message received from CAN2
LED_toggleCAN2 ^= 1;
if ( LED_toggleCAN2)
{
HW_SetLED ( HW_LED_CAN2, HW_LED_ORANGE);
}
else
{
HW_SetLED ( HW_LED_CAN2, HW_LED_GREEN);
}
// Test: CAN-FD Signal auf CAN2 erzeugen, in CAN übersetzen und an CAN1 senden
// RxMsg.msgtype = CAN_MSGTYPE_STANDARD;
// forward message to CAN1
CAN_Write ( CAN_BUS1, &RxMsg);
}
}
}