csulz
Posts: 3
Joined: Tue May 29, 2018 6:56 pm

Connecting two UARTs together

Tue May 29, 2018 7:12 pm

Hello,

I am building an application where I intend that two CM3 units will use the serial lines to communicate between each other. I thought it would be a good start to have two processes on the same CM3 talking to each other. I was able to get /dev/serial0 and /dev/serial1 both working individually, This was verified by connecting TX to RX of the same UART and using minicom to see the loopback echo.

But now when I try to connect serial0 TX to serial1 RX and vice versa, minicom shows garbage characters no matter what I type.

I also tried connecting the CM3 to the UART pins of a pi3, closer to my intended application, making sure to keep a common ground, and I have the exact same problem there.

So is there something I am missing here? What other setup is needed to have two UARTs talk to each other?

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1760
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Connecting two UARTs together

Tue May 29, 2018 9:08 pm

Your original test - intra-UART loopback - will work whatever the baud rate, whereas the new test - inter-UART loopback - requires that both UARTs are operating at the same baud rate. Use stty (or a suitable library call) to set the baud rate for each UART.

An extra complication with ttyS0 (serial1 on a CM3) is that it shares a source clock with the VideoCore processors, so when the processors enters or leaves turbo mode the baud rate will change. Try adding "core_freq=250" to fix the clock at 250MHz (this happens automatically on a Bluetooth-equipped Pi when the UART (ttyS0 - serial0 on a BT Pi) is enabled.

csulz
Posts: 3
Joined: Tue May 29, 2018 6:56 pm

Re: Connecting two UARTs together

Wed May 30, 2018 11:38 pm

PhilE wrote:
Tue May 29, 2018 9:08 pm
Your original test - intra-UART loopback - will work whatever the baud rate, whereas the new test - inter-UART loopback - requires that both UARTs are operating at the same baud rate. Use stty (or a suitable library call) to set the baud rate for each UART.
I was using minicom to do the test, I made sure that they were both at the same baud rate. Would stty overwrite the baud rate setting in minicom? I used the command " minicom -b 115200 -o -D /dev/serial1" and in another console " minicom -b 115200 -o -D /dev/serial0"

PhilE wrote:
Tue May 29, 2018 9:08 pm
An extra complication with ttyS0 (serial1 on a CM3) is that it shares a source clock with the VideoCore processors, so when the processors enters or leaves turbo mode the baud rate will change. Try adding "cpu_freq=250" to fix the clock at 250MHz (this happens automatically on a Bluetooth-equipped Pi when the UART (ttyS0 - serial0 on a BT Pi) is enabled.
Is the cpu_freq setting in /boot/config.txt? Is it different than "arm_freq"? The CM3 doesnt have bluetooth so this would make sense. I figured that the clocks must have been getting desynchronized somehow. I will try your suggestion.

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1760
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Connecting two UARTs together

Thu May 31, 2018 5:48 am

"core_freq=250" (cpu_freq was an error that I have corrected to avoid confusing others) controls the VPU clock speed, and that of several peripheral interfaces. It is independent of the ARM clock, which is controlled by arm_freq.

csulz
Posts: 3
Joined: Tue May 29, 2018 6:56 pm

Re: Connecting two UARTs together

Fri Jun 01, 2018 11:21 pm

The core_freq setting seems to have fixed the problem, I am able to both talk between different UARTs on the same CM3 and communicate to other raspberry pis. Thank you for the help

Return to “Compute Module”

Who is online

Users browsing this forum: No registered users and 1 guest