nicolap8
Posts: 334
Joined: Mon Mar 13, 2017 9:45 pm

[RPi Zero W] UART not working when SPI1 enabled

Tue Mar 14, 2017 11:55 pm

Hi all,
using a RPi Zero W, last image, kernel 4.4.50, attached an USB hub and a keyboard.
Enabled the uart:
- "enable_uart=1" in config.txt
- removed reference to console in cmdline.txt
In /dev there are serial0 and serial1.
The serial1 belongs to Bluetooth (confirmed from command "systemctl status hciuart.service -l").
Installed Minicom.

If I start
minicom -b 9600 -o -D /dev/serial1
(tried other baudrate also) when I press a key the program starts to consume all cpu (I need to open another terminal and kill it).

When trying with serial0 the Rpi hangs and stops responding. Dead :-(

Here the dmesg:
kern :notice: [ 0.000000] Kernel command line: 8250.nr_uarts=1 bcm2708_fb.fbwidth=656 bcm2708_fb.fbheight=416 bcm2708_fb.fbswap=1 dma.dmachans=0x7f35 bcm2708.boardrev=0x9000c1 bcm2708.serial=0xac23f4f5 bcm2708.uart_clock=48000000 bcm2708.disk_led_gpio=47 smsc95xx.macaddr=B8:27:EB:23:F4:F5 vc_mem.mem_base=0x1ec00000 vc_mem.mem_size=0x20000000 dwc_otg.lpm_enable=0 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait
kern :info : [ 0.140429] uart-pl011 20201000.uart: could not find pctldev for node /soc/[email protected]/uart0_pins, deferring probe
kern :info : [ 0.297034] 20215040.uart: ttyS0 at MMIO 0x20215040 (irq = 53, base_baud = 50000000) is a 16550
kern :info : [ 0.973390] 20201000.uart: ttyAMA0 at MMIO 0x20201000 (irq = 81, base_baud = 0) is a PL011 rev2
kern :info : [ 13.976432] uart-pl011 20201000.uart: no DMA platform data
I know that this RPi switched the uarts and now on the header is present the port 1 (TXD1, RXD1), I need only to connect a GPS at 9600 baud.
Thanks for help
Nicola
Last edited by nicolap8 on Thu Mar 16, 2017 11:53 pm, edited 1 time in total.

dgordon42
Posts: 764
Joined: Tue Aug 13, 2013 6:55 pm
Location: Dublin, Ireland

Re: [RPi Zero W] Serial ports not working

Thu Mar 16, 2017 3:30 pm

nicolap8 wrote:using a RPi Zero W, last image, kernel 4.4.50, attached an USB hub and a keyboard.
Enabled the uart:
- "enable_uart=1" in config.txt
- removed reference to console in cmdline.txt
In /dev there are serial0 and serial1.
The serial1 belongs to Bluetooth (confirmed from command "systemctl status hciuart.service -l").
This all looks good.

Running "dmesg | grep uart" returns the same messages on my Pi 3B (I don't have a Zero W) as you have posted.
nicolap8 wrote:If I start
minicom -b 9600 -o -D /dev/serial1
(tried other baudrate also) when I press a key the program starts to consume all cpu (I need to open another terminal and kill it).

When trying with serial0 the Rpi hangs and stops responding. Dead
This is where things get a little strange.
If you point minicom at '/dev/serial0' with nothing connected to the Serial Port pins, I would expect minicom to appear to do nothing. It will blindly transmit any keys you press on the keyboard, but nothing will appear on the screen as nothing is connected to the Serial Port RxD pin.
If you connect TxD and Rxd (pyhsical pins 8 & 10) together, and run minicom again, any key you press on the keyboard will be echoed back onto the screen. This is a useful way of checking that your Serial Port works. It's called a loopback test.

If you point minicom at '/dev/serial1', then I would expect minicom to lock up, as '/dev/serial1' is owned by the Bluetooth hardware. You will need to use 'kill' to stop minicom.

You must not connect the Serial Port (or any other) GPIO pins to devices that operate at more than 3.3V. Many devices with serial ports operate at 5V, at some operate at up to +/- 15V. Doing so will most likely damage your Pi.

Some things you can check:
Ensure that you are on the correct GPIO pins.
Ensure that there are no "extra" UART commands in '/boot/config.txt' with:

Code: Select all

grep uart /boot/config.txt
This command must return a single line: "enable_uart=1". If it returns any other UART commands, comment them out or delete them, and reboot.
Connect GPIO physical pins 8 & 10 together, and use minicom to run the loopback check described above to verify youe Serial Port hardware and configuration.

One final thing, I noticed from your Linux command line that you removed "console=tty1", as well as "console=serial0,115200" from your '/boot/cmdline.txt' file. You should restore the "console=tty1" phrase, as it tells Linux to add a Virtual Console to your monitor at boot up. This could be very valuable if you ever have boot problems.

Good Luck,
Dave.

nicolap8
Posts: 334
Joined: Mon Mar 13, 2017 9:45 pm

Re: [RPi Zero W] Serial ports not working

Thu Mar 16, 2017 11:51 pm

Hi Gordon & all,
I must admit that I, ehm, omitted some particular: I have a board running with a RPi Zero (and a lot of elettronics) so I tried to swap the Zero with a ZeroW. In the process I modified the config.txt to enable W1, I2C, both SPI and a custom .dtbo.
My config.txt includes:

Code: Select all

dtparam=audio=off
dtdebug=on
gpu_mem=64
dtparam=i2c=on
dtparam=spi=on
dtoverlay=spi0-hw-cs
enable_uart=1
dtoverlay=w1-gpio,gpiopin=26
dtoverlay=pwm,pin=13,func=4
dtoverlay=spi1-3cs,cs2_pin=27
dtoverlay=epaper
Now I had a long session of adding one line at time, reboot, launch minicom, press some keys, repeat.
It seems that this line is causing the problem:

Code: Select all

dtoverlay=spi1-3cs,cs2_pin=27
I tested also with some variant(1) but doesn't matter: if SPI1 is enabled then using(2) UART1 (serial0) hangs the RPi.
Note: I ever checked the gpio configuration using raspi-gpio get and all pins seems ok.

1) variants, removed all changes, left only enable_uart=1 and:
- dtoverlay=spi1-1cs
- dtoverlay=spi1-1cs,cs0_pin=17 (16, 27 and some others)

2) at first key press = first data transmission

