PIC as MODBUS slave

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

Moderator: Benj

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

Re: PIC as MODBUS slave

Post by Benj »

Hello,

I think the problem causing the compilation error is the Flowcode project file name, it's been reported before. Try shortening the name and getting rid of the brackets.
viewtopic.php?f=63&t=17965&p=76175#p76151

SILVESTROS9
Posts: 115
Joined: Wed Aug 03, 2016 10:45 pm
Has thanked: 24 times
Been thanked: 11 times
Contact:

Re: PIC as MODBUS slave

Post by SILVESTROS9 »

Hello,
Thanks for info. I give a short FC project file name (MBSlaveLCD16.fcfx) , compiler gives me the following , no data at lcd when I send some characters ( emulator gives me response error). LCD works fine when I change the MCU with a PIC16F1939(with the same code).

Launching the compiler...
C:\Program Files (x86)\Flowcode 7\compilers\pic\bin\xc8.exe --chip=18F458 "MBSlaveLCD16.c" --MSGDISABLE=359,1273,1388
Microchip MPLAB XC8 C Compiler (Free Mode) V1.38
Build date: Jun 30 2016
Part Support Version: 1.38
Copyright (C) 2016 Microchip Technology Inc.
License type: Node Configuration
Employing 18F458 errata work-arounds:
* Address 4000h boundary
* Faulty table reads at -40 degrees C
* GOTO instruction at reset vector must be preceded by NOP
* Peripherals can misbehave if BSR = 15
* DAW instruction may improperly clear CARRY bit
* Writes to flash must target opposite side of 4000h boundary
MBSlaveLCD16.c:
37: __config("__PROG_CONFIG", "pic18", 0x3, 0xFFFF);
^ (0) Can't find config word 3 used in in __PROG_CONFIG() (warning)

Are configuration settings correct? Below I post the file . Thanks.
Attachments
MBSlaveLCD16.fcfx
(26.64 KiB) Downloaded 229 times

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

Re: PIC as MODBUS slave

Post by Benj »

Hello,

To sanity check your configuration settings use the 1 second flasher method, it works really well and is a nice double check that everything is right. I cannot really double check your config settings are valid without knowing the details of your hardware.

It looks to me from your project like you have a 16MHz crystal connected to the oscillator pins. The other config settings look fine though the power up timer can be useful if you want to enable this.
37: __config("__PROG_CONFIG", "pic18", 0x3, 0xFFFF);
^ (0) Can't find config word 3 used in in __PROG_CONFIG() (warning)
This can be safely ignored.

The other warnings are just telling you about workarounds the compiler is doing to get around known problems with the silicone.

SILVESTROS9
Posts: 115
Joined: Wed Aug 03, 2016 10:45 pm
Has thanked: 24 times
Been thanked: 11 times
Contact:

Re: PIC as MODBUS slave

Post by SILVESTROS9 »

Making some tests with flasher method , I note that the code with PIC18F458 don't start and therefore not run , while with PIC16F1939 works fine , I don't know why. Is there an error at code , or hardware needs modification? Hardware is simple , I don't think that there is a reason for modification . Is there a way to check the code for errors? Below I post a sketch of schematic for your opinion.
Attachments
MBSlaveLCD16.fcfx
(27.12 KiB) Downloaded 222 times
MODBUS LCD -SCH001.pdf
(1.84 MiB) Downloaded 244 times

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

Re: PIC as MODBUS slave

Post by Benj »

Hello,

From your schematic it looks like you're missing a resistor between pin 1 of the micro and VCC to pull the MCLR/Reset pin high. A value in the range of 1K to 100K should work well.

The 16F1937 has a configuration option for internal MCLR but the 18F458 does not which maybe explains the difference.

SILVESTROS9
Posts: 115
Joined: Wed Aug 03, 2016 10:45 pm
Has thanked: 24 times
Been thanked: 11 times
Contact:

Re: PIC as MODBUS slave

Post by SILVESTROS9 »

I connect a pull-up resistor 10K between pin1 and VDD , so the mcu works fine . Many thanks Ben !

Post Reply