Arduino Forum

Using Arduino => Networking, Protocols, and Devices => Topic started by: Mickey_blu_eyes on Oct 11, 2018, 11:16 am

Title: Why can I only send 28 holding registers over modbus?
Post by: Mickey_blu_eyes on Oct 11, 2018, 11:16 am
Hi, following the tutorials, I'm using a TTL-to-RS485 converter (https://eu.banggood.com/Wholesale-Warehouse-5V-MAX485-TTL-To-RS485-Converter-Module-Board-For-Arduino-wp-Eu-912674.html?gmcCountry=GBP&currency=GBP&createTmp=1&utm_source=googleshopping&utm_medium=cpc_elc&utm_content=zouzou&utm_campaign=pla-gb-ele-euw-pc&gclid=Cj0KCQjw6fvdBRCbARIsABGZ-vRap7hVXKhyp4EFfuYCqZAsAXoIKHoIhlcWDQzxCgyJZ8usBNrVtQQaAg7DEALw_wcB) and a RS485-to-USB converter (https://www.amazon.com/serial-2-wire-adapter-Windows-driver/dp/B071FXZH1G) with a 2m USB extension cable (https://www.rapidonline.com/RVFM-USB3-823BL-USB-3-0-A-Male-Female-Extension-Cable-Blue-3m-19-4222?IncVat=1&pdg=aud-313476735250:pla-294357559827:kwd-294357559827:cmp-757438067:adg-44804851896:crv-207912323492:pid-19-4222:dev-c&gclid=Cj0KCQjw6fvdBRCbARIsABGZ-vRQ7tCvGpppmoaBcwsz3JK_zUVar-Sreo_04O_ZvhaW2ubbnwNTu_4aArtFEALw_wcB) to send various sensor outputs over modbus to a receiving program on my PC. I'm using the enum method as here (please ignore the lhs channel numberings):
Code: [Select]

enum
{
  T1a,       //CHANNEL 3 //0
  T1b,       //CHANNEL 4 //1
  T2a,       //CHANNEL 5 //2
  T2b,       //CHANNEL 6 //3
  T3a,       //CHANNEL 7 //4
  T3b,       //CHANNEL 8 //5
  T4a,       //CHANNEL 9 //6
  T4b,       //CHANNEL 10 //7
  T5a,       //CHANNEL 11 //8
  T5b,       //CHANNEL 12 //9
  T6a,       //CHANNEL 13 //10
  T6b,       //CHANNEL 14 //11
  T7a,        //CHANNEL 15 //12
  T7b,        //CHANNEL 16 //13
  T8a,        //CHANNEL 17 //14
  T8b,        //CHANNEL 18 //15
  FP1a,        //CHANNEL 19 //16
  FP1b,        //CHANNEL 20 //17
  FP2a,        //CHANNEL 21 //18
  FP2b,        //CHANNEL 22 //19
  FP3a,        //CHANNEL 23 //20
  FP3b,        //CHANNEL 24 //21
  FP4a,        //CHANNEL 25 //22
  FP4b,        //CHANNEL 26 //23
  FP5a,        //CHANNEL 27 //24
  FP5b,        //CHANNEL 28 //25
  FP6a,        //CHANNEL 29 //26
  FP6b,        //CHANNEL 30 //27
  FP7a,        //CHANNEL 31 //28
  FP7b,        //CHANNEL 32 //29
  FP8a,        //CHANNEL 33 //30
  FP8b,        //CHANNEL 34 //31
  //Error1,     //CHANNEL 35 //32
  //Error2,     //CHANNEL 36 //33
  HOLDING_REGS_SIZE
};

unsigned int holdingRegs[HOLDING_REGS_SIZE];

Modbus slave(1, 0, TXEN); // this is slave @1 and RS-485

 slave.begin(115200);

 slave.poll( holdingRegs, HOLDING_REGS_SIZE );


But I can only seem to be able to send a maximum of 28 registers, can someone enlighten me please?

From looking at similar threads I thought it might be the USB RS485 converter (https://es.aliexpress.com/item/USB-2-0-to-RS485-Serial-Converter-Adapter-CP2104-SN75176-double-protection-FUSE-TVS-stable/32675296782.html)'s buffer wasn't big enough - but it uses a cp2104 chip and the datasheet (https://www.pololu.com/file/0J679/cp2104.pdf) says the buffer is 576 bytes, which is 10x larger than 28 registers right?

Cheers all
Title: Re: Why can I only send 28 holding registers over modbus?
Post by: noiasca on Oct 11, 2018, 11:44 am
Check if there are any limitations documented in the library you are using.
By the way ... which library you are using (please provide exact version and download - link).

Title: Re: Why can I only send 28 holding registers over modbus?
Post by: Mickey_blu_eyes on Oct 11, 2018, 11:56 am
Hi noiasca, I'm using the modbustru library by smarmengol (https://github.com/smarmengol/Modbus-Master-Slave-for-Arduino/blob/master/ModbusRtu.h). On line 147 it says the max buffer size is 64 bytes. Doesn't 64 bytes equate to 32 holding registers?

But anyway thanks, it must be this. I will try looking for a different library with a larger buffer.

Cheers
Title: Re: Why can I only send 28 holding registers over modbus?
Post by: noiasca on Oct 11, 2018, 02:33 pm
... or as a workaround define two objects and split the registers...

Modbus slave(1, 0, TXEN);
Modbus slave2(1, 0, TXEN);

you know what I try to say?
Title: Re: Why can I only send 28 holding registers over modbus?
Post by: pylon on Oct 11, 2018, 02:43 pm
The library you use has a buffer for the response message of size 64 bytes. That includes the data and the message header as well as the CRC.

Quote
But anyway thanks, it must be this. I will try looking for a different library with a larger buffer.
What about simply increasing the buffer size if you really need to transfer all values in one message.
Title: Re: Why can I only send 28 holding registers over modbus?
Post by: Mickey_blu_eyes on Oct 11, 2018, 10:22 pm
Ah, thanks both. Didn't realise you could do either of these things...Will have a fiddle and get back to you, Cheers
Title: Re: Why can I only send 28 holding registers over modbus?
Post by: pylon on Oct 12, 2018, 05:19 pm
Quote
... or as a workaround define two objects and split the registers...

Modbus slave(1, 0, TXEN);
Modbus slave2(1, 0, TXEN);

you know what I try to say?
That doesn't help. The size of the array supplied is not the problem but the buffer size of the result message.