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.
Thank you.
Abhi
Change UART Properties
Moderator: Benj
- 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
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
Even parity on UART channel 1
Two Stop bits on UART channel 1
For other channels replace U1 with U2 etc.
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;
Code: Select all
U1CON0 = U1CON0 | 0x03;
Code: Select all
U1CON2 = U1CON2 | 0x30;
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
- AbhijitR
- Posts: 300
- Joined: Fri Nov 07, 2014 12:48 pm
- Location: Pune, India
- Has thanked: 283 times
- Been thanked: 80 times
Re: Change UART Properties
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
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
- AbhijitR
- Posts: 300
- Joined: Fri Nov 07, 2014 12:48 pm
- Location: Pune, India
- Has thanked: 283 times
- Been thanked: 80 times
Re: Change UART Properties
Hello! Ben
Good evening
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.
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
Good evening
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
- AbhijitR
- Posts: 300
- Joined: Fri Nov 07, 2014 12:48 pm
- Location: Pune, India
- Has thanked: 283 times
- Been thanked: 80 times
Re: Change UART Properties
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
Make the necessary changes in the properties
And again, start the UART
I hope this will be helpful to someone.
Thank you.
Abhi
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;
And again, start the UART
Code: Select all
U1CON1bits.ON = 1;
Thank you.
Abhi