UART connect external MCU(STM32) transmit and recieved data

Hi 

    I need to send data from nRF7002 to external CPU(STM32) use UART protocol, for HW nRF7002 P0.20 connect STM32 RX and RF7002 P0.22 connect STM32 TX, I try to use exercise to modify send 8 bytes data and recieved from STM32 8 bytes data, there is no any data recieved data from STM32 and nRF7002, isn't I miss some config for this flow?below is my device three overlay and code, please give suggestion for this, Thanks.

&uart0_default {
	group1 {
		psels = <NRF_PSEL(UART_TX, 0, 20)>, <NRF_PSEL(UART_RTS, 0, 19)>;
	};
};

&uart0_sleep {
	group1 {
		psels = <NRF_PSEL(UART_TX, 0, 20)>,
				<NRF_PSEL(UART_RX, 0, 22)>,
				<NRF_PSEL(UART_RTS, 0, 19)>,
				<NRF_PSEL(UART_CTS, 0, 21)>;
	};
};
&uart0 {
	status = "okay";
	current-speed = <115200>;
	pinctrl-0 = <&uart0_default>;
	pinctrl-1 = <&uart0_sleep>;
	pinctrl-names = "default", "sleep";
};

#define RECEIVE_BUFF_SIZE 8
const struct device *uart= DEVICE_DT_GET(DT_NODELABEL(uart0));
static uint8_t tx_buf[] =   {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07};
static uint8_t rx_buf[RECEIVE_BUFF_SIZE] = {0};
int main(void)
{
	int ret;
		if (!device_is_ready(uart)){
		printk("UART device not ready\r\n");
		return 1 ;
	}
	ret = uart_tx(uart, tx_buf, sizeof(tx_buf), SYS_FOREVER_MS);
	if (ret) {
		return 1;
	}
		ret = uart_rx_enable(uart ,rx_buf,sizeof rx_buf,RECEIVE_TIMEOUT);
	if (ret) {
		return 1;
	}
	while (1) {
		k_msleep(SLEEP_TIME_MS);
	}
}

