TOP Contributors

  1. MIKROE (2781 codes)
  2. Alcides Ramos (377 codes)
  3. Shawon Shahryiar (307 codes)
  4. jm_palomino (118 codes)
  5. Bugz Bensce (97 codes)
  6. S P (73 codes)
  7. dany (71 codes)
  8. MikroBUS.NET Team (35 codes)
  9. NART SCHINACKOW (34 codes)
  10. Armstrong Subero (27 codes)

Most Downloaded

  1. Timer Calculator (139580 times)
  2. FAT32 Library (72043 times)
  3. Network Ethernet Library (57260 times)
  4. USB Device Library (47633 times)
  5. Network WiFi Library (43230 times)
  6. FT800 Library (42569 times)
  7. GSM click (29932 times)
  8. mikroSDK (28313 times)
  9. PID Library (26934 times)
  10. microSD click (26309 times)
Libstock prefers package manager

Package Manager

We strongly encourage users to use Package manager for sharing their code on Libstock website, because it boosts your efficiency and leaves the end user with no room for error. [more info]

< Back
mikroSDK Library

CAN FD 6 Click

Rating:

0

Author: MIKROE

Last Updated: 2024-10-31

Package Version: 2.1.0.10

mikroSDK Library: 2.0.0.0

Category: CAN

Downloaded: 193 times

Not followed.

License: MIT license  

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.

No Abuse Reported

Do you want to subscribe in order to receive notifications regarding "CAN FD 6 Click" changes.

Do you want to unsubscribe in order to stop receiving notifications regarding "CAN FD 6 Click" changes.

Do you want to report abuse regarding "CAN FD 6 Click".

  • Information
  • Comments (0)

mikroSDK Library Blog


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.

canfd6_click.png

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 );
  • canfd6_init Initialization function.

    err_t canfd6_init ( canfd6_t *ctx, canfd6_cfg_t *cfg );
  • canfd6_default_cfg Click Default Configuration function.

    void canfd6_default_cfg ( canfd6_t *ctx );

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[ ] );
  • 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 );
  • canfd6_mcan_read_nextfifo This function will read the next MCAN FIFO element specified and return the corresponding header information and data payload.

    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[ ] );

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.


void application_init ( void ) {
    log_cfg_t log_cfg;        /**< Logger config object. */
    canfd6_cfg_t canfd6_cfg;  /**< Click config object. */

    /** 
     * Logger initialization.
     * Default baud rate: 115200
     * Default log level: LOG_LEVEL_DEBUG
     * @note If USB_UART_RX and USB_UART_TX 
     * are defined as HAL_PIN_NC, you will 
     * need to define them manually for log to work. 
     * See @b LOG_MAP_USB_UART macro definition for detailed explanation.
     */
    LOG_MAP_USB_UART( log_cfg );
    log_init( &logger, &log_cfg );
    log_info( &logger, " Application Init " );

    // Click initialization.
    canfd6_cfg_setup( &canfd6_cfg );
    CANFD6_MAP_MIKROBUS( canfd6_cfg, MIKROBUS_1 );
    err_t init_flag = canfd6_init( &canfd6, &canfd6_cfg );
    if ( init_flag == SPI_MASTER_ERROR ) {
        log_error( &logger, " Application Init Error. " );
        log_info( &logger, " Please, run program again... " );

        for ( ; ; );
    }

    canfd6_default_cfg( &canfd6 );
    Delay_ms ( 100 );
#ifdef DEMO_APP_TRANSMITTER
    canfd6_mcan_tx_header_t canfd6_header = { 0 };
    uint8_t data_send_buf[ 64 ] = { 0 };
    strcpy ( data_send_buf, "MIKROE" );
    canfd6_header.DLC = CANFD6_MCAN_DLC_6B;
    canfd6_header.ID = 0x123;
    canfd6_header.FDF = 1;
    canfd6_header.BRS = 1;
    canfd6_header.EFC = 0;
    canfd6_header.MM  = 0;
    canfd6_header.RTR = 0;
    canfd6_header.XTD = 0;
    canfd6_header.ESI = 0;
    canfd6_mcan_write_txbuffer( &canfd6, CANFD6_FIRST_MSG, &canfd6_header, data_send_buf );

    strcpy ( data_send_buf, "CAN FD 6 Click board" );
    canfd6_header.DLC = CANFD6_MCAN_DLC_20B;
    canfd6_header.ID = 0x456;
    canfd6_header.FDF = 1;
    canfd6_header.BRS = 1;
    canfd6_header.EFC = 0;
    canfd6_header.MM  = 0;
    canfd6_header.RTR = 0;
    canfd6_header.XTD = 0;
    canfd6_header.ESI = 0;
    canfd6_mcan_write_txbuffer( &canfd6, CANFD6_SECOND_MSG, &canfd6_header, data_send_buf );
    log_printf( &logger, " Application Mode: Transmitter\r\n" );
#else
    log_printf( &logger, " Application Mode: Receiver\r\n" );
#endif
    log_info( &logger, " Application Task " );
}

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.


void application_task ( void ) {
#ifdef DEMO_APP_TRANSMITTER
    log_printf( &logger, " Transmit first message\r\n" );
    canfd6_mcan_transmit_buffer_contents( &canfd6, CANFD6_FIRST_MSG );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    log_printf( &logger, " Transmit second message\r\n" );
    canfd6_mcan_transmit_buffer_contents( &canfd6, CANFD6_SECOND_MSG );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
#else
    uint8_t cnt = 0;
    if ( !canfd6_get_int_pin( &canfd6 ) ) {
        canfd6_device_interrupts_t canfd6_dev_ir = { 0 };
        canfd6_mcan_interrupts_t canfd6_mcan_ir = { 0 };
        canfd6_device_read_interrupts( &canfd6, &canfd6_dev_ir );
        canfd6_mcan_read_interrupts( &canfd6, &canfd6_mcan_ir );

        if ( canfd6_dev_ir.SPIERR ) {
            canfd6_device_clear_spierr( &canfd6 );
        }

        if ( canfd6_mcan_ir.RF0N ) {
            canfd6_mcan_rx_header_t canfd6_msg_header = { 0 };
            uint8_t num_bytes = 0;
            uint8_t data_payload[ 64 ] = { 0 };

            canfd6_mcan_clear_interrupts( &canfd6, &canfd6_mcan_ir );

            num_bytes = canfd6_mcan_read_nextfifo( &canfd6, CANFD6_RXFIFO0, &canfd6_msg_header, data_payload );

            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
}

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.


ALSO FROM THIS AUTHOR

Digital Input Output Demo

0

The application demonstrates GPIO SDK functionality.

[Learn More]

LightRanger 10 Click

0

LightRanger 10 Click is a compact add-on board suitable for range-finding and distance sensing applications. This board features the VL53L4CX, a ToF (time of flight) optical distance sensor with an extended target detection range from STMicroelectronics. Specifically designed for long-range and multi-target measurements, the VL53L4CX provides very accurate distance measurements up to 6m with excellent results over short distances and 18° FoV (Field of View), which improves performances under ambient light. Data processing is performed inside the VL53L4CX, providing distance information and confidence values through its I2C interface.

[Learn More]

Battery Source Click

0

Battery Source Click is a compact add-on board designed to boost power from a battery for portable applications. This board features the TPS81256, a high-efficiency step-up converter from Texas Instruments. The board boosts input voltage (2.5V to 5.5V) to 5V/1A on a USB Type-C connector. It operates at a 4MHz switching frequency, enters Power-Save mode at light loads, and reduces supply current to 43μA during light load operation. The board supports over 3W output power and has an input current of less than 1µA in shutdown mode, maximizing battery life.

[Learn More]