problem with Modbus Master in Flowcode v7

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 7.

Moderator: Benj

radist73
Posts: 36
Joined: Mon Dec 22, 2014 10:04 pm
Location: TALLINN
Has thanked: 5 times
Been thanked: 2 times
Contact:

problem with Modbus Master in Flowcode v7

Postby radist73 » Tue Sep 13, 2016 9:44 am

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) ?
Attachments
IMG_201606.jpg
(504.71 KiB) Downloaded 1899 times
modbus_master_1.fcfx
(17.22 KiB) Downloaded 163 times

User avatar
Benj
Matrix Staff
Posts: 14797
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4759 times
Been thanked: 4361 times
Contact:

Re: problem with Modbus Master in Flowcode v7

Postby Benj » Tue Sep 13, 2016 10:16 am

Hello,

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

Have you seen the Flowcode 7 update files available here.
viewtopic.php?f=63&t=17953

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

radist73
Posts: 36
Joined: Mon Dec 22, 2014 10:04 pm
Location: TALLINN
Has thanked: 5 times
Been thanked: 2 times
Contact:

Re: problem with Modbus Master in Flowcode v7

Postby radist73 » Tue Sep 13, 2016 2:22 pm

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!

User avatar
Benj
Matrix Staff
Posts: 14797
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4759 times
Been thanked: 4361 times
Contact:

Re: problem with Modbus Master in Flowcode v7

Postby Benj » Tue Sep 13, 2016 5:41 pm

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.

radist73
Posts: 36
Joined: Mon Dec 22, 2014 10:04 pm
Location: TALLINN
Has thanked: 5 times
Been thanked: 2 times
Contact:

Re: problem with Modbus Master in Flowcode v7

Postby radist73 » Wed Sep 14, 2016 10:09 am

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
Attachments
mod_master_1.fcfx
(14.49 KiB) Downloaded 156 times
ModBus_Slave_Example1 (1).fcfx
(11.18 KiB) Downloaded 162 times

User avatar
Benj
Matrix Staff
Posts: 14797
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4759 times
Been thanked: 4361 times
Contact:

Re: problem with Modbus Master in Flowcode v7

Postby Benj » Wed Sep 14, 2016 12:52 pm

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.

radist73
Posts: 36
Joined: Mon Dec 22, 2014 10:04 pm
Location: TALLINN
Has thanked: 5 times
Been thanked: 2 times
Contact:

Re: problem with Modbus Master in Flowcode v7

Postby radist73 » Wed Sep 14, 2016 1:29 pm

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
Last edited by radist73 on Wed Sep 14, 2016 2:55 pm, edited 3 times in total.

User avatar
Benj
Matrix Staff
Posts: 14797
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4759 times
Been thanked: 4361 times
Contact:

Re: problem with Modbus Master in Flowcode v7

Postby Benj » Wed Sep 14, 2016 2:39 pm

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.
These users thanked the author Benj for the post:
radist73 (Wed Sep 14, 2016 2:53 pm)
Rating: 5%
 

radist73
Posts: 36
Joined: Mon Dec 22, 2014 10:04 pm
Location: TALLINN
Has thanked: 5 times
Been thanked: 2 times
Contact:

Re: problem with Modbus Master in Flowcode v7

Postby radist73 » Fri Sep 16, 2016 10:54 am

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

radist73
Posts: 36
Joined: Mon Dec 22, 2014 10:04 pm
Location: TALLINN
Has thanked: 5 times
Been thanked: 2 times
Contact:

Re: problem with Modbus Master in Flowcode v7

Postby radist73 » Sun Sep 18, 2016 12:40 am

Hello,
I found working example
viewtopic.php?f=64&t=17938&p=76367&hilit=modbus#p76164 Example3 and understand, but my logic understanding was wrong :)
Thank you!

hsavas
Posts: 1
Joined: Sun Oct 08, 2017 10:57 am
Contact:

Re: problem with Modbus Master in Flowcode v7

Postby hsavas » Sun Oct 08, 2017 11:01 am

I have try most of examples but still getting CRC Error.
Master works fine with Modbus PLC simulators.
but no luck with slave.

User avatar
LeighM
Matrix Staff
Posts: 2014
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 480 times
Been thanked: 691 times
Contact:

Re: problem with Modbus Master in Flowcode v7

Postby LeighM » Mon Oct 09, 2017 8:51 am

Hi hsavas
Have you updated with the latest components from here? ...
viewtopic.php?f=63&t=18760