Best Regards

    Tina

          

  • hi Naeem Maroof

                    For tx_buf[ ] only can use string like below.

    static uint8_t tx_buf[] =   {"0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07"};

    it can't use like below, if use as below, it can't send.

    static uint8_t tx_buf[] = {0x41, 0x42, 0x43};

    what setting does I missing?

    Best Regards

         Tina

  • I used the example you have shared in previous response. Example from DevAcademy

    I can use

     

    static uint8_t tx_buf[] = {0x41, 0x42, 0x43};

    and see ABC on the screen as 0x41 = 65 in decimal which is Ascii code of A, and similarly 0x42 and 0x43 are for B and C respectively.

  • Hi Naeem Maroof

                                Thanks for your reply, it not work on my side with hex byte array as below picture.I have another problem for uart.I need two uart, one for connect external MCU(stm32), other is for internal debug log uart0 (tx pin:1.01, rx pin:1.00), but when I create connect external uart2 on overlay file is below , the internal debug uart log LOG_INF(" ")

    is not work, how can I do for two uart work for same time?Isn't need to cange COM port setting?where can I assign for COM port setting?

    Hex Byte Array

    static uint8_t tx_buf[] =   {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};
    static uint8_t rx_buf[RECEIVE_BUFF_SIZE] = {0};
    
    if (!device_is_ready(uart)){
    	printk("UART device not ready\r\n");
    	return 1 ;
    	}
    	ret = uart_tx(uart, tx_buf, sizeof(tx_buf), SYS_FOREVER_MS);
    if (ret) 
    {
    	return 1;
    }
    ret = uart_rx_enable(uart ,rx_buf,sizeof rx_buf,RECEIVE_TIMEOUT);
    if (ret) 
    {
    	return 1;	
    }

    Not work as below

    String send

    static uint8_t tx_buf[] =   {"0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07"};
    static uint8_t rx_buf[RECEIVE_BUFF_SIZE] = {0};
    
    	if (!device_is_ready(uart)){
    		printk("UART device not ready\r\n");
    		return 1 ;
    	}
    	ret = uart_tx(uart, tx_buf, sizeof(tx_buf), SYS_FOREVER_MS);
    	if (ret) 
    	{
    		return 1;
    	}
    	ret = uart_rx_enable(uart ,rx_buf,sizeof rx_buf,RECEIVE_TIMEOUT);
    	if (ret) 
    	{
    		return 1;	
    	}

    work as below

    Overlay add UART2 as below

    &uart2 {
    	status = "okay";
    	current-speed = <115200>;
    	pinctrl-0 = <&uart2_default>;
    	pinctrl-1 = <&uart2_sleep>;
    	pinctrl-names = "default", "sleep";
    
    };
    &pinctrl {
    	uart2_default:uart2_default {
    		group1 {
    			psels = <NRF_PSEL(UART_TX, 0, 20)>, <NRF_PSEL(UART_RTS, 0, 19)>;
    		};
    		group2 {
            	psels = <NRF_PSEL(UART_RX, 0, 22)>, <NRF_PSEL(UART_CTS, 0, 21)>;
        	};
    	};
    
    	uart2_sleep:uart2_sleep {
    		group1 {
    			psels = <NRF_PSEL(UART_TX, 0, 20)>,
    					<NRF_PSEL(UART_RX, 0, 22)>,
    					<NRF_PSEL(UART_RTS, 0, 19)>,
    					<NRF_PSEL(UART_CTS, 0, 21)>;
    		};
    	};
    };

    when I change the terminal send hex byte array as below

    Best Regards

        Tina

  • Hi

    In your original post, you were using the same pins for uart0.

    Please make sure that you are using correct pins for uart0 and uar2 (if you are using it) from the compiled DTS.

    I have used the PUTTY app for serial terminal.

    You can also use the built-in NRF Serial Terminal from the VS Code.

    Can you try sending 0x41, 0x42 hex for example to check A and B characters on the console, as the 0x00 and 0x01 are the NULL and SOH characters that would not be displayed.

  • Hi Naeem Maroof

                               I try to send 0x41, but it convert to ASCII code, it can't work for our goal, we need to send some hex byte array it's not match in ASCII table, like 0xFE, 0xFD, 0xFC, 0xFB, 0xFA , we need to get this byte and need decide which job need to do, so I need for tx send as real hex byte array.

     For uart0 we use (tx:p1.1, rx:p1.00), uart2 (tx:p0.20,rx:p0.22), overlay as below, for uart2 connect to external MCU(STM32), uart0 is for debug log print.but when I connect external MCU, uart0 print log is not work.what I need to do for two uart work same time?now I'm not change for uart0 baud rate, at the final I need to change the uart0 baud rate as 921600.

    I also use SPI for other application, but SPI tx and rx can send hex byte array, it's not change to any type.why uart can't?

    &uart0_default {
    	group1 {
    		psels = <NRF_PSEL(UART_TX, 1, 1)>, <NRF_PSEL(UART_RTS, 1, 5)>;
    	};
    	group2 {
            psels = <NRF_PSEL(UART_RX, 1, 00)>, <NRF_PSEL(UART_CTS, 1, 4)>;
        };
    };
    
    &uart0_sleep {
    	group1 {
    		psels = <NRF_PSEL(UART_TX, 1, 1)>,
    				<NRF_PSEL(UART_RX, 1, 00)>,
    				<NRF_PSEL(UART_RTS, 1, 05)>,
    				<NRF_PSEL(UART_CTS, 1, 04)>;
    	};
    };
    &uart0 {
    	status = "okay";
    	current-speed = <115200>;
    	pinctrl-0 = <&uart0_default>;
    	pinctrl-1 = <&uart0_sleep>;
    	pinctrl-names = "default", "sleep";
    };
    
    &uart2_default {
    	group1 {
    		psels = <NRF_PSEL(UART_TX, 0, 20)>, <NRF_PSEL(UART_RTS, 0, 19)>;
    	};
    	group2 {
            psels = <NRF_PSEL(UART_RX, 0, 22)>, <NRF_PSEL(UART_CTS, 0, 21)>;
        };
    };
    
    &uart2_sleep {
    	group1 {
    		psels = <NRF_PSEL(UART_TX, 0, 20)>,
    				<NRF_PSEL(UART_RX, 0, 22)>,
    				<NRF_PSEL(UART_RTS, 0, 19)>,
    				<NRF_PSEL(UART_CTS, 0, 21)>;
    	};
    };
    &uart2 {
    	status = "okay";
    	current-speed = <921600>;
    	pinctrl-0 = <&uart2_default>;
    	pinctrl-1 = <&uart2_sleep>;
    	pinctrl-names = "default", "sleep";
    };

    Best Regards

       Tina 

Related