Code: Select all
dtoverlay=pi3-miniuart-bt
Code: Select all
uart_fd = open("/dev/serial0", O_RDWR | O_NOCTTY | O_NDELAY);
But in this case a Bluetooth is not available.
So how to configure RPi 4 to work with both modules?
Code: Select all
dtoverlay=pi3-miniuart-bt
Code: Select all
uart_fd = open("/dev/serial0", O_RDWR | O_NOCTTY | O_NDELAY);
Code: Select all
dtoverlay=pi3-miniuart-bt
Code: Select all
enable_uart=1
without the line - pi3-miniuart-bt - UART prints gibberish.dgordon42 wrote: ↑Sun Jan 12, 2020 11:56 amIt's not necessary to useto use the UART's on a Pi, just addCode: Select all
dtoverlay=pi3-miniuart-bt
to the '/boot/config.txt' file and reboot instead. The miniUART will now be available as a serial port on the GPIO pin, and it's clocking, etc., will be set up as necessary. The miniUART is sufficient for most serial port applications.Code: Select all
enable_uart=1
If you do need to use the full UART, then you will need to use "pi3-miniuart-bt", but you should follow the procedure in the '/boot/overlays/README' file. You will need to set values for 'core_freq' and 'core_freq_min' in '/boot/config.txt'. The values depend on your Pi model and may be found here.
Also, you should note that the DT Parameter 'pi3-miniuart-bt' has now been changed to just 'miniuart-bt' but the old style remains for backward compatibility.
The Serial Port will still appear at '/dev/serial0', and Bluetooth will still operate using either of the above procedures.
Hope this helps,
Dave.
Not sure why you are experiencing this.john77 wrote:without the line - pi3-miniuart-bt - UART prints gibberish.
Code: Select all
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# serial_port_loopback3.py
# Will also work on Python2.
# Serial port testing on a RaspberryPi
from __future__ import print_function
import serial
test_string = "Testing 1 2 3 4".encode('utf-8')
#test_string = b"Testing 1 2 3 4" ### Will also work
port_list = ["/dev/serial0"]
for port in port_list:
try:
serialPort = serial.Serial(port, 115200, timeout = 2)
serialPort.flushOutput()
serialPort.flushInput() # Syntax may change in new version of python3-serial
print("Opened port", port, "for testing:")
bytes_sent = serialPort.write(test_string)
print ("Sent", bytes_sent, "bytes")
loopback = serialPort.read(bytes_sent)
if loopback == test_string:
print ("Received", len(loopback), "valid bytes, Serial port", port, "working \n")
else:
print ("Received incorrect data", loopback, "over Serial port", port, "loopback\n")
serialPort.close()
except:
#except IOError:
print ("Failed at", port, "\n")
# That's it!
Code: Select all
enable_uart=1
Code: Select all
core_freq=500
core_freq_min=500
dtoverlay=miniuart-bt
Thank you. I'll consider this solution. As we are limited on GPIOs I have to spare every pin for other functionalities.
Pls have a look here:
Apparently it looks like, if you give Bluetooth the UART0, then the mini uart (barely usable) must be on TX-RX @GPIO 14-15.Adding "enable_uart=1" to config.txt on a Pi4 enables ttyS0 (UART1) on GPIOs 14 & 15 (Alt5), leaving UART0 driving the Bluetooth interface on 30-33 (Alt3).
So right now, with dtoverlay=miniuart-bt I use a mini-uart? Actually it works quite well with a baud rate 115200. Another option - to use GPIO 0-1 and free GPIO 14-15 for other purpose?rin67630 wrote: ↑Mon Jan 13, 2020 1:08 pmApparently it looks like, if you give Bluetooth the UART0, then the mini uart (barely usable) must be on TX-RX @GPIO 14-15.
The new UARTs 2-5 can only be mapped to other pins in ALT-4 mode. If you are short on pins and are not happy with the mini uart, then the solution could have been to disable the mini-UART and use GPIO 14-15 for another purpose.
If you don't need the HAT EEPROM feature, you might use UART2 (/dev/ttyAMA1) at GPIO 0 and 1 in ALT4 mode.
Incorrect, with "dtoverlay=miniuart-bt", Bluetooth uses the miniUART 'ttyS0' internally and you use the full UART 'ttyAMA0' as the Serial Port on GPIO pins 14 and 15 (physical pins 8 and 10). The clue is in the name.john77 wrote:So right now, with dtoverlay=miniuart-bt I use a mini-uart?
OK. But what's the problem to use miniUART with Blutooth?dgordon42 wrote: ↑Tue Jan 14, 2020 1:32 pmIncorrect, with "dtoverlay=miniuart-bt", Bluetooth uses the miniUART 'ttyS0' internally and you use the full UART 'ttyAMA0' as the Serial Port on GPIO pins 14 and 15 (physical pins 8 and 10). The clue is in the name.john77 wrote:So right now, with dtoverlay=miniuart-bt I use a mini-uart?
Dave.
Code: Select all
int BT_Open(void)
{
bt_dev_id = hci_get_route(nullptr);
bt_sock = hci_open_dev(bt_dev_id);
if (bt_dev_id < 0 || bt_sock < 0)
{
printf ("Bluetooth initialization failed fail\n");
return -1;
}
else
printf ("Bluetooth device id = %d, socket = %d\n", bt_dev_id, bt_sock);
return 0;
}
void BT_Scan(void)
{
int flags = IREQ_CACHE_FLUSH;
int max_resp = 2;
int len=8, i;
char addr[19] = { 0 };
char name[248] = { 0 };
inquiry_info *inq_info = (inquiry_info *) malloc (max_resp * sizeof(inquiry_info));
int num_rsp = hci_inquiry(bt_dev_id, len, max_resp, nullptr, &inq_info, flags);
if (num_rsp < 0)
{
printf ("Inquiry error\n");
free(inq_info);
return;
}
for (i=0; i<num_rsp; i++)
{
ba2str(&(inq_info+i)->bdaddr, addr);
memset(name, 0 , sizeof(name));
if (hci_read_remote_name(bt_sock, &(inq_info+i)->bdaddr, sizeof(name), name, 0) < 0)
strcpy (name, "[unknown]");
printf ("%s %s\n", addr, name);
}
free(inq_info);
}