BLE UART

We have an NRF52833 connected to the host board(runs LINUX) through UART can anyone help us with the code that goes in the NRF module that can make it work as a transceiver module(just like BLE adaptor) like sending data received from BLE to UART and data received from the host board to BLE

The final solution we are looking for is as follows: Using python on the host board we should be able to use NRF as a BLE adaptor and connect to BLE devices like sensors and receive data from them. All the connection and scanning and reading data code should be controlled or written in python and NRF should act like a transceiver module 

Can it be done? or are we looking in the wrong direction? 

  • sure waiting for your reply meanwhile we are doing the same setup on the Raspberry pi 3b+ just to verify its not jetson dev kit issue 

  • Hi,

    Can you check that there is no problems with the UART communication between the devices?

    Hi,

    I attempted to do more or less the same as you, and this is what I got (just to have a base-line of a working setup). When I test this on a DK with the HCI UART sample from nrF Connect SDK 2.3.0 and a Linux computer, I get things to work with this approach:

    1. Start "sudo bluetoothctl" in a terminal

    2. In another terminal:

    eith@eith-linux:~$ sudo hciattach -s 1000000 /dev/ttyACM2 any 1000000 flow nosleep
    Device setup complet

    3. I see this was successful in the bluetoothctl window:

    [NEW] Controller E4:CD:3F:87:10:E4 eith-linux.nordicsemi.no #2 [default]
    [CHG] Controller E4:CD:3F:87:10:E4 Powered: yes
    [CHG] Controller E4:CD:3F:87:10:E4 Alias: eith-linux.nordicsemi.no #2
    [CHG] Controller E4:CD:3F:87:10:E4 UUIDs: 0000110e-0000-1000-8000-00805f9b34fb
    ...

    4. Check status in bluetoothctl with show:

    [bluetooth]# show
    Controller E4:CD:3F:87:10:E4 (random)
    	Name: eith-linux.nordicsemi.no #2
    	Alias: eith-linux.nordicsemi.no #2
    	Class: 0x00000000
    	Powered: yes
    	Discoverable: no
    	DiscoverableTimeout: 0x000000b4
    	Pairable: yes
    	UUID: A/V Remote Control        (0000110e-0000-1000-8000-00805f9b34fb)
    	UUID: Handsfree Audio Gateway   (0000111f-0000-1000-8000-00805f9b34fb)
    	UUID: PnP Information           (00001200-0000-1000-8000-00805f9b34fb)
    	UUID: Audio Sink                (0000110b-0000-1000-8000-00805f9b34fb)
    	UUID: Headset                   (00001108-0000-1000-8000-00805f9b34fb)
    	UUID: A/V Remote Control Target (0000110c-0000-1000-8000-00805f9b34fb)
    	UUID: Generic Access Profile    (00001800-0000-1000-8000-00805f9b34fb)
    	UUID: Audio Source              (0000110a-0000-1000-8000-00805f9b34fb)
    	UUID: Generic Attribute Profile (00001801-0000-1000-8000-00805f9b34fb)
    	UUID: Device Information        (0000180a-0000-1000-8000-00805f9b34fb)
    	Modalias: usb:v1D6Bp0246d0540
    	Discovering: no
    	Roles: central
    	Roles: peripheral
    Advertising Features:
    	ActiveInstances: 0x00 (0)
    	SupportedInstances: 0x05 (5)
    	SupportedIncludes: appearance
    	SupportedIncludes: local-name
    

    5. Try to can in bluetoothhctl with "scan on", and I get a lot of devices found.

    6. I also see logs like this in btmon (this shows going from down to up with "sudo hciconfig hci1 up"

    eith@eith-linux:~$ sudo btmon
    Bluetooth monitor ver 5.64
    = Note: Linux version 5.19.0-38-generic (x86_64)                                                        0.250358
    = Note: Bluetooth subsystem version 2.22                                                                0.250360
    = New Index: 00:00:00:00:00:00 (Primary,UART,hci1)                                               [hci1] 0.250362
    = New Index: A0:59:50:DB:B0:13 (Primary,USB,hci0)                                                [hci0] 0.250362
    @ MGMT Open: bluetoothd (privileged) version 1.22                                              {0x0001} 0.250364
    @ RAW Open: hciconfig (privileged) version 2.22                                                {0x0002} 3.315125
    = Open Index: 00:00:00:00:00:00                                                                  [hci1] 3.315142
    < HCI Command: Read Local Supported Features (0x04|0x0003) plen 0                             #1 [hci1] 3.315158
    > HCI Event: Command Complete (0x0e) plen 12                                                  #2 [hci1] 3.315953
          Read Local Supported Features (0x04|0x0003) ncmd 1
            Status: Success (0x00)
            Features: 0x00 0x00 0x00 0x00 0x60 0x00 0x00 0x00
              BR/EDR Not Supported
              LE Supported (Controller)
    < HCI Command: Read Local Version Information (0x04|0x0001) plen 0                            #3 [hci1] 3.316014
    > HCI Event: Command Complete (0x0e) plen 12                                                  #4 [hci1] 3.316876
          Read Local Version Information (0x04|0x0001) ncmd 1
            Status: Success (0x00)
            HCI version: Reserved (0x0c) - Revision 4683 (0x124b)
            LMP version: Reserved (0x0c) - Subversion 4683 (0x124b)
            Manufacturer: Nordic Semiconductor ASA (89)
    < HCI Command: Read BD ADDR (0x04|0x0009) plen 0                                              #5 [hci1] 3.316910
    > HCI Event: Command Complete (0x0e) plen 10                                                  #6 [hci1] 3.317957
          Read BD ADDR (0x04|0x0009) ncmd 1
            Status: Success (0x00)
            Address: 00:00:00:00:00:00 (OUI 00-00-00)
    < HCI Command: LE Read Buffer Size (0x08|0x0002) plen 0                                       #7 [hci1] 3.317994
    > HCI Event: Command Complete (0x0e) plen 7                                                   #8 [hci1] 3.318932
          LE Read Buffer Size (0x08|0x0002) ncmd 1
            Status: Success (0x00)
            Data packet length: 27
            Num data packets: 3
    < HCI Command: LE Read Local Supported Features (0x08|0x0003) plen 0                          #9 [hci1] 3.318966
    > HCI Event: Command Complete (0x0e) plen 12                                                 #10 [hci1] 3.319993
          LE Read Local Supported Features (0x08|0x0003) ncmd 1
            Status: Success (0x00)
            Features: 0xfd 0x41 0x00 0x00 0x00 0x00 0x00 0x00
              LE Encryption
              Extended Reject Indication
              Peripheral-initiated Features Exchange
              LE Ping
              LE Data Packet Length Extension
              LL Privacy
              Extended Scanner Filter Policies
              LE 2M PHY
              Channel Selection Algorithm #2
    < HCI Command: LE Read Supported States (0x08|0x001c) plen 0                                 #11 [hci1] 3.320028
    > HCI Event: Command Complete (0x0e) plen 12                                                 #12 [hci1] 3.320880
          LE Read Supported States (0x08|0x001c) ncmd 1
            Status: Success (0x00)
            States: 0x000000ff000041ff
              Non-connectable Advertising State
              Scannable Advertising State
              Connectable Advertising State
              High Duty Cycle Directed Advertising State
              Passive Scanning State
              Active Scanning State
              Initiating State
                and Connection State (Central Role)
              Connection State (Peripheral Role)
              Non-connectable Advertising State
                and Passive Scanning State
              Connectable Advertising State
                and Active Scanning State
              Connectable Advertising State
                and Initiating State
                and Central Role & Peripheral Role
              High Duty Cycle Directed Advertising State
                and Initiating State
                and Central Role & Peripheral Role
              Low Duty Cycle Directed Advertising State
                and Initiating State
                and Central Role & Peripheral Role
              Connectable Advertising State
                and Connection State (Central Role)
                and Central Role & Peripheral Role
              High Duty Cycle Directed Advertising State
                and Connection State (Central Role)
                and Central Role & Peripheral Role
              Low Duty Cycle Directed Advertising State
                and Connection State (Central Role)
                and Central Role & Peripheral Role
              Connectable Advertising State
                and Connection State (Peripheral Role)
                and Central Role & Peripheral Role
              High Duty Cycle Directed Advertising State
                and Connection State (Peripheral Role)
                and Peripheral Role & Peripheral Role
    < HCI Command: Read Local Supported Commands (0x04|0x0002) plen 0                            #13 [hci1] 3.321362
    > HCI Event: Command Complete (0x0e) plen 68                                                 #14 [hci1] 3.323646
          Read Local Supported Commands (0x04|0x0002) ncmd 1
            Status: Success (0x00)
            Commands: 66 entries
              Disconnect (Octet 0 - Bit 5)
              Read Remote Version Information (Octet 2 - Bit 7)
              Set Event Mask (Octet 5 - Bit 6)
              Reset (Octet 5 - Bit 7)
              Read Transmit Power Level (Octet 10 - Bit 2)
              Set Controller To Host Flow Control (Octet 10 - Bit 5)
              Host Buffer Size (Octet 10 - Bit 6)
              Host Number of Completed Packets (Octet 10 - Bit 7)
              Read Local Version Information (Octet 14 - Bit 3)
              Read Local Supported Features (Octet 14 - Bit 5)
              Read BD ADDR (Octet 15 - Bit 1)
              Read RSSI (Octet 15 - Bit 5)
              Set Event Mask Page 2 (Octet 22 - Bit 2)
              LE Set Event Mask (Octet 25 - Bit 0)
              LE Read Buffer Size (Octet 25 - Bit 1)
              LE Read Local Supported Features (Octet 25 - Bit 2)
              LE Set Random Address (Octet 25 - Bit 4)
              LE Set Advertising Parameters (Octet 25 - Bit 5)
              LE Read Advertising Channel TX Power (Octet 25 - Bit 6)
              LE Set Advertising Data (Octet 25 - Bit 7)
              LE Set Scan Response Data (Octet 26 - Bit 0)
              LE Set Advertise Enable (Octet 26 - Bit 1)
              LE Set Scan Parameters (Octet 26 - Bit 2)
              LE Set Scan Enable (Octet 26 - Bit 3)
              LE Create Connection (Octet 26 - Bit 4)
              LE Create Connection Cancel (Octet 26 - Bit 5)
              LE Read Accept List Size (Octet 26 - Bit 6)
              LE Clear Accept List (Octet 26 - Bit 7)
              LE Add Device To Accept List (Octet 27 - Bit 0)
              LE Remove Device From Accept List (Octet 27 - Bit 1)
              LE Connection Update (Octet 27 - Bit 2)
              LE Set Host Channel Classification (Octet 27 - Bit 3)
              LE Read Channel Map (Octet 27 - Bit 4)
              LE Read Remote Used Features (Octet 27 - Bit 5)
              LE Encrypt (Octet 27 - Bit 6)
              LE Rand (Octet 27 - Bit 7)
              LE Start Encryption (Octet 28 - Bit 0)
              LE Long Term Key Request Reply (Octet 28 - Bit 1)
              LE Long Term Key Request Neg Reply (Octet 28 - Bit 2)
              LE Read Supported States (Octet 28 - Bit 3)
              LE Receiver Test (Octet 28 - Bit 4)
              LE Transmitter Test (Octet 28 - Bit 5)
              LE Test End (Octet 28 - Bit 6)
              Read Authenticated Payload Timeout (Octet 32 - Bit 4)
              Write Authenticated Payload Timeout (Octet 32 - Bit 5)
              LE Set Data Length (Octet 33 - Bit 6)
              LE Read Suggested Default Data Length (Octet 33 - Bit 7)
              LE Write Suggested Default Data Length (Octet 34 - Bit 0)
              LE Read Local P-256 Public Key (Octet 34 - Bit 1)
              LE Generate DHKey (Octet 34 - Bit 2)
              LE Add Device To Resolving List (Octet 34 - Bit 3)
              LE Remove Device From Resolving List (Octet 34 - Bit 4)
              LE Clear Resolving List (Octet 34 - Bit 5)
              LE Read Resolving List Size (Octet 34 - Bit 6)
              LE Set Address Resolution Enable (Octet 35 - Bit 1)
              LE Set Resolvable Private Address Timeout (Octet 35 - Bit 2)
              LE Read Maximum Data Length (Octet 35 - Bit 3)
              LE Read PHY (Octet 35 - Bit 4)
              LE Set Default PHY (Octet 35 - Bit 5)
              LE Set PHY (Octet 35 - Bit 6)
              LE Enhanced Receiver Test (Octet 35 - Bit 7)
              LE Enhanced Transmitter Test (Octet 36 - Bit 0)
              LE Read Transmit Power (Octet 38 - Bit 7)
              LE Set Privacy Mode (Octet 39 - Bit 2)
              Octet 41 - Bit 2 
              Octet 45 - Bit 6 
    < HCI Command: Set Event Mask (0x03|0x0001) plen 8                                           #15 [hci1] 3.323684
            Mask: 0x200080000204e890
              Disconnection Complete
              Encryption Change
              Read Remote Version Information Complete
              Command Complete
              Command Status
              Hardware Error
              Number of Completed Packets
              Data Buffer Overflow
              Encryption Key Refresh Complete
              LE Meta
    > HCI Event: Command Complete (0x0e) plen 4                                                  #16 [hci1] 3.324912
          Set Event Mask (0x03|0x0001) ncmd 1
            Status: Success (0x00)
    < HCI Command: LE Set Event Mask (0x08|0x0001) plen 8                                        #17 [hci1] 3.324940
            Mask: 0x0000000000080fdf
              LE Connection Complete
              LE Advertising Report
              LE Connection Update Complete
              LE Read Remote Used Features Complete
              LE Long Term Key Request
              LE Data Length Change
              LE Read Local P-256 Public Key Complete
              LE Generate DHKey Complete
              LE Enhanced Connection Complete
              LE Direct Advertising Report
              LE PHY Update Complete
              LE Channel Selection Algorithm
    > HCI Event: Command Complete (0x0e) plen 4                                                  #18 [hci1] 3.325896
          LE Set Event Mask (0x08|0x0001) ncmd 1
            Status: Success (0x00)
    < HCI Command: LE Read Advertising Channel TX Power (0x08|0x0007) plen 0                     #19 [hci1] 3.325981
    > HCI Event: Command Complete (0x0e) plen 5                                                  #20 [hci1] 3.326873
          LE Read Advertising Channel TX Power (0x08|0x0007) ncmd 1
            Status: Success (0x00)
            TX power: 0 dbm (0x00)
    < HCI Command: LE Read Transmit Power (0x08|0x004b) plen 0                                   #21 [hci1] 3.326924
    > HCI Event: Command Complete (0x0e) plen 6                                                  #22 [hci1] 3.327893
          LE Read Transmit Power (0x08|0x004b) ncmd 1
            Status: Success (0x00)
            Min Tx power: -40 dBm
            Max Tx power: 4 dBm
    < HCI Command: LE Read Accept List Size (0x08|0x000f) plen 0                                 #23 [hci1] 3.327927
    > HCI Event: Command Complete (0x0e) plen 5                                                  #24 [hci1] 3.328878
          LE Read Accept List Size (0x08|0x000f) ncmd 1
            Status: Success (0x00)
            Size: 8
    < HCI Command: LE Clear Accept List (0x08|0x0010) plen 0                                     #25 [hci1] 3.329023
    > HCI Event: Command Complete (0x0e) plen 4                                                  #26 [hci1] 3.329909
          LE Clear Accept List (0x08|0x0010) ncmd 1
            Status: Success (0x00)
    < HCI Command: LE Read Resolving List Size (0x08|0x002a) plen 0                              #27 [hci1] 3.330180
    > HCI Event: Command Complete (0x0e) plen 5                                                  #28 [hci1] 3.330880
          LE Read Resolving List Size (0x08|0x002a) ncmd 1
            Status: Success (0x00)
            Size: 8
    < HCI Command: LE Clear Resolving List (0x08|0x0029) plen 0                                  #29 [hci1] 3.331098
    > HCI Event: Command Complete (0x0e) plen 4                                                  #30 [hci1] 3.331892
          LE Clear Resolving List (0x08|0x0029) ncmd 1
            Status: Success (0x00)
    < HCI Command: LE Set Resolvable Private Address Timeout (0x08|0x002e) plen 2                #31 [hci1] 3.331928
            Timeout: 900 seconds
    > HCI Event: Command Complete (0x0e) plen 4                                                  #32 [hci1] 3.332873
          LE Set Resolvable Private Address Timeout (0x08|0x002e) ncmd 1
            Status: Success (0x00)
    < HCI Command: LE Read Maximum Data Length (0x08|0x002f) plen 0                              #33 [hci1] 3.332962
    > HCI Event: Command Complete (0x0e) plen 12                                                 #34 [hci1] 3.333897
          LE Read Maximum Data Length (0x08|0x002f) ncmd 1
            Status: Success (0x00)
            Max TX octets: 251
            Max TX time: 2704
            Max RX octets: 251
            Max RX time: 2704
    < HCI Command: LE Read Suggested Default Data Length (0x08|0x0023) plen 0                    #35 [hci1] 3.333930
    > HCI Event: Command Complete (0x0e) plen 8                                                  #36 [hci1] 3.334879
          LE Read Suggested Default Data Length (0x08|0x0023) ncmd 1
            Status: Success (0x00)
            TX octets: 27
            TX time: 328
    < HCI Command: Set Event Mask Page 2 (0x03|0x0063) plen 8                                    #37 [hci1] 3.334908
            Mask: 0x0000000000800000
              Authenticated Payload Timeout Expired
    > HCI Event: Command Complete (0x0e) plen 4                                                  #38 [hci1] 3.335893
          Set Event Mask Page 2 (0x03|0x0063) ncmd 1
            Status: Success (0x00)
    < HCI Command: LE Write Suggested Default Data Length (0x08|0x0024) plen 4                   #39 [hci1] 3.335924
            TX octets: 251
            TX time: 2704
    > HCI Event: Command Complete (0x0e) plen 4                                                  #40 [hci1] 3.336873
          LE Write Suggested Default Data Length (0x08|0x0024) ncmd 1
            Status: Success (0x00)
    < HCI Command: LE Set Default PHY (0x08|0x0031) plen 3                                       #41 [hci1] 3.336973
            All PHYs preference: 0x00
            TX PHYs preference: 0x01
              LE 1M
            RX PHYs preference: 0x01
              LE 1M
    > HCI Event: Command Complete (0x0e) plen 4                                                  #42 [hci1] 3.337950
          LE Set Default PHY (0x08|0x0031) ncmd 1
            Status: Success (0x00)
    = Index Info: 00:00:00:00:00:00 (Nordic Semiconductor ASA)                                       [hci1] 3.337977
    < HCI Command: LE Set Advertising Data (0x08|0x0008) plen 32                                 #43 [hci1] 3.338066
            Length: 6
            Flags: 0x04
              BR/EDR Not Supported
            TX power: 0 dBm
    > HCI Event: Command Complete (0x0e) plen 4                                                  #44 [hci1] 3.338987
          LE Set Advertising Data (0x08|0x0008) ncmd 1
            Status: Success (0x00)
    < HCI Command: LE Set Scan Response Data (0x08|0x0009) plen 32                               #45 [hci1] 3.339017
            Length: 13
            Name (short): eith-linux
    > HCI Event: Command Complete (0x0e) plen 4                                                  #46 [hci1] 3.339936
          LE Set Scan Response Data (0x08|0x0009) ncmd 1
            Status: Success (0x00)
    @ MGMT Event: New Settings (0x0006) plen 4                                              {0x0001} [hci1] 3.339968
            Current settings: 0x00008a01
              Powered
              Low Energy
              Secure Connections
              Static Address
    @ RAW Close: hciconfig                                                                         {0x0002} 3.340006
    
    

    The above shows how this should work normally just to have a base line of what to expect in a working setup.

    In your screenshots I do not see any obvious issues before the last one with bluetoothctl that shows you don't have any controllers (and probably as a consequence of that there is not much in btmon). I don't see any indication of why, though.

    Does this work if you try with your board on a normal Linux desktop computer? Or a DK on the desktop or even a DK with the Jetson?

  • we tried with the hciattach command you have given 

    Our setup -> Nvidia Jetson nano dev kit -- NRF52dk 

    1) hciattach outputs -> Device setup complete

    2) btmon output

    3) hciconfig command shows UART device with address 00:00:00:00:00 but its DOWN
    4)sudo hciconfig hci0 up gives timeout error



    NOTE: as u asked us to test the UART first we tested it with a UART echo bot it worked anything I type on nrf UART can be in the jetson UART serial monitor 
    https://docs.zephyrproject.org/3.1.0/samples/drivers/uart/echo_bot/README.html



    Few questions 

    1) Instead of nrf connect sdk sample we are using the zephyr hci_uart sample is that okay?
    https://docs.zephyrproject.org/2.7.0/samples/bluetooth/hci_uart/README.html

    2) can you confirm after hciattach , hciconfig shows an hci device with MTU 0.0 because we read that MTU should not be 0.0?

    3) if you are loading HCI UART sample how are you using /dev/ttyACM2 (this is for USB devices) are you using FTDI converter ?

    4)we are using /dev/ttyTHS1 as per jetson UART1. can you give us a way to check what device to select for hciattach because dmesg in Linux shows nothing about a new device connected via GPIO pins I think we are attaching the wrong serial device. 

  • Hi,

    Pradeep_kshemin said:
    1) Instead of nrf connect sdk sample we are using the zephyr hci_uart sample is that okay?
    https://docs.zephyrproject.org/2.7.0/samples/bluetooth/hci_uart/README.html

    Yes, this is the right one and the one I use, and the one I use. But use it from the nRF Connect SDK, of which Zephyr is a part. What I tested and that worked for me was the Zephyr HCI UART sample included in nRF Connect SDK 2.3.0 (under zephyr/samples/bluetooth/hci_uart/).

    Pradeep_kshemin said:
    2) can you confirm after hciattach , hciconfig shows an hci device with MTU 0.0 because we read that MTU should not be 0.0?

    I did not spot that in your screenshot, but you are right, that is yet another indication of an issue with your setup. On my end, I have this:

    eith@eith-linux:~$ hciconfig
    hci1:	Type: Primary  Bus: UART
    	BD Address: 00:00:00:00:00:00  ACL MTU: 27:3  SCO MTU: 0:0
    	UP RUNNING 
    	RX bytes:552 acl:0 sco:0 events:44 errors:0
    	TX bytes:274 acl:0 sco:0 commands:44 errors:0

    Pradeep_kshemin said:
    3) if you are loading HCI UART sample how are you using /dev/ttyACM2 (this is for USB devices) are you using FTDI converter ?

    Yes, you are right. I don't have a serial port on my computer. I am using the onboard debugger on a DK as a USB-UART bridge.

    Pradeep_kshemin said:
    4)we are using /dev/ttyTHS1 as per jetson UART1. can you give us a way to check what device to select for hciattach because dmesg in Linux shows nothing about a new device connected via GPIO pins I think we are attaching the wrong serial device. 

    That seems likely. Unlike with USB, there is no automatic detection of a device being connected to the serial pins, so you nee to know which it is connected to. I am not able to help you with that other than to suggest that you attempt to communicate with the nRF over UART in another way to ensure that you have the right serial port. Perhaps test a UART example on the device to see that you can write and get characters echoed back. Then you will know that the bi-directional communication is working, and also that you have the right device. You write that you did this though, so I assume that is good and that this was also with the same /dev/tty/*? If not, make sure you use the one you tested and found working.

  • from your reply -> Yes, you are right. I don't have a serial port on my computer. I am using the onboard debugger on a DK as a USB-UART bridge.

    we also did the same thing, loaded the hci_uart sample onto the DK and connected to our Linux computer 
    using DK USB_UART bridge. It worked i got the MTU as 27.7 and was able to scan and connect using bluetoothctl

    Now if it works with USB-UART bridge why it fails with jumper wires on TX(P0.06) and RX(P0.08) pins connected to our jetson UART pins (cross-connection rx-tx and tx-rx).

    we thought our jumper wires are damaged but no we replaced them with a new set of wires many times still haciattach doesn't give an MTU reading to start with its always 0.0

    can you tell us a way to change the tx rx pins of nrf in zephyr to make sure if the pins 6 and 8 are damaged for some reason?

    our current overlay file is 

    &uart0 {
        compatible = "nordic,nrf-uarte";
        current-speed = <1000000>;
        status = "okay";
        hw-flow-control;
    };




Related