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

Re: Pi-4 Activating additional UART ports

Tue Aug 06, 2019 3:42 pm

i2c0 is irrelevant when you have i2c1!

But seriously, it depends on your application - if you are building a network-connected serial port concentrator then i2c is probably not that important.

danjperron
Posts: 3404
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Pi-4 Activating additional UART ports

Tue Aug 06, 2019 4:58 pm

i2c0 is irrelevant when you have i2c1!
This mean that ID_SD(pin 27) and ID_SC (pin 28) could be used for other things?
I though they were reserved for eerom on hat board ?

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

Re: Pi-4 Activating additional UART ports

Tue Aug 06, 2019 6:35 pm

On all Pis with 40-pin headers, pins 27 and 28 are wired to GPIOs 0 & 1, which are configured for I2C0. GPIOs 2 & 3, which can be configured for I2C1, are available on other header pins (3 & 5). This means that I2C0 is notionally reserved for the firmware (e.g. for driving the camera), but in practise on many Pis (including the 4B) by the time the ARMs are started the firmware will not use I2C0 again unless you use the camera.

danjperron
Posts: 3404
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Pi-4 Activating additional UART ports

Tue Aug 06, 2019 7:53 pm

Thanks PhilE,

Are you sure that is pin 28 and 29 . I think it is 27 and 28.

To summarize.

uart2 uses pins that could conflict with the camera and any kind of "hat" with eerom. Also If you enable the handshake, I2C1 has to be disabled.
uart3 use GPIO4 then you should consider to change 1 wire GPIO pin if you need 1 wire.
uart4 use the SPI GPIOs. SPI needs to be disabled.
No conflict with the uart5. This is the safest one to use.

oops uart3 uses GPIO7 if you enable handshake then you need to disable SPI.

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

Re: Pi-4 Activating additional UART ports

Tue Aug 06, 2019 8:20 pm

> Are you sure that is pin 28 and 29 . I think it is 27 and 28.

You're right - corrected. It comes from preferring to count from zero.

asafyurdakul
Posts: 2
Joined: Fri Dec 29, 2017 3:32 pm

Re: Pi-4 Activating additional UART ports

Wed Aug 07, 2019 10:08 am

Thank you PhilE
I have found my problem.

I have checked command "raspi-gpio get 0-15". I see that there is no problem like your result.
But when I run my program , the result of this command changed. 4,5 (Uart3) and 13 (Uart5) gpio pins "alt=4" properties are cleared and "func" properties are changed.

My program is runnig on mono c# platform.
I am using Unosquare library "https://github.com/unosquare/raspberryio". That is perfect library for mono.


On my program I was enabled SPI. I noticed that when I was done it 4,5 and 13 pins properties changed.
Cancelled codes are below
Pi.Init<BootstrapWiringPi>();
Pi.Spi.Channel0Frequency = SpiChannel.MinFrequency;

So, I cancelled these SPI init codes and problem solved. Now all 5 uarts works without any problem.

Best regards

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

Re: Pi-4 Activating additional UART ports

Wed Aug 07, 2019 10:15 am

I'm happy you found the problem. A lot of libraries talk directly to the hardware, bypassing the Linux drivers, sometimes for good reasons (the old sysfs API to GPIOs is notoriously slow - the new ioctl-based gpiolib interface is much quicker), sometimes not. If the Unosquare library had used a Linux API then it would have received an error indicating that the pins were in use, which should have been easier to track down.

leoP4
Posts: 6
Joined: Mon Aug 05, 2019 6:58 pm

Re: Pi-4 Activating additional UART ports

Wed Aug 07, 2019 1:31 pm

Hi everyone

I'm interested in the topic, but how to use the script? I can't understand the passage.
Sorry for the trivial question.

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

Re: Pi-4 Activating additional UART ports

Wed Aug 07, 2019 1:36 pm

Which script are you referring to? If you just want to enable one of the additional serial ports on Pi4, just add "dtoverlay=uart2" to config.txt, where "uart2" could also be "uart3", "uart4" or "uart5". After rebooting, and if you don't have a clash with something else that needs the same pins, you will find a new /dev/ttyAMA*.

leoP4
Posts: 6
Joined: Mon Aug 05, 2019 6:58 pm

Re: Pi-4 Activating additional UART ports

Wed Aug 07, 2019 1:43 pm

I was referring to the script mentioned above, that is #! / bin / sh

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

Re: Pi-4 Activating additional UART ports

Mon Aug 12, 2019 3:39 pm

That script just sends the characters 0-5 to ttyAMA0-5 every second. Attaching a serial cable to one of the groups of UART pins, the character that appears in your terminal emulator reveals which ttyAMA* it is connected to.

martinslater
Posts: 3
Joined: Mon Jun 27, 2016 8:31 am

Re: Pi-4 Activating additional UART ports

Thu Nov 14, 2019 10:22 am

Are these extra UART ports on the PI Zero W as well?
Last edited by martinslater on Thu Nov 14, 2019 10:27 am, edited 1 time in total.

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

Re: Pi-4 Activating additional UART ports

Thu Nov 14, 2019 10:27 am

No - they were new in the BCM2711, which is only used in the 4B.

martinslater
Posts: 3
Joined: Mon Jun 27, 2016 8:31 am

Re: Pi-4 Activating additional UART ports

Thu Nov 14, 2019 10:35 am

Darn. Thanks Phil

Return to “Device Tree”