Page 1 of 1

PIC24fj256GA406 RS-485 Based Modbus RTU

Posted: Fri Sep 11, 2020 9:46 am
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]

Re: PIC24fj256GA406 RS-485 Based Modbus RTU

Posted: Fri Sep 11, 2020 11:06 am
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.

Re: PIC24fj256GA406 RS-485 Based Modbus RTU

Posted: Fri Sep 11, 2020 6:41 pm
by seokgi
It was recognized by RS-232 communication. 1ms 1s timer works well.

Re: PIC24fj256GA406 RS-485 Based Modbus RTU

Posted: Wed Sep 16, 2020 10:55 am
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.

Re: PIC24fj256GA406 RS-485 Based Modbus RTU

Posted: Wed Sep 16, 2020 4:50 pm
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

Re: PIC24fj256GA406 RS-485 Based Modbus RTU

Posted: Thu Sep 17, 2020 1:44 am
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.

Re: PIC24fj256GA406 RS-485 Based Modbus RTU

Posted: Thu Sep 17, 2020 9:45 am
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.

Re: PIC24fj256GA406 RS-485 Based Modbus RTU

Posted: Wed Sep 23, 2020 8:14 am
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.

Re: PIC24fj256GA406 RS-485 Based Modbus RTU

Posted: Thu Sep 24, 2020 2:09 pm
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?

Re: PIC24fj256GA406 RS-485 Based Modbus RTU

Posted: Fri Sep 25, 2020 6:19 am
by seokgi
Here is my schematic.
Thanks for your help every time.

Re: PIC24fj256GA406 RS-485 Based Modbus RTU

Posted: Sat Sep 26, 2020 1:32 pm
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