Intermediate
30 min

Stay ahead in the world of communication technology with MAX485 and dsPIC33EP512MU810

Transforming data transmission: The magic of RS485 transceivers

RS485 5 Click with Explorer 16/32 development board

Published Oct 19, 2023

Click board™

RS485 5 Click

Dev Board

Explorer 16/32 development board

Compiler

NECTO Studio

MCU

dsPIC33EP512MU810

The core purpose of this solution is to establish a robust, long-distance network, facilitating efficient data exchange

A

A

Hardware Overview

How does it work?

RS485 5 Click is based on the MAX485, low-power, slew-rate-limited transceiver for RS-485 and RS-422 communication from Analog Devices, which draw between 120µA and 500µA of supply current when unloaded or fully loaded with disabled drivers. All parts operate from a single 5V supply. Driver is short-circuit current limited and is protected against excessive power dissipation by thermal shutdown circuitry that places the driver outputs into a high-impedance state. The receiver input has a fail-safe feature that guarantees a logic-high output if the input is open circuit. The MAX485 slew rates are not limited, allowing it to transmit up to 2.5Mbps and half-duplex communication. In general, the maximal transfer

speed is determined by the bus length, longer bus lines will result in less transfer speed. The RS485/422 line should be terminated at both ends in its characteristic impedance and stub lengths off the main line should be kept as short as possible to minimize the reflections. The RS-485/RS-422 standard covers line lengths up to 1220 meters (4000 feet). Excessive output current and power dissipation caused by faults or by bus contention are prevented by two mechanisms. A foldback current limit on the output stage provides immediate protection against short circuits over the whole common-mode voltage range. In addition, a thermal shutdown circuit forces the driver outputs into a high-impedance

state if the temperature rises excessively. There are two 2-pole screw terminals on board (+, B, A, -) for connecting RS422/485 bus twisted pair cable, along with the GND and VCC. The terminal inputs labeled as “A” and “B” are used to connect the bus wires. GND and VCC rails can be used to provide the power supply for another node. Note that the VCC terminal is directly routed to the 5V rail of the mikroBUS™. This Click board™ can be operated only with a 5V logic voltage level. The board must perform appropriate logic voltage level conversion before using MCUs with different logic levels. Also, it comes equipped with a library containing functions and an example code that can be used as a reference for further development.

RS485 5 Click top side image
RS485 5 Click bottom side image

Features overview

Development board

Explorer 16/32 development board is a flexible and convenient development, demonstration, and testing platform for 16-bit PIC24 MCUs, dsPIC® DSCs, and 32-bit PIC32 MCUs from Microchip Technology. It features all the necessary hardware to develop and debug a complete embedded application. The board accepts Processor Plug-In Modules (PIMs) designed for the Explorer 16 or Explorer 16/32 development board for easy device swapping. In addition to the hardware features provided by the board, hardware expansion is possible through the use of PICtail™ Plus

daughter cards and mikroBUS™ accessory boards. Coupled with the integrated PICkit™-On-Board (PKOB), MPLAB ICD In-Circuit Debugger real-time debug facilities enable faster evaluation and prototyping of applications. This development board supports all the Explorer PIMs. However, not all PIMs are supported by the PKOB. To check the list of supported and unsupported PIMs, refer to the PICkit™ On-Board 3 (PKOB3) Support List. For PIMs not on the PKOB3 support list, use the JP1 or J14 connectors to program the device with a newer generation programming tool. Explorer 16/32

development board offers only the main board, allowing customization of the other necessary components. Choose your PIM based on MCUs and DSCs under consideration from a wide range of Processor Plug-In Modules. This board is optimal for customers migrating from Classic Explorer 16 to the new Explorer 16/32 platform, while all the necessary additional components like Processor Plug-In Modules and PICtail™ Plus Daughter Boards are already available.

Explorer 16/32 double side image

Microcontroller Overview

MCU Card / MCU

default

Architecture

dsPIC

MCU Memory (KB)

512

Silicon Vendor

Microchip

Pin count

100

RAM (Bytes)

53248

Used MCU Pins

mikroBUS™ mapper

NC
NC
AN
Receiver Output
PG14
RST
Drive Output
PG9
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
NC
NC
3.3V
Ground
GND
GND
NC
NC
PWM
NC
NC
INT
UART TX
PF3
TX
UART RX
PF2
RX
NC
NC
SCL
NC
NC
SDA
Power Supply
5V
5V
Ground
GND
GND
1

Take a closer look

Schematic

RS485 5 Click Schematic schematic

Step by step

Project assembly

Explorer 16/32 front image hardware assembly

Start by selecting your development board and Click board™. Begin with the Explorer 16/32 development board as your development board.

