This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nrf 5340 for Bluetooth low energy

Hi!

This tutorial is just for current Measuring current. I want the same for latency with code. 

I'm working with two nrf5340 for Bluetooth low energy and I want to measure latency value between those cards using oscilloscope. Is there any sample code that I can use to send data  and receive it in the other cord. I want to allow  one bin in the first nrf5340 to write data and a bin in the other nrf5340 to read this data. 

2. I also want to measure RSSI. Is is possible to do that using the same method. I mean that I want to measure RSSI when the two cards are connected to each other.

Best regards  

Parents
  • I want the same for latency with code. 

    I'm working with two nrf5340 for Bluetooth low energy and I want to measure latency value between those cards using oscilloscope.

     Could you please explain what exactly you meant by "measure latency value between those cards" ? 


    If you want to track the communication between two device over the air you can use the nRF sniffer. 

    The latency between a packet sent and when it's received on the peer device depends on the connection interval, slave latency and if there is any other packets to be sent queued before the current packet. 

    2. If you want to measure RSSI of the advertising packet, you have that report in the bt_le_scan_recv_info  *device_inf in the scan callbacks. 

    When you are in a connection I'm not so sure how you can get it, but I found some config here that maybe related. 

  • Hi!

    I use this printf("%d\n",device_inf->rssi); to print RSSI value but I receive the  same value all the time  105 regardless if I change direction for other nrf5340 or not. How can i receive right value?

Reply Children
  • Hi Marwa, 
    Please show where exactly you print the value, also try to print the advertising, just to be sure you captured the correct advertising packets.

    Have you tried to scan for all devices just to see if you can capture all advertising packets from different devices ? 

    Hung

  • I don't now where I should put it but I put it in case UART_RX_BUF_RELEASED in Central UART example and I didn't do any thing in Perihelial UART example. I don't understand why I get the same value.

    static void uart_cb(const struct device *dev, struct uart_event *evt, void *user_data)
    {
    	ARG_UNUSED(dev);
    
    	static uint8_t *current_buf;
    	static size_t aborted_len;
    	static bool buf_release;
    	struct uart_data_t *buf;
    	static uint8_t *aborted_buf;
           // const struct  device *dev;
            dev = device_get_binding("GPIO_0");
            gpio_pin_configure(dev, 27, GPIO_OUTPUT); 
    
    	switch (evt->type) {
    	case UART_TX_DONE:
    		if ((evt->data.tx.len == 0) ||
    		    (!evt->data.tx.buf)) {
                  
    			return;
    		}
    
    		if (aborted_buf) {
    			buf = CONTAINER_OF(aborted_buf, struct uart_data_t,
    					   data);
    			aborted_buf = NULL;
    			aborted_len = 0;
    		} else {
    			buf = CONTAINER_OF(evt->data.tx.buf,
    					   struct uart_data_t,
    					   data);
    		}
    
    		k_free(buf);
    
    		buf = k_fifo_get(&fifo_uart_tx_data, K_NO_WAIT);
    		if (!buf) {
                           
                            gpio_pin_set(dev,27,0);
    			return;
    		}
    
    		if (uart_tx(uart, buf->data, buf->len, SYS_FOREVER_MS)) {
    			LOG_WRN("Failed to send data over UART");
    		}
                
    		break;
    
    	case UART_RX_RDY:
    		buf = CONTAINER_OF(evt->data.rx.buf, struct uart_data_t, data);
    		buf->len += evt->data.rx.len;
    		buf_release = false;
                    
    
    		if (buf->len == UART_BUF_SIZE) {
    			k_fifo_put(&fifo_uart_rx_data, buf);
    		} else if ((evt->data.rx.buf[buf->len - 1] == '\n') ||
    			  (evt->data.rx.buf[buf->len - 1] == '\r')) {
    			k_fifo_put(&fifo_uart_rx_data, buf);
    			current_buf = evt->data.rx.buf;
    			buf_release = true;
    			uart_rx_disable(uart);
    		}
                    
    		break;
    
    	case UART_RX_DISABLED:
    		buf = k_malloc(sizeof(*buf));
    		if (buf) {
    			buf->len = 0;
    		} else {
    			LOG_WRN("Not able to allocate UART receive buffer");
    			k_delayed_work_submit(&uart_work,
    					      UART_WAIT_FOR_BUF_DELAY);
                           
    			return;
    		}
    
    		uart_rx_enable(uart, buf->data, sizeof(buf->data),
    			       UART_RX_TIMEOUT);
                    
                  
    		break;
    
    	case UART_RX_BUF_REQUEST:
    		buf = k_malloc(sizeof(*buf));
    		if (buf) {
    			buf->len = 0;
    			uart_rx_buf_rsp(uart, buf->data, sizeof(buf->data));
    		} else {
    			LOG_WRN("Not able to allocate UART receive buffer");
    		}
    
    		break;
    
    	case UART_RX_BUF_RELEASED:
    		buf = CONTAINER_OF(evt->data.rx_buf.buf, struct uart_data_t,
    				   data);
    		if (buf_release && (current_buf != evt->data.rx_buf.buf)) {
    			k_free(buf);
    			buf_release = false;
    			current_buf = NULL;
    		}
                    gpio_pin_set(dev,27,1);
                    printf("%d\n",device_inf->rssi);
    		break;
    
    	case UART_TX_ABORTED:
    			if (!aborted_buf) {
    				aborted_buf = (uint8_t *)evt->data.tx.buf;
    			}
    
    			aborted_len += evt->data.tx.len;
    			buf = CONTAINER_OF(aborted_buf, struct uart_data_t,
    					   data);
    
    			uart_tx(uart, &buf->data[aborted_len],
    				buf->len - aborted_len, SYS_FOREVER_MS);
                           
                           
    		break;
    
    	default:
    		break;
    	}
    }
     

  • No, I don't think it's the place to call the function. You should put it inside the scan_filter_match() (or scan_filter_no_match) function.

    Please have a look at my blog here, it may help. 

  • Hi!

    I put it in both function but I get value in  scan_filter_match() function. I still get the same value with which is not correct.  RSSI will be between 0-100 but the best result is 50 so i don't now what 105 stands for and why it never changes.

    static void scan_filter_match(struct bt_scan_device_info *device_info,
    			      struct bt_scan_filter_match *filter_match,
    			      bool connectable)
    {
    	char addr[BT_ADDR_LE_STR_LEN];
    
    	bt_addr_le_to_str(device_info->recv_info->addr, addr, sizeof(addr));
    
    	LOG_INF("Filters matched. Address: %s connectable: %d",
    		log_strdup(addr), connectable);
           // LOG_INF("%d\n",inf->rssi);
            printf("%d\n",inf->rssi);
    }

  • Please explain why you come up with "inf->rssi" ? 

    What is inf variable ? 
    Please study how a callback function work and the arguments come with it. 

Related