0

I am trying to configure the UART on the Pi 4. I have entered enable_uart=1 into /boot/config.txt and I have

sudo systemctl disable serial-getty@ttyS0.service

and removed console=serial0,115200 from /boot/cmdline.txt.

Here is the C code I got fromwiringPi:

include <stdio.h>
#include <string.h>
#include <errno.h>

#include <wiringPi.h>
#include <wiringSerial.h>

int main ()
{
  int serial_port ;
  char dat;
  if ((serial_port = serialOpen ("/dev/ttyAMA0", 115200)) < 0)  /* open serial port */
  {
    fprintf (stderr, "Unable to open serial device: %s\n", strerror (errno)) ;
    return 1 ;
  }

  if (wiringPiSetup () == -1)   /* initializes wiringPi setup */
  {
    fprintf (stdout, "Unable to start wiringPi: %s\n", strerror (errno)) ;
    return 1 ;
  }

  while(1){

        if(serialDataAvail (serial_port) )
   {
                //dat = serialGetchar (serial_port); /* receive character serially*/
                //printf ("%c", dat) ;
                //fflush (stdout) ;
                serialPutchar(serial_port, '@');  /* transmit character serially on port */
                  }
        }

}

What did I not do?

Tony
  • 13
  • 1
  • 3

1 Answers1

1

Don't bother with trying to manually configure UART - use the menu in raspi-config which gets it right. You have disable the serial port by trying to do it manually (probobly by following some obsolete instructions).

/dev/ttyAMA0 is connected to Bluetooth - use dev/serial0

See How do I make serial work on the Raspberry Pi3 , Pi3B+, PiZeroW

Milliways
  • 54,718
  • 26
  • 92
  • 182