Explorer 16/32 front image hardware assembly
GNSS2 Click front image hardware assembly
PIM for PIC32MZ2048EFH100 front image hardware assembly
Prog-cut hardware assembly
GNSS2 Click complete accessories setup image hardware assembly
Explorer 16/32 MB 1 Access - upright/background hardware assembly
Necto image step 2 hardware assembly
Necto image step 3 hardware assembly
Necto image step 4 hardware assembly
Necto image step 5 hardware assembly
Necto image step 6 hardware assembly
Explorer 16/32 MCU Step hardware assembly
Necto No Display image step 8 hardware assembly
Necto image step 9 hardware assembly
Necto image step 10 hardware assembly
Debug Image Necto Step hardware assembly

Track your results in real time

Application Output

After loading the code example, pressing the "DEBUG" button builds and programs it on the selected setup.

Application Output Step 1

After programming is completed, a header with buttons for various actions available in the IDE appears. By clicking the green "PLAY "button, we start reading the results achieved with Click board™.

Application Output Step 3

Upon completion of programming, the Application Output tab is automatically opened, where the achieved result can be read. In case of an inability to perform the Debug function, check if a proper connection between the MCU used by the setup and the CODEGRIP programmer has been established. A detailed explanation of the CODEGRIP-board connection can be found in the CODEGRIP User Manual. Please find it in the RESOURCES section.

Application Output Step 4

Software Support

Library Description

This library contains API for RS485 5 Click driver.

Key functions:

  • rs4855_generic_write - Generic write function.

  • rs4855_set_de_state - Sets DE pin to high or low state.

  • rs4855_set_re_state - Sets RE pin to high or low state.

Open Source

Code example

This example can be found in NECTO Studio. Feel free to download the code, or you can copy the code below.

/*!
 * \file 
 * \brief Rs4855 Click example
 * 
 * # Description
 * This example reads and processes data from RS485 5 clicks.
 *
 * The demo application is composed of two sections :
 * 
 * ## Application Init 
 * Initializes the driver and enables the selected mode.
 * 
 * ## Application Task  
 * Depending on the selected mode, it reads all the received data or sends the desired message
 * every 2 seconds.
 * 
 * ## Additional Function
 * - rs4855_process ( ) - The general process of collecting the received data.
 * 
 * \author MikroE Team
 *
 */
// ------------------------------------------------------------------- INCLUDES

#include "board.h"
#include "log.h"
#include "rs4855.h"
#include "string.h"

#define PROCESS_RX_BUFFER_SIZE 500

#define TEXT_TO_SEND "MikroE\r\n"

// ------------------------------------------------------------------ VARIABLES

#define DEMO_APP_RECEIVER
// #define DEMO_APP_TRANSMITTER

static rs4855_t rs4855;
static log_t logger;

// ------------------------------------------------------- ADDITIONAL FUNCTIONS

static void rs4855_process ( void )
{
    int32_t rsp_size;
    
    char uart_rx_buffer[ PROCESS_RX_BUFFER_SIZE ] = { 0 };
    uint8_t check_buf_cnt;
    
    rsp_size = rs4855_generic_read( &rs4855, uart_rx_buffer, PROCESS_RX_BUFFER_SIZE );

    if ( rsp_size >= strlen( TEXT_TO_SEND ) )
    {  
        log_printf( &logger, "Received data: " );
        
        for ( check_buf_cnt = 0; check_buf_cnt < rsp_size; check_buf_cnt++ )
        {
            log_printf( &logger, "%c", uart_rx_buffer[ check_buf_cnt ] );
        }
    }
    Delay_ms( 100 );
}

// ------------------------------------------------------ APPLICATION FUNCTIONS

void application_init ( void )
{
    log_cfg_t log_cfg;
    rs4855_cfg_t cfg;

    /** 
     * 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.

    rs4855_cfg_setup( &cfg );
    RS4855_MAP_MIKROBUS( cfg, MIKROBUS_1 );
    rs4855_init( &rs4855, &cfg );

    Delay_ms( 100 );

#ifdef DEMO_APP_RECEIVER
    rs4855_set_re_state( &rs4855, RS4855_PIN_STATE_LOW );
    rs4855_set_de_state( &rs4855, RS4855_PIN_STATE_LOW );
    log_info( &logger, "---- Receiver mode ----" );
#endif    
#ifdef DEMO_APP_TRANSMITTER
    rs4855_set_re_state( &rs4855, RS4855_PIN_STATE_HIGH );
    rs4855_set_de_state( &rs4855, RS4855_PIN_STATE_HIGH );
    log_info( &logger, "---- Transmitter mode ----" );
#endif    
}

void application_task ( void )
{
#ifdef DEMO_APP_RECEIVER
    rs4855_process( );
#endif    
    
#ifdef DEMO_APP_TRANSMITTER
    rs4855_generic_write( &rs4855, TEXT_TO_SEND, 8 );
    log_info( &logger, "---- Data sent ----" );
    Delay_ms( 2000 );
#endif    
}

void main ( void )
{
    application_init( );

    for ( ; ; )
    {
        application_task( );
    }
}


// ------------------------------------------------------------------------ END

Additional Support

Resources