PIC24fj256GA406 RS-485 Based Modbus RTU

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

Moderator: Benj

Post Reply
seokgi
Posts: 161
Joined: Fri Jan 13, 2012 4:21 am
Location: South KOREA
Contact:

PIC24fj256GA406 RS-485 Based Modbus RTU

Post by seokgi »

Hi!
I am working on a project using PIC24fj256GA406.
MODBUS Slave mode does not work.
I checked RX and TX using RS-232 port and RS-485 converter.
I upload my program.
Please review.
Thank you.[/b]
Attachments
SUN_Main_Test.fcfx
(29.77 KiB) Downloaded 14 times

User avatar
Benj
Matrix Staff
Posts: 15009
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Contact:

Re: PIC24fj256GA406 RS-485 Based Modbus RTU

Post by Benj »

Hello,

Have you confirmed your hardware is setup and running at the correct frequency with a 1 second flasher test. You will need to do this to ensure your UART baud rates are correct.

https://www.matrixtsl.com/wiki/index.ph ... ED_flasher

The values you have assigned to the holding registers are too large for the registers, the valid range is 0 to 65535.

seokgi
Posts: 161
Joined: Fri Jan 13, 2012 4:21 am
Location: South KOREA
Contact:

Re: PIC24fj256GA406 RS-485 Based Modbus RTU

Post by seokgi »

It was recognized by RS-232 communication. 1ms 1s timer works well.

seokgi
Posts: 161
Joined: Fri Jan 13, 2012 4:21 am
Location: South KOREA
Contact:

Re: PIC24fj256GA406 RS-485 Based Modbus RTU

Post by seokgi »

I have used several methods, but it doesn't work.
Replaced in anticipation of a defective chip. And I changed Read DDR from Low to Hihg. The received signal comes in as a result. However, it is not received from the communication program (Modbus Poll). If set serial TTL instead of Modbus mode, transmit Direction Pin in High state and receive it with RS-485 converter in Low state, it works well. For what reason? Please help me

Thank you.
Attachments
SUN_Main_RS485_Test.fcfx
(38.66 KiB) Downloaded 11 times

TaliG
Posts: 52
Joined: Fri Apr 07, 2017 1:55 am
Location: Greece
Contact:

Re: PIC24fj256GA406 RS-485 Based Modbus RTU

Post by TaliG »

Hi!

Can you explain what you are trying to accomplish please?
eg, I would like to read something from my hardware and see it on modbus poll.

Can you also confirm the following please?

1. Modbus poll is the master and PIC24 hardware is the slave.

2. Connection from your PC is a usb to rs485 dongle to an rs485 to uart converter to PIC24 uart.

If not, explain how you connect your PC to your hardware.

eg. PC to rs232 cable to rs232-ttl converter to PIC24, or any other way.

George

seokgi
Posts: 161
Joined: Fri Jan 13, 2012 4:21 am
Location: South KOREA
Contact:

Re: PIC24fj256GA406 RS-485 Based Modbus RTU

Post by seokgi »

Thanks for your interest. Sometimes I make mistakes without my knowledge. But I've been working in industrial automatic control for 30 years. Therefore, I am well aware of what I told you.
Thanks for the advice.

User avatar
Benj
Matrix Staff
Posts: 15009
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Contact:

Re: PIC24fj256GA406 RS-485 Based Modbus RTU

Post by Benj »

Hello,

Maybe worth increasing the reply delay to ensure the transmit state has time to ripple through to the master?

In your Modbus_Slave_2 macro each write is to the same holding register 0.

seokgi
Posts: 161
Joined: Fri Jan 13, 2012 4:21 am
Location: South KOREA
Contact:

Re: PIC24fj256GA406 RS-485 Based Modbus RTU

Post by seokgi »

I changed the MCU to PIC18F47Q10 and tested it.
However, the result is not good.
When I used MAX485 and tested it in RS-232 TTL mode, the data is not perfect due to timing problems, but it works well.
However, MODBUS RS-485 mode does not work.

PIC18F47Q10 has UARTINT0, but UARTINT1 is not visible.

Sorry for just asking questions every time.
Please help me.

I upload my program.
Attachments
MAX485_Serial_TTL_Test.fcfx
(14.45 KiB) Downloaded 6 times
MAX485_ModTest.fcfx
(15.26 KiB) Downloaded 4 times

User avatar
Benj
Matrix Staff
Posts: 15009
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Contact:

Re: PIC24fj256GA406 RS-485 Based Modbus RTU

Post by Benj »

Hello,

Thanks for letting us know regarding the Q10 device missing it's channel 2 interrupts, these have now been added for you.

Let us know if you spot anything further using RS485, can you share your hardware setup with a simple schematic just to make sure everything here is ok?

seokgi
Posts: 161
Joined: Fri Jan 13, 2012 4:21 am
Location: South KOREA
Contact:

Re: PIC24fj256GA406 RS-485 Based Modbus RTU

Post by seokgi »

Here is my schematic.
Thanks for your help every time.
Attachments
K-002.png
K-002.png (115.25 KiB) Viewed 197 times

TaliG
Posts: 52
Joined: Fri Apr 07, 2017 1:55 am
Location: Greece
Contact:

Re: PIC24fj256GA406 RS-485 Based Modbus RTU

Post by TaliG »

Hi,

In your schematic you are using a max13487 transceiver.
This chip has a build in state machine for auto direction control.
You do not need to use the DIR pin from your microcontroller.
Just connect the the RE and SHDN pins according to max13487 datasheet and use RS232 ttl method instead RS485 in your flowchart.

George

Post Reply