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.
Features overview
Development board
EasyPIC v7 is the seventh generation of PIC development boards specially designed to develop embedded applications rapidly. It supports a wide range of 8-bit PIC microcontrollers from Microchip and has a broad set of unique functions, such as a powerful onboard mikroProg programmer and In-Circuit debugger over USB-B. The development board is well organized and designed so that the end-user has all the necessary elements in one place, such as switches, buttons, indicators, connectors, and others. With four different connectors for each port, EasyPIC v7 allows you to connect accessory boards, sensors, and custom electronics more efficiently than ever. Each part of
the EasyPIC v7 development board contains the components necessary for the most efficient operation of the same board. An integrated mikroProg, a fast USB 2.0 programmer with mikroICD hardware In-Circuit Debugger, offers many valuable programming/debugging options and seamless integration with the Mikroe software environment. Besides it also includes a clean and regulated power supply block for the development board. It can use various external power sources, including an external 12V power supply, 7-23V AC or 9-32V DC via DC connector/screw terminals, and a power source via the USB Type-B (USB-B) connector. Communication options such as
USB-UART and RS-232 are also included, alongside the well-established mikroBUS™ standard, three display options (7-segment, graphical, and character-based LCD), and several different DIP sockets. These sockets cover a wide range of 8-bit PIC MCUs, from PIC10F, PIC12F, PIC16F, PIC16Enh, PIC18F, PIC18FJ, and PIC18FK families. EasyPIC v7 is an integral part of the Mikroe ecosystem for rapid development. Natively supported by Mikroe software tools, it covers many aspects of prototyping and development thanks to a considerable number of different Click boards™ (over a thousand boards), the number of which is growing every day.
Microcontroller Overview
MCU Card / MCU
Architecture
PIC
MCU Memory (KB)
32
Silicon Vendor
Microchip
Pin count
40
RAM (Bytes)
1536
Used MCU Pins
mikroBUS™ mapper
Take a closer look
Click board™ Schematic
Step by step
Project assembly
Track your results in real time
Application Output via UART Mode
1. Once the code example is loaded, pressing the "FLASH" button initiates the build process, and programs it on the created setup.
2. After the programming is completed, click on the Tools icon in the upper-right panel, and select the UART Terminal.
3. After opening the UART Terminal tab, first check the baud rate setting in the Options menu (default is 115200). If this parameter is correct, activate the terminal by clicking the "CONNECT" button.
4. Now terminal status changes from Disconnected to Connected in green, and the data is displayed in the Received data field.
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
The complete application code and a ready-to-use project are available through the NECTO Studio Package Manager for direct installation in the NECTO Studio. The application code can also be found on the MIKROE GitHub account.
/*!
* \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 ( 1000 );
Delay_ms ( 1000 );
#endif
}
int main ( void )
{
/* Do not remove this line or clock might not be set correctly. */
#ifdef PREINIT_SUPPORTED
preinit();
#endif
application_init( );
for ( ; ; )
{
application_task( );
}
return 0;
}
// ------------------------------------------------------------------------ END
/*!
* \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 ( 1000 );
Delay_ms ( 1000 );
#endif
}
int main ( void )
{
/* Do not remove this line or clock might not be set correctly. */
#ifdef PREINIT_SUPPORTED
preinit();
#endif
application_init( );
for ( ; ; )
{
application_task( );
}
return 0;
}
// ------------------------------------------------------------------------ END
/*!
* \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 ( 1000 );
Delay_ms ( 1000 );
#endif
}
int main ( void )
{
/* Do not remove this line or clock might not be set correctly. */
#ifdef PREINIT_SUPPORTED
preinit();
#endif
application_init( );
for ( ; ; )
{
application_task( );
}
return 0;
}
// ------------------------------------------------------------------------ END