Now need to sleep ;-)
Thanks
Nicola

nicolap8
Posts: 334
Joined: Mon Mar 13, 2017 9:45 pm

Re: [RPi Zero W] UART not working when SPI1 enabled

Fri Mar 17, 2017 10:32 am

A followup.
I posted an issue at github. It seems that this problem is already known and there will be a solution.

References:
https://github.com/raspberrypi/linux/issues/1484
https://github.com/raspberrypi/linux/issues/1573
https://github.com/raspberrypi/linux/issues/1905

Thanks
Nicola

ViolaRobot
Posts: 2
Joined: Tue Oct 23, 2018 3:32 am

Re: [RPi Zero W] UART not working when SPI1 enabled

Tue Oct 23, 2018 3:47 am

I have a similar problem with my Pi-Zero w running the latest Raspbian Stretch lite release over SSH in headless mode. I tried all the suggestions, but none of them seemed to work. Furthermore, the minicom program remains inactive for some strange reason; no keyboard input works at any time and I am forced to shut down the shell and login again. That said, I have been testing the functionality with python (python3 using the standard serial library). The script I used should work on any other machine, and I have inserted a print() function to print out when the Pi has sent the data (a string encoded with "utf-8"), but there is no output. When I interrupt the script with Ctrl-C, it says the code has stopped at the point where the data should have sent: it has frozen at that line.

I did make some changes to the Pi's operating system when I first flashed the chip (enabling SSH and loading g_ethernet for initial bootup in headless mode, loading g_mass_storage for another project), but I have followed the instructions in the thread above to the letter (all save for the still-inoperable minicom commands) and nothing has worked. I have no other output to show. Do you know what might be going on?

Sincerely,
ViolaRobot

P.S. the python script I am using, for reference:

Code: Select all

#!/usr/bin/python3
import serial
import time
ser = serial.Serial("/dev/ttyAMA0", 9600)
data = 0
while True:
  #ser.write(str(data).encode("utf-8"))
  ser.write(str("\r\n").encode("utf-8"))
  print("Wrote data", data)
  time.sleep(1)
  data += 1

dgordon42
Posts: 764
Joined: Tue Aug 13, 2013 6:55 pm
Location: Dublin, Ireland

Re: [RPi Zero W] UART not working when SPI1 enabled

Tue Oct 23, 2018 9:19 am

As a quick fix, try changing "/dev/ttyAMA0" in your Python3 script to "/dev/serial0" and run it again. Thats SerialZero, not SerialOh.

If that does not help, report the output of the following commands:

Code: Select all

uname -a
cat /boot/cmdline.txt
grep -v -e ^# -e ^$ /boot/config.txt
Thanks,
Dave.
Last edited by dgordon42 on Tue Oct 23, 2018 9:28 am, edited 1 time in total.

DirkS
Posts: 9970
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: [RPi Zero W] UART not working when SPI1 enabled

Tue Oct 23, 2018 9:25 am

dgordon42 wrote:
Tue Oct 23, 2018 9:19 am

Code: Select all

grep -V -e ^# -e ^$ /boot/config.txt
I think that should be

Code: Select all

grep -v -e ^# -e ^$ /boot/config.txt

dgordon42
Posts: 764
Joined: Tue Aug 13, 2013 6:55 pm
Location: Dublin, Ireland

Re: [RPi Zero W] UART not working when SPI1 enabled

Tue Oct 23, 2018 9:27 am

Good catch, thanks.
I've edited my post above.

Dave.

ViolaRobot
Posts: 2
Joined: Tue Oct 23, 2018 3:32 am

Re: [RPi Zero W] UART not working when SPI1 enabled

Sun Oct 28, 2018 5:01 am

The program no longer blows up. To all appearances, it seems to be working, using serial0 (zero) or its other alias of ttyS0 (zero). The program functions as it should from the pi side of things.

However, something's still wrong: the receiving module is not getting anything. For this part of the setup, I have an Arduino with an Xbee board communicating with another Xbee connected to the pi via the serial pin. I know the Xbee chips work and that the Arduino is functional, so the only fault lies with something in the pi. I've tried poking around with various pins on the board and double checking with the pinout diagrams of both the Xbee and the pi to ensure I am using the right pins, but still I have nothing.

In addition, when I remove the TX pin from the pi, the program still says that it is writing data.

I ran the commands you listed. Here is the output:
1. Linux MY_PI'S_NAME 4.14.71+ #1145 Fri Sep 21 15:06:38 BST 2018 armv6l GNU/Linux
2. dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait modules-load=dwc2,g_ether,g_mass_storage
3. enable_uart=1

Can you make any sense of this?

Sincerely,
ViolaRobot

P.S. Sorry it's taken me a while to get back.

dgordon42
Posts: 764
Joined: Tue Aug 13, 2013 6:55 pm
Location: Dublin, Ireland

Re: [RPi Zero W] UART not working when SPI1 enabled

Mon Oct 29, 2018 4:46 pm

ViolaRobot wrote:I ran the commands you listed. Here is the output:
1. Linux MY_PI'S_NAME 4.14.71+ #1145 Fri Sep 21 15:06:38 BST 2018 armv6l GNU/Linux
2. dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait modules-load=dwc2,g_ether,g_mass_storage
3. enable_uart=1
This tells me that your RaspberryPi is running an up to date operating system, and is configured to use it's serial port pins when they are refered to as '/dev/serial0'. All good.
ViolaRobot wrote:In addition, when I remove the TX pin from the pi, the program still says that it is writing data.
All the Pi does is change the voltage levels on the Serial Port pins. It does knot know what (if anything) they are connected to, so what you observe is expected behavior.

Are you sure that your Xbee boards can work, and are configured to work, at the 3.3V level the Pi works at. I don't know what type of Xbee board you are using and so I cannot check this.

Dave.

Return to “Interfacing (DSI, CSI, I2C, etc.)”