Page 1 of 1

problem with Modbus Master in Flowcode v7

Posted: Tue Sep 13, 2016 9:44 am
by radist73
Hello,
I have some expirience with Fc v6 and just purchaced Flowcode v7 because need to make devices with Modbus connectivity.
Question, have Modbus component any restrictions for choosing PIC microcontrollers?
In attachement my small flowchart for testing Modbus master component, my testboard have PIC16F877A with 19,660 crystal.
It have MCP23017 with LEDs , connected via I2C to PIC, and oneLED conected to port RD4. This LED flash once per second to show that program running.
Pushbutton connected to port RE0.
If controller powers up, RD4 LED start flashing and I2C LEDs show preprogrammed value.
If I press the RE0 button, program need to read inputs via Modbus from Slave 1, but program stop working and not running so long, as button pressed. If button released, program will run again.
Is it problem with my logic, or hardware problem (incompatible controller) ?

Re: problem with Modbus Master in Flowcode v7

Posted: Tue Sep 13, 2016 10:16 am
by Benj
Hello,

The Modbus component will work with any microcontroller that has a UART peripheral.

Have you seen the Flowcode 7 update files available here.
http://www.matrixtsl.com/mmforums/viewt ... 63&t=17953

They contain some component fixes for Modbus which may solve the problem you're having.

Re: problem with Modbus Master in Flowcode v7

Posted: Tue Sep 13, 2016 2:22 pm
by radist73
Thanks!
Now example Master-Slave works fine.
But I am confused with reading analog input...
What way is ok?
1. --Use ADC component and read adc value adc0_read.
--Write this value to holding register with SetHoldingRegister with address 1 and value adc0_read.
--Master read the register state (slave address 1, register aadress 1, return value adc0_rd)
2. -- Slave component have function ReadAnalogueInput with address and Return value. Address is 1 and return value is adc0_read. How I can associate address 1 with PIC port An0?.

I need set to work one example, where master ask from slave analog input value and show it in master RD ports.
Many thanks!

Re: problem with Modbus Master in Flowcode v7

Posted: Tue Sep 13, 2016 5:41 pm
by Benj
Hello,

You need to use option 1. Although they are called AnalogueInputs they are basically a second set of holding registers.

i.e. use an ADC component to take an analogue reading.

Store the reading either in a holding register (SetHoldingRegister) or in an analogue Input register (SetAnalogueInput).

Read the corresponding register using the Master.

Hope this helps.

Re: problem with Modbus Master in Flowcode v7

Posted: Wed Sep 14, 2016 10:09 am
by radist73
Sorry, but have problem with adc....
my test program steps:
--read analog value adc0
--write to register SetHoldingRegister addr0,
In ModbusSlave parameters Register aadresses starts with 0
Master side:
--ReadHoldingRegister slave id28, register address0, count0
And answer zero....
Maybe any problem with regesters addressing?
Regards,
Mihhail

Re: problem with Modbus Master in Flowcode v7

Posted: Wed Sep 14, 2016 12:52 pm
by Benj
Hello Mihhail,

In the Master program for the ReadHoldingRegister component macro you have the RegCount parameter set to 0, I think this needs to be set to 1.

Hopefully that change will allow the code to work as expected.

Re: problem with Modbus Master in Flowcode v7

Posted: Wed Sep 14, 2016 1:29 pm
by radist73
Hello,
set to 1 not working too... Master just havent read a Holding register values. I just tried to put a fixed value 0x1f to Holding register address 0 in Slave side. No change, output zero
Master side translate address 0 to 40001, 1 to 40002 etc... As the slave side do the same?
In ModbusSlave parameters Modbus Register start value 0 will be translated to 40001 too?

Updated:
On Master side function PresetHoldingRegister works fine, master write to holding register addr0 on slave side fix value and show it on local slave LCD display, but read again the same register from slave by master give zero

Re: problem with Modbus Master in Flowcode v7

Posted: Wed Sep 14, 2016 2:39 pm
by Benj
Hello,
Master side translate address 0 to 40001, 1 to 40002 etc.
Yes both the master and slave should translate the addresses for you: 0 to 40001, 1 to 40002 etc.

I'll see if I can rig up something here and replicate the issue for you.

Re: problem with Modbus Master in Flowcode v7

Posted: Fri Sep 16, 2016 10:54 am
by radist73
Hello,
I has checked all Read from slave functions (ReadHoldingRegister, ReadInputStatus, ReadCoilStatus) and I hasnt it working.
Locally in slave ReadCoilStatus works fine, but all remote read functions not work....

The same Master program on Flowcode 6 works, but veeery slowly, one TX per 4sec :) And in FC6 modbus master component properties I cant change Silent time and RX timeout, I think they have by default 60 and 220 values .. If I press button on master side, slave answer after 10sec and reading register again from slave give answer to master after 30sec

Re: problem with Modbus Master in Flowcode v7

Posted: Sun Sep 18, 2016 12:40 am
by radist73
Hello,
I found working example
http://www.matrixtsl.com/mmforums/viewt ... bus#p76164 Example3 and understand, but my logic understanding was wrong :)
Thank you!

Re: problem with Modbus Master in Flowcode v7

Posted: Sun Oct 08, 2017 11:01 am
by hsavas
I have try most of examples but still getting CRC Error.
Master works fine with Modbus PLC simulators.
but no luck with slave.

Re: problem with Modbus Master in Flowcode v7

Posted: Mon Oct 09, 2017 8:51 am
by LeighM
Hi hsavas
Have you updated with the latest components from here? ...
http://www.matrixtsl.com/mmforums/viewt ... 63&t=18760