nRF7002 DK external UART communication logic level conversion?

Hi,

I am using nRF7002 DK. I have set P1.04 as UART RX. For testing I am using TI CC26x2R1 Launchpad to send UART data to nRF7002 DK. I use a logic level shifter board to convert the UART 3.3V to 1.8V. Here is my setup below.

There is no UART activity from my logic analyzer capture.

How do I make this work?

Regards,

Markel

Parents
  • Hello,

    You need to select a different GPIO which is free and available. Could you post your overlay files and code where you initialize the UART device? is there any signal on the used pins for UART communication?

    Thanks.

    BR

    Kazi

  • Hi,

    I am using blefund_less2_exer2_solution as base. https://github.com/NordicDeveloperAcademy/bt-fund

    overlay file:

    &uart0 {
        current-speed = <9600>;
        pinctrl-0 = <&uart0_default>;
        pinctrl-1 = <&uart0_sleep>;
        pinctrl-names = "default", "sleep";
    };
       
    &pinctrl {
        uart0_default: uart0_default {
            group1 {
                psels = <NRF_PSEL(UART_TX, 0, 5)>;
            };
            group2 {
                psels = <NRF_PSEL(UART_RX, 0, 4)>;
                bias-pull-up;
            };
        };
       
        uart0_sleep: uart0_sleep {
            group1 {
                psels = <NRF_PSEL(UART_TX, 0, 5)>;
            };
            group2 {
                psels = <NRF_PSEL(UART_RX, 0, 4)>;
                bias-pull-up;
            };
        };
    };

    main.c:

    #include <zephyr/kernel.h>
    #include <zephyr/device.h>
    #include <zephyr/devicetree.h>
    #include <zephyr/logging/log.h>
    #include <zephyr/bluetooth/bluetooth.h>
    #include <zephyr/bluetooth/gap.h>
    #include <dk_buttons_and_leds.h>
    #include <zephyr/drivers/gpio.h>
    #include <zephyr/sys/printk.h>
    #include <string.h>
    #include <zephyr/drivers/uart.h>
    #include "df2301q.h"
    
    #define COMPANY_ID_CODE 0x0059 // Nordic BLE ID
    
    #define DEVICE_NAME CONFIG_BT_DEVICE_NAME
    #define DEVICE_NAME_LEN (sizeof(DEVICE_NAME) - 1)
    
    #define RUN_STATUS_LED DK_LED1
    #define RUN_LED_BLINK_INTERVAL 1000
    
    #define USER_BUTTON1 DK_BTN1_MSK
    #define USER_BUTTON2 DK_BTN2_MSK
    
    /* Define the size of the UART receive buffer */
    #define RECEIVE_BUFF_SIZE 13
    
    /* Define the receiving timeout period */
    #define RECEIVE_TIMEOUT 1000
    
    /* RTOS Task properties */
    #define SB_STACKSIZE       1024
    #define SB_PRIORITY        5 
    
    /* Define semaphore */
    K_SEM_DEFINE(sem, 0, 1);
    
    /* Declare the structure for your custom data  */
    typedef struct adv_mfg_data {
    	uint16_t company_code; /* Company Identifier Code. */
    	//uint16_t number_press; /* Number of times Button 1 is pressed */
    	uint8_t home_points;
    	uint8_t guest_points;
    	uint8_t home_set;
    	uint8_t guest_set;
    	uint8_t serving_horn; 
    } adv_mfg_data_type;
    
    /* Create an LE Advertising Parameters variable */
    static struct bt_le_adv_param *adv_param = BT_LE_ADV_PARAM(BT_LE_ADV_OPT_NONE, /* No options specified */
    											800, /* Min Advertising Interval 500ms (800*0.625ms) */
    											801, /* Max Advertising Interval 500.625ms (801*0.625ms) */
    											NULL); /* Set to NULL for undirected advertising */
    
    /* Define and initialize a variable of type adv_mfg_data_type */
    static adv_mfg_data_type adv_mfg_data = {COMPANY_ID_CODE, 0x00, 0x00, 0x00, 0x00, 0x00};
    
    static unsigned char url_data[] = { 0x17, '/', '/', 'a', 'c', 'a', 'd', 'e', 'm',
    				    				'y',  '.', 'n', 'o', 'r', 'd', 'i', 'c', 's',
    				    				'e',  'm', 'i', '.', 'c', 'o', 'm' };
    
    LOG_MODULE_REGISTER(Lesson2_Exercise2, LOG_LEVEL_INF);
    
    static const struct bt_data ad[] = {
    	BT_DATA_BYTES(BT_DATA_FLAGS, BT_LE_AD_NO_BREDR),
    	BT_DATA(BT_DATA_NAME_COMPLETE, DEVICE_NAME, DEVICE_NAME_LEN),
    	/* Include the Manufacturer Specific Data in the advertising packet. */
    	BT_DATA(BT_DATA_MANUFACTURER_DATA, (unsigned char *)&adv_mfg_data, sizeof(adv_mfg_data)),
    };
    
    static const struct bt_data sd[] = {
    	BT_DATA(BT_DATA_URI, url_data, sizeof(url_data)),
    };
    
    /* Get the device pointer of the UART hardware */
    const struct device *uart= DEVICE_DT_GET(DT_NODELABEL(uart0));
    
    /* STEP 10.1.2 - Define the receive buffer */
    static uint8_t rx_buf[RECEIVE_BUFF_SIZE] = {0};
    
    static uint8_t tx_buf[] =   {"Score Board Broadcaster\n\r"};
    
    /* STEP 7 - Define the callback function for UART */
    static void uart_cb(const struct device *dev, struct uart_event *evt, void *user_data)
    {
    	switch (evt->type) {
    
    	case UART_RX_RDY:		
    		k_sem_give(&sem);	
    	break;
    
    	case UART_RX_DISABLED:
    		uart_rx_enable(dev ,rx_buf,sizeof rx_buf,RECEIVE_TIMEOUT);
    	break;
    		
    	default:
    	break;
    	}
    }
    
    /* Add the definition of callback function and update the advertising data dynamically */
    static void button_changed(uint32_t button_state, uint32_t has_changed)
    {
    	if (has_changed & button_state & USER_BUTTON1) {
    		//adv_mfg_data.home_points += 1;
    		//bt_le_adv_update_data(ad, ARRAY_SIZE(ad), sd, ARRAY_SIZE(sd));
    	}
    
    	if (has_changed & button_state & USER_BUTTON2) {
    		//adv_mfg_data.guest_points += 1;
    		//bt_le_adv_update_data(ad, ARRAY_SIZE(ad), sd, ARRAY_SIZE(sd));
    	}
    
    }
    /* Define the initialization function of the buttons and setup interrupt.  */
    static int init_button(void)
    {
    	int err;
    
    	err = dk_buttons_init(button_changed);
    	if (err) {
    		printk("Cannot init buttons (err: %d)\n", err);
    	}
    
    	return err;
    }
    
    int thread0(void)
    {	
    	int err;
    
    	/* Setup leds on your board  */
    	err = dk_leds_init();
    	if (err) {
    		LOG_ERR("LEDs init failed (err %d)\n", err);
    		return -1;
    	}
    
    	//dk_set_led(RUN_STATUS_LED, 1);
    
    	/* Setup buttons on your board  */
    	err = init_button();
    	if (err) {
    		printk("Button init failed (err %d)\n", err);
    		return -1;
    	}
    
    	/* Verify that the UART device is ready */ 
    	if (!device_is_ready(uart)){
    		printk("UART device not ready\r\n");
    		return -1;
    	}
    
    	/* Register the UART callback function */
    	err = uart_callback_set(uart, uart_cb, NULL);
    	if (err) {
    		return -1;
    	}
    
    	/* Bluetooth enable */
    	err = bt_enable(NULL);
    	if (err) {
    		LOG_ERR("Bluetooth init failed (err %d)\n", err);
    		return -1;
    	}
    
    	LOG_INF("Bluetooth initialized\n");
    
    	err = bt_le_adv_start(adv_param, ad, ARRAY_SIZE(ad), sd, ARRAY_SIZE(sd));
    	if (err) {
    		LOG_ERR("Advertising failed to start (err %d)\n", err);
    		return -1;
    	}
    
    	LOG_INF("Advertising successfully started\n");
    
    	err = uart_tx(uart, tx_buf, sizeof(tx_buf), SYS_FOREVER_MS);
    	if (err) {
    		return -1;
    	}
    
    	err = uart_rx_enable(uart ,rx_buf,sizeof rx_buf,RECEIVE_TIMEOUT);
    	if (err) {			
    		return -1;
    	}
    	dk_set_led(DK_LED3, 1);
    
    	while(1){
    		k_sem_take(&sem, K_FOREVER);
    
    		if((rx_buf[0] == 0xF4) && (rx_buf[1] == 0xF5))
    		{			
    			if(rx_buf[2] == 0x03)
    			{				
    				if(rx_buf[7] == 0x16)
    				{					
    					adv_mfg_data.home_points += 1; 
    					dk_set_led(DK_LED1, 1);
    					dk_set_led(DK_LED2, 0);
    				}
    				else if(rx_buf[7] == 0x17)
    				{
    					adv_mfg_data.guest_points += 1; 
    					dk_set_led(DK_LED1, 0);
    					dk_set_led(DK_LED2, 1);					
    				}			
    			}
    			else if(rx_buf[2] == 0x02)
    			{
    				
    			}	
    
    			bt_le_adv_update_data(ad, ARRAY_SIZE(ad), sd, ARRAY_SIZE(sd));
    			memset(rx_buf, 0, sizeof(rx_buf));				
    		} 		
    		
    		//k_sleep(K_MSEC(RUN_LED_BLINK_INTERVAL));
    	}
    }
    
    K_THREAD_DEFINE(thread0id, SB_STACKSIZE, thread0, NULL, NULL, NULL,
    				SB_PRIORITY, 0, 0);

    My final objective is to connect DFRobot Voice Recognition Module using UART interface to nRF7002 DK. Then send the received commands as part of Bluetooth advertisement packet.

    I already made this to work using nRF52840 DK. I need this to work for nRF7002 DK which will function as Bluetooth Broadcaster, the problem is the IO voltage is 1.8V. I tried to use a bi-directional logic level shifter board but there was no output.

    Actually, it worked using nRF7002 DK when I did not use the logic level shifter board and then power the nRF7002 DK externally 3.3V. But, I might damage the nRF7002 DK this way.

    Regards,

    Markel

  • Hi,

    I decided to not use nRF7002 DK. I used nRF52840 DK instead.

    Regards,

    Markel

Reply Children
No Data
Related