Change UART Properties

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

Moderator: Benj

Post Reply
User avatar
AbhijitR
Posts: 299
Joined: Fri Nov 07, 2014 12:48 pm
Location: Pune, India
Has thanked: 280 times
Been thanked: 79 times
Contact:

Change UART Properties

Post by AbhijitR »

Hello!

I am using the MODBUS Slave component, the PIC chip is 18F26K42 running @16Mhz, everything is working good for the moment when communicating with MODSCAN32 or RADZIO on computer, but i am facing problem while communicating with some other hardware or other computer software which is demanding Parity and Stop Bit settings.

After reading the datasheet of the same chip (page 499 to 501, datasheet not able to attach due to size), i found few settings for UART Control Registers, in these settings i noticed it was possible to set the Parity as well the Stop bit for the UART (if i am not wrong the Modbus slave is working on RS232 bus), may i know if it is possible to change the settings of this registers accordingly after Initializing the Modbus Slave and before the beginning of the Loop in the Main, is the change valid and acceptable if written in C block, if yes may i request someone to help me how it is done.
PIC18F26K42Page499.PNG
PIC18F26K42Page499.PNG (59.47 KiB) Viewed 14654 times
PIC18F26K42Page4991.PNG
PIC18F26K42Page4991.PNG (101.02 KiB) Viewed 14654 times
PIC18F26K42Page501.PNG
PIC18F26K42Page501.PNG (98.23 KiB) Viewed 14654 times
Thank you.

Abhi

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: Change UART Properties

Post by Benj »

Hello Abhi,

If you want to do the fix using C code then you can add this line to a C-icon after initialising the Modbus component.

Odd parity on UART channel 1

Code: Select all

U1CON0 = U1CON0 | 0x02;
Even parity on UART channel 1

Code: Select all

U1CON0 = U1CON0 | 0x03;
Two Stop bits on UART channel 1

Code: Select all

U1CON2 = U1CON2 | 0x30;
For other channels replace U1 with U2 etc.

User avatar
AbhijitR
Posts: 299
Joined: Fri Nov 07, 2014 12:48 pm
Location: Pune, India
Has thanked: 280 times
Been thanked: 79 times
Contact:

Re: Change UART Properties

Post by AbhijitR »

Hello! Ben
Good afternoon

Many many thanks for the reply/answer, I shall try your suggestions after I reach home, I am sure that will work,.

Thank you again.

Abhi

User avatar
AbhijitR
Posts: 299
Joined: Fri Nov 07, 2014 12:48 pm
Location: Pune, India
Has thanked: 280 times
Been thanked: 79 times
Contact:

Re: Change UART Properties

Post by AbhijitR »

Hello! Ben
Good evening
Benj wrote:
Wed Oct 12, 2022 12:00 pm

If you want to do the fix using C code then you can add this line to a C-icon after initializing the Modbus component.
I tried one setting at a time in the C block, no doubt as you said after initializing the Modbus, also made necessary changes in the MODSCAN32 software on the computer but no luck.

Yesterday I tried few other settings, but nothing worked, I noticed only disable channel 1 setting worked, I purposely initialized the Modbus and added delay for 50mS and then add the below in C block after delay, only this setting worked, after that Modbus did not worked with MODSCAN32, so i was very sure after i hear from you.

Code: Select all

PMD5bits.U1MD=1;


Is there anything more you would like to suggest, meantime i will try to borrow a Modbus Master device (eg. HMI or any PLC) from friends if available to test on hardware instead of computer to validate if the new settings work on the slave.

Thank you again.

Abhi

User avatar
AbhijitR
Posts: 299
Joined: Fri Nov 07, 2014 12:48 pm
Location: Pune, India
Has thanked: 280 times
Been thanked: 79 times
Contact:

Re: Change UART Properties

Post by AbhijitR »

Hello!

Finally, the Modbus is working now, the change in the UART properties, i.e., Parity and Stop Bit, is achieved, as per what Ben mentioned in his previous post about using the C blocks to change the functions.

One will need to read the datasheet of their respective chip, it is clearly mentioned in the same about how to configure the UART properties, unfortunately I missed the same.

One of my forum friends (Peter) helped me to solve the problem, it is as below,

To stop the UART

Code: Select all

U1CON1bits.ON = 0;
Make the necessary changes in the properties

And again, start the UART

Code: Select all

U1CON1bits.ON = 1;
I hope this will be helpful to someone.

Thank you.

Abhi

Post Reply