Wiznet makers

mason

Published March 10, 2024 © MIT license (MIT)

82 UCC

15 WCC

28 VAR

0 Contests

0 Followers

0 Following

RP2040-HAT-MODBUS-C

Modbus TCP RTU/ASCII on WIZnet Pico boards

COMPONENTS Hardware components

WIZnet - W5500-EVB-Pico

x 1


WIZnet - W5100S-EVB-Pico

x 1


PROJECT DESCRIPTION

RP2040-HAT-MODBUS-C

This project is a Modbus TCP RTU/ASCII example code that runs on the W5500-EVB-Pico or W5100S-EVB-Pico.

https://docs.wiznet.io/Product/iEthernet/W5100S/w5100s-evb-pico https://docs.wiznet.io/Product/iEthernet/W5500/w5500-evb-pico

Set the CMakeLists

Set the PICO_SDK_PATH in RP2040-HAT-MODBUS-C/CMakeLists.txt
Refer to the documentation below for more information.
https://www.raspberrypi.com/documentation/microcontrollers/c_sdk.html

if(NOT DEFINED PICO_SDK_PATH)
    set(PICO_SDK_PATH ${CMAKE_SOURCE_DIR}/libraries/pico-sdk)
    message(STATUS "PICO_SDK_PATH = ${PICO_SDK_PATH}")
endif()

If you are using the W5100S-EVB-Pico board, make the following changes. The default is W5500-EVB-Pico.

# Set ethernet chip
set(WIZNET_CHIP W5100S)

Set Timer

If you have a different MCU or a different clock, you will need to set the Timer. This example is set to a timer of 20khz.
RP2040-HAT-MODBUS-C\port\modbus\src\mbtimer.c

1/20khz = 50us

add_repeating_timer_us(50, vMBPortTimersCallback, NULL, &g_mb_timer);

Set Modbus Serial

In this example, the UART1 TX : 4, RX : 5 Pins are converted to Modbus Serial.
Baudrate is 19200. RP2040-HAT-MODBUS-C\port\modbus\inc\mbserial.h

#define UART_MODBUS uart1
#define UART_MODBUS_TX 4
#define UART_MODBUS_RX 5
#define UART_MODBUS_BAUDRATE 19200

Build

RP2040-HAT-MODBUS-C

mkdir build
cd build
cmake -G "NMake Makefiles" ..
nmake

I tested using modbus poll/slave tools.
modbus poll : https://www.modbustools.com/modbus_poll.html
modbus slave : https://www.modbustools.com/modbus_slave.html

Modbus Pool Connect :
Modbus Poll connect.png

Modbus Slave Connect :
Modbus Slave connect.png

Test Result :
Test Result.png

Documents
  • RP2040-HAT-MODBUS-C Code

Comments Write