The way I set up CAN was to use Processor Expert with the S32 SDK, which is an addon you can get from the S32 download page I believe. Then you can choose which FlexCAN module to use in a graphical interface and then add functionality by dragging and dropping code. Hence the final code set-up (FlexCAN only) for me was
in "main()":
// FlexCAN message struct for sending
flexcan_msgbuff_t send_buff;
send_buff.data[0] = 0;
send_buff.data[1] = 0xFF;
send_buff.data[2] = 0;
send_buff.data[3] = 0xFF;
send_buff.data[4] = 0;
send_buff.data[5] = 0xFF;
send_buff.data[6] = 0;
send_buff.data[7] = 0xFF;
send_buff.dataLen = 8; // data length
send_buff.msgId = 1; // Message ID
// FlexCAN Data Info
flexcan_data_info_t txInfo = {
.data_length = 8,
.is_remote = 0,
.msg_id_type = FLEXCAN_MSG_ID_STD,
};
// Initialize FlexCAN module
FLEXCAN_DRV_Init(INST_CANCOM1, &canCom1_State, &canCom1_InitConfig0);
// Configure Tx Message Buffer 0 to send CAN message
FLEXCAN_DRV_ConfigTxMb(INST_CANCOM1, 0, &txInfo, send_buff.msgId);
// Send the message
FLEXCAN_DRV_Send(INST_CANCOM1, 0, &txInfo, send_buff.msgId, &(send_buff.data));
while(1)
{
// Wait for transfer to complete
while (FLEXCAN_DRV_GetTransferStatus(INST_CANCOM1, 0) == STATUS_BUSY) {
//FLEXCAN_DRV_Send(INST_CANCOM1, 0, &txInfo, send_buff.msgId, &(send_buff.data));
counter++;
}
}
If you don't use the S32 SDK I think you can just replace CAN2 with CAN0 in the example code you saw, but you probably need to pay attention to the peripheral clocking for CAN0. On the DEVKIT, only CAN0 is connected to a proper CAN transceiver (MC33901WEF, see above) so with minimal set-up you would just need a 120-ohm resistor and some wires to connect to the Vector CAN peripherals.