View previous topic :: View next topic |
Author |
Message |
neo19
Joined: 14 Aug 2012 Posts: 30 Location: France
|
PIC18F4550 and RS485 link |
Posted: Tue Apr 04, 2023 8:50 am |
|
|
Hello,
I need some advice about RS232 connection.
I use :
- PCWH compiler 5.050
- PIC 18F4550
- baud=115200
My PIC (Slave) communicates with a microprocessor board and It's working well.
The microprocessor board can read Voltage values from the PIC but it's slow when I use lots of slave PIC. Character frames are around 34 characters.
The PIC send directly the values with :
Code: |
for (i=0;i<=6;i++)
printf("%04.1f ",M_V[i]);
putc('\r');
|
I would like to optimise the speed of my RS232 connection and send only an 2 hexadecimal value instead of 5 Characters. So the Character frames will be reduce by 4 so around 14 characters.
I use this code :
Code: |
for (i=0;i<=6;i++)
{
VLCAN=M_V_int[i] & 0b11111111;
VHCAN=(M_V_int[i] & 0b111100000000)/16;
printf("%c%",VHCAN, VLCAN);
}
putc('\r');
|
with VHCAN and VLCAN are bytes
It's working well except if the value are less than 20 !!
In this case, I have strange behaviors.
Is there something I can do to solve this?
Thanks a lot for your help.
Last edited by neo19 on Wed Apr 05, 2023 7:48 am; edited 1 time in total |
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Tue Apr 04, 2023 9:28 am |
|
|
I think you have a misconception regarding RS232, since this type of cable communication only admits 2 devices
connected to each other, a DTE and a DCE. For the purposes of the RS-232 standard, a connection is defined by a
cable from one device to another, that is, between 2 devices.
neo19wrote:
Quote: | The microprocessor board can read Voltage values from the PIC but it's slow when I use lots of slave PIC. |
To achieve this you must implement a connection with RS485 protocol that supports various devices connected to
the network, which makes it possible for multiple nodes. _________________ Humber |
|
|
neo19
Joined: 14 Aug 2012 Posts: 30 Location: France
|
|
Posted: Wed Apr 05, 2023 7:50 am |
|
|
Hello Humberto,
You are right, I missed Something in my first message :
Of course I'm working with a RS485 connection and protocol. Else it could not work. |
|
|
gaugeguy
Joined: 05 Apr 2011 Posts: 303
|
|
Posted: Wed Apr 05, 2023 8:53 am |
|
|
It appears you are trying to mix ASCII characters and binary values together in one message. This will take some very special parsing to get to work as you found out binary values below 20 are ASCII control characters. |
|
|
|