Hello members,
I am new to ESP-IDF and trying to read a float value from a meter using the mb_master example but not able to do it. Can anyone please help me with this task.
Visual Studio Code - ESP-IDF V 4.1
Uart Pin: Rx 16 - Tx 4 - RTS 2
Meter Setting: baud 9600, Stop bit 1, parity none,
Slave Id: 1
This is the register I want to read. from a resister, we have to subtract 1 value to get the correct response. The response is in the IEEE Float format.
Can Anyone help me where to modify things to read it?
Modbus Master Read Resister
-
- Posts: 211
- Joined: Fri Feb 01, 2019 4:02 pm
- Contact:
Re: Modbus Master Read Resister
@bhavikbhansali,
Could you provide more information about your application?
1. What kind of interface do you use for communication with your device?
2. Did you try to test your interface using uart_echo_rs485 example? if not, please try it first following the official documentation for the example.
Also set the kconfig values correctly for your speed (9600), communication mode: RTU or ASCII (usually RTU), Your UART pin numbers, and etc. The initialization of serial parameters is performed here:
This will allow to get the register into holding_reg_params.freq_data0 value then you can substract 1 from this value.
The actual reading of register is performed in the master_operation_func() task. You can change its code to customize output.
Please refer to official documentation for modbus master and slave examples and ESP-IDF documentation related to setup IDF and RS485 communication. (https://docs.espressif.com/projects/esp ... /uart.html)
Let me know if you need more help.
Could you provide more information about your application?
1. What kind of interface do you use for communication with your device?
2. Did you try to test your interface using uart_echo_rs485 example? if not, please try it first following the official documentation for the example.
The register 40172 corresponds to holding register area (40xxx) and actual register number = 172. Please try the code below to configure data dictionary in your example:This is the register I want to read. from a resister, we have to subtract 1 value to get the correct response. The response is in the IEEE Float format.
Also set the kconfig values correctly for your speed (9600), communication mode: RTU or ASCII (usually RTU), Your UART pin numbers, and etc. The initialization of serial parameters is performed here:
Code: Select all
examples\protocols\modbus\serial\mb_master\main\master.c:
// Modbus master initialization
static esp_err_t master_init(void)
{
// Initialize and start Modbus controller
mb_communication_info_t comm = {
.port = MB_PORT_NUM,
#if CONFIG_MB_COMM_MODE_ASCII
.mode = MB_MODE_ASCII,
#elif CONFIG_MB_COMM_MODE_RTU
.mode = MB_MODE_RTU,
#endif
.baudrate = MB_DEV_SPEED,
.parity = MB_PARITY_NONE
};
.....
Code: Select all
examples\protocols\modbus\serial\mb_example_common\include\modbus_params.hmodbus_params.h:
#pragma pack(push, 1)
typedef struct
{
// Holding registers of the slave device
float freq_data0;
uint16_t test_regs[150];
} holding_reg_params_t;
#pragma pack(pop)
// examples\protocols\modbus\serial\mb_master\main\master.c: configuration of Modbus data dictionary
// Enumeration of modbus slave addresses accessed by master device
enum {
MB_DEVICE_ADDR1 = 1
};
// Enumeration of all supported CIDs for device (used in parameter definition table)
enum {
CID_SLAVE_FREQ = 0
};
// Example Data (Object) Dictionary for Modbus parameters
const mb_parameter_descriptor_t device_parameters[] = {
// CID, Name, Units, Modbus addr, register type, Modbus Reg Start Addr, Modbus Reg read length,
// Instance offset (NA), Instance type, Instance length (bytes), Options (NA), Permissions
{ CID_SLAVE_FREQ, STR("Frequency"), STR("Hz"), MB_DEVICE_ADDR1, MB_PARAM_HOLDING, 172, 2,
HOLD_OFFSET(freq_data0), PARAM_TYPE_FLOAT, 4, OPTS( 0, 10000, 1 ), PAR_PERMS_READ_WRITE_TRIGGER },
};
The actual reading of register is performed in the master_operation_func() task. You can change its code to customize output.
Please refer to official documentation for modbus master and slave examples and ESP-IDF documentation related to setup IDF and RS485 communication. (https://docs.espressif.com/projects/esp ... /uart.html)
Let me know if you need more help.
Who is online
Users browsing this forum: Google [Bot] and 87 guests