Closed mdjavedakhtar closed 1 month ago
The function mbc_master_send_request() works if it is used properly.
The example:
// The slave uid, command to send, start register, register size
mb_param_request_t req = {.slave_addr = 1, .command = 0x03, .reg_start = 1, .reg_size = 2};
uint8_t buf[4] = {0};
err = mbc_master_send_request(&req, &info_buf[0]);
if (err != ESP_OK) {
ESP_LOGE("SEND_REQ", "Read slave info fail.");
} else {
ESP_LOGI("SEND_REQ", "Slave Data: %" PRIX32, *(uint32_t*)&buf[0]);
}
The function mbc_master_send_request() works if it is used properly.
The example:
// The slave uid, command to send, start register, register size mb_param_request_t req = {.slave_addr = 1, .command = 0x03, .reg_start = 1, .reg_size = 2}; uint8_t buf[4] = {0}; err = mbc_master_send_request(&req, &info_buf[0]); if (err != ESP_OK) { ESP_LOGE("SEND_REQ", "Read slave info fail."); } else { ESP_LOGI("SEND_REQ", "Slave Data: %" PRIX32, *(uint32_t*)&buf[0]); }
Hi Thanks for the information I just missed the command thing and it gave all kinds of strange issues there !!
Checklist
Issue or Suggestion Description
Hello i am trying to read data from a smart meter. the same setup is working with Arduino library(code attached) but with esp component its not working also the bits are different in logic analyzer. can anyone suggest
IDF code in app_main (uart setup is done before this) ` uint16_t val[4]; esp_err_t err; uint16_t reg_type = 2; uint16_t start_addr = 0x14; uint16_t nRegs = 2;
**modbus_get Function**
esp_err_t modbus_get(uint16_t start_reg, uint16_t nRegs, uint16_t reg_type, void* dstBuf) { esp_err_t err; double slave_addr = 1; err = mbc_master_send_request( &(mb_param_request_t) {slave_addr, reg_type, start_reg, nRegs}, dstBuf);} `
Arduino IDE Code that works (modbus-esp8266 Library)
mb.readHreg(1, 0x14, val, 2, cb); // Slave id is 1 and register address is 0x14
logic analyzer screenshot from IDF codelogic analyzer screenshot from Arduino IDE code