BLE Communication between two nrf5340

Hello,

I have on nrf5340 an application, that meassures Temperature every second. I need to send the data to another nrf5340. I am going throw the bluetooth samples, but can't find, how can I astabilish the connection between two nrf5340s. Could you please recommend me some tutorial, that handles this issue?

Parents Reply Children
  • Hi Amanda

    thank you very much for the tips.

    While testing those samples, I can't get any output, that the Kits are connected. I only get a message "Starting Bluetooth Central UART example" in NRF TERMINAL, but nothing else. On the Kit with the Peripheral sample on it indicates the LED 2 that the Kit is connected, but in NRF TERMINAL is also only the "Starting Nordic UART service example" message. I also connected PuTTy to the Central, but I don!'t get any message here. I did not change anything in the Samples so far.

    Could you please give me an advice, what should I do?

    Regards, Jirik

  • Hi, 

    In the UART samples, the UART console is used to send and read data over the NUS service. Debug messages are not displayed in this UART console. Instead, they are printed by the RTT logger. If you want to view the debug messages, follow the procedure in Connecting using RTT. Once you connect via RTT, you can the event logs. 

    -Amanda

  • Hi Amanda

    Thank you very much for tips, I think I understood the connecting and the communication between the Central and Peripheral. Now I have problems with getting the data from the temperature sensors to the UART sending buffer. I get the temperature data with SPI interface as uint32_t.

    Would you have some advice for me?

    Jiri

  • Hi Amanda

    thank you for advice. I have still problems with the received data. 

    This is how is changed the ble_write_thread, I just added array number and variable length, and I'm increasing the number everz second and send it to the central.

    uint8_t number[1];
    uint16_t length;
    
    void ble_write_thread(void)
    {
    	/* Don't go any further until BLE is initialized */
    	k_sem_take(&ble_init_ok, K_FOREVER);
    	length = sizeof(number);
    	number[0] = 0b0000001;
    	for (;;) {
    		if (bt_nus_send(NULL, number, length)) {
    			LOG_WRN("Failed to send data over BLE connection");
    		}
    		number[0] ++;
    		length = sizeof(number);
    		k_msleep(1000);
    		printk("number %x\t length %x\n", number[0], length);
    	}
    }

    The output in PuTTy of the peripheral looks like this: 

    Starting Nordic UART service example
    
    number 2         length 1
    
    number 3         length 1
    
    number 4         length 1
    
    number 5         length 1
    

    When I do no changes to the central, the UART outputs in PuTTy are characters, which I do not need, I need the numbers, so I made following change.

    static uint8_t ble_data_received(struct bt_nus_client *nus,
    						uint8_t *data, uint16_t len)
    {
    	ARG_UNUSED(nus);
    
    	printk("%x\n", &data);
    	
    	return BT_GATT_ITER_CONTINUE;
    }

    In the central I just let the received data print to console like this (without sending it to UART).

    But now I don't get the data I send, I get something like this: 

    20003b94
    
    20003b94
    
    20003b94
    
    20003b94
    
    20003b94
    
    20003b94
    
    20003b94
    
    20003b94
    

    Some data, I don't understand, and every time same. How is it possible?

    I think in the central I work with wrong data, but I can't find the right.

    I also tried another sample, peripheral_hr and central_hr, I think this programm does the same thing as I tried, the peripheral sends every second increased number, and the central should receive it and print it, but it prints every time the same number.

    PuTTy - Peripheral

    Heartrate 141
    
    Heartrate 142
    
    Heartrate 143
    
    Heartrate 144
    
    Heartrate 145
    
    Heartrate 146
    
    Heartrate 147
    
    Heartrate 148
    
    Heartrate 149
    

    PuTTy - Central

    [NOTIFICATION] data 20005dc0 length 2
    
    [NOTIFICATION] data 20005dc0 length 2
    
    [NOTIFICATION] data 20005dc0 length 2
    
    [NOTIFICATION] data 20005dc0 length 2
    
    [NOTIFICATION] data 20005dc0 length 2
    
    [NOTIFICATION] data 20005dc0 length 2
    
    [NOTIFICATION] data 20005dc0 length 2
    
    [NOTIFICATION] data 20005dc0 length 2
    
    [NOTIFICATION] data 20005dc0 length 2
    
    

    I think it must be some other parameter read.

    Could you please give me an advice, how do I get to the data, I actually wanted to send?

    Jiri

Related