CAN FD 6 click
CAN FD 6 Click is a compact add-on board containing a CAN transceiver that supports CAN and CAN FD protocols. This board features the TCAN4550, a CAN FD controller that provides an interface between the CAN bus and the CAN protocol controller up to 5 megabits per second (Mbps) from Texas Instruments.
click Product page
Click library
- Author : Stefan Nikolic
- Date : feb 2021.
- Type : SPI type
Software Support
We provide a library for the CANFD6 Click as well as a demo application (example), developed using MikroElektronika compilers. The demo can run on all the main MikroElektronika development boards.
Package can be downloaded/installed directly from NECTO Studio Package Manager(recommended way), downloaded from our LibStock™ or found on mikroE github account.
Library Description
This library contains API for CANFD6 Click driver.
Standard key functions :
canfd6_cfg_setup
Config Object Initialization function.
void canfd6_cfg_setup(canfd6_cfg_t *cfg)
CAN FD 6 configuration object setup function.
CAN FD 6 Click configuration object.
Definition canfd6.h:927
canfd6_init
Initialization function.
err_t canfd6_init(canfd6_t *ctx, canfd6_cfg_t *cfg)
CAN FD 6 initialization function.
CAN FD 6 Click context object.
Definition canfd6.h:903
canfd6_default_cfg
Click Default Configuration function.
void canfd6_default_cfg(canfd6_t *ctx)
CAN FD 6 default configuration function.
Example key functions :
canfd6_mcan_write_txbuffer
This function will write a CAN message to a specified TX buffer that can be transmitted at a later time with the transmit buffer contents function.
uint32_t canfd6_mcan_write_txbuffer(canfd6_t *ctx, uint8_t buf_index, canfd6_mcan_tx_header_t *header, uint8_t data_payload[])
CAN FD 6 write tx buffer function.
canfd6_mcan_transmit_buffer_contents
This function writes the specified buffer index bit value into the TXBAR register to request a message to send.
err_t canfd6_mcan_transmit_buffer_contents(canfd6_t *ctx, uint8_t buf_index)
CAN FD 6 transmit buffer contents function.
canfd6_mcan_read_nextfifo
This function will read the next MCAN FIFO element specified and return the corresponding header information and data payload.
canfd6_mcan_fifo_enum_t
CAN FD 6 Click RX FIFO enum.
Definition canfd6.h:977
uint8_t canfd6_mcan_read_nextfifo(canfd6_t *ctx, canfd6_mcan_fifo_enum_t fifo_def, canfd6_mcan_rx_header_t *header, uint8_t data_payload[])
CAN FD 6 read next fifo function.
Example Description
This application presents the capabilities of the CAN FD 6 click board. The board can be used both as a receiver and a transmitter. Use def directive to define the receive or transmit app.
The demo application is composed of two sections :
Application Init
The app starts by initializing the UART LOG and SPI drivers. The default cfg function performs the mandatory settings of the device. The user's default configuration can be modified ( for more information about device configuration, check the datasheet ). Additionally, the app writes two messages to the FIFO buffer and sends them if the transmit buffer content event is triggered.
log_cfg_t log_cfg;
LOG_MAP_USB_UART( log_cfg );
log_init( &logger, &log_cfg );
log_info( &logger, " Application Init " );
if ( init_flag == SPI_MASTER_ERROR ) {
log_error( &logger, " Application Init Error. " );
log_info( &logger, " Please, run program again... " );
for ( ; ; );
}
Delay_ms ( 100 );
#ifdef DEMO_APP_TRANSMITTER
uint8_t data_send_buf[ 64 ] = { 0 };
strcpy ( data_send_buf, "MIKROE" );
canfd6_header.
ID = 0x123;
strcpy ( data_send_buf, "CAN FD 6 click board" );
canfd6_header.
ID = 0x456;
log_printf( &logger, " Application Mode: Transmitter\r\n" );
#else
log_printf( &logger, " Application Mode: Receiver\r\n" );
#endif
log_info( &logger, " Application Task " );
}
#define CANFD6_MAP_MIKROBUS(cfg, mikrobus)
MikroBUS pin mapping.
Definition canfd6.h:885
#define CANFD6_MCAN_DLC_6B
Definition canfd6.h:213
#define CANFD6_MCAN_DLC_20B
Definition canfd6.h:218
void application_init(void)
Definition main.c:49
#define CANFD6_FIRST_MSG
Definition main.c:43
#define CANFD6_SECOND_MSG
Definition main.c:44
Application Task
Depending on the defined app option, the application task performs the following procedure. If the transmitter is preferred, the application task triggers the transmit buffer contents event of the first message and, later on, the second message. On the other hand, the receiver waits for the CAN FD interrupt, where the payload is read along with the header ID.
#ifdef DEMO_APP_TRANSMITTER
log_printf( &logger, " Transmit first message\r\n" );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
log_printf( &logger, " Transmit second message\r\n" );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
#else
uint8_t cnt = 0;
}
if ( canfd6_mcan_ir.
RF0N ) {
uint8_t num_bytes = 0;
uint8_t data_payload[ 64 ] = { 0 };
log_printf( &logger,
" Message received ID[ 0x%X ]: ", canfd6_msg_header.
ID );
while ( cnt < 64 ) {
if ( data_payload[ cnt ] ) {
log_printf( &logger, "%c", data_payload[ cnt ] );
cnt++;
} else {
log_printf( &logger, "\r\n" );
cnt = 64;
}
}
}
}
#endif
}
@ CANFD6_RXFIFO0
Definition canfd6.h:978
uint8_t canfd6_get_int_pin(canfd6_t *ctx)
CAN FD 6 get int pin function.
void canfd6_device_clear_spierr(canfd6_t *ctx)
CAN FD 6 device clear spierr function.
void canfd6_mcan_clear_interrupts(canfd6_t *ctx, canfd6_mcan_interrupts_t *ir)
CAN FD 6 clear interrupts function.
void canfd6_device_read_interrupts(canfd6_t *ctx, canfd6_device_interrupts_t *ir)
CAN FD 6 device read interrupts function.
void canfd6_mcan_read_interrupts(canfd6_t *ctx, canfd6_mcan_interrupts_t *ir)
CAN FD 6 read interrupts function.
void application_task(void)
Definition main.c:112
CAN FD 6 Click device interrupt bit field struct.
Definition canfd6.h:1461
uint8_t SPIERR
Definition canfd6.h:1470
CAN FD 6 Click MCAN interrupts.
Definition canfd6.h:1276
uint8_t RF0N
Definition canfd6.h:1282
The full application code, and ready to use projects can be installed directly from NECTO Studio Package Manager(recommended way), downloaded from our LibStock™ or found on mikroE github account.
Other mikroE Libraries used in the example:
- MikroSDK.Board
- MikroSDK.Log
- Click.CANFD6
Additional notes and informations
Depending on the development board you are using, you may need USB UART click, USB UART 2 Click or RS232 Click to connect to your PC, for development systems with no UART to USB interface available on the board. The terminal available in all Mikroelektronika compilers, or any other terminal application of your choice, can be used to read the message.