Help with basic implementation of UART

Hello,

I am working on developing a BLE peripheral FW (Reader) with NRF52840 using nRF Connect SDK 2.0.0. The Reader has two MCU, one is BLE MCU and other is the main Control MCU.

I have implemented my custom BLE service in the BLE FW. 

Some data that i received from BLE Client i have to send to Main MCU using UART and also Some data that i receive on UART from Control MCU i have to send to BLE Client probably.

Which is the easiest method to achieve this from a sample ?

I have read the peripheral_uart example, but that seems to be more complex than what i need. It implements every data on UART to BLE Client.

Also, i am not much clear the steps to configure, init and use UART functions.

I am reading through samples and responses from devzone since 2 days, but havent got a good understanding on how to start yet.

Please help.

Parents
  • Hello .. any help ? I need to get this to work asap. 

    I have reference from peripheral_lpuart example and use it in my project as : 

    LOG_MODULE_REGISTER(uart);
    
    const struct device *lpuart = DEVICE_DT_GET(DT_NODELABEL(lpuart));
    
    int uart_init(void)
    {
    	if (!device_is_ready(lpuart)) 
    	{
    		printk("LPUART device not ready\n");
    		return -ENODEV;
    	}
    
    	uart_irq_callback_user_data_set(lpuart, uart_irq_handler, NULL);
    
    	uart_irq_rx_enable(lpuart);
    
    	while (1) 
    	{
    		uart_irq_tx_enable(lpuart);
    		k_sleep(K_MSEC(500));
    
    		uart_poll_out(lpuart, 0xff);
    		k_sleep(K_MSEC(100));
    	}
    }
    
    static void uart_irq_handler(const struct device *dev, void *context)
    {
    	uint8_t buf[] = {1, 2, 3, 4, 5};
    
    	if (uart_irq_tx_ready(dev)) 
    	{
    		(void)uart_fifo_fill(dev, buf, sizeof(buf));
    		uart_irq_tx_disable(dev);
    	}
    
    	if (uart_irq_rx_ready(dev)) 
    	{
    		uint8_t buf[10];
    		int len = uart_fifo_read(dev, buf, sizeof(buf));
    
    		if (len) 
    		{
    			printk("read %d bytes\n", len);
    		}
    	}
    }

    I am not able to understand how do i use it ? Can you explain .. the flow of these UART API and Tx and Rx. What triggers what ?

    I have used interrupt based uart.

    I have my high level Application functions: Datalnit, SendData and ReceiveData in nRF52840 code to be used for UART.

    uart_init i am calling inside DataInit.

    What shall i write inside SendData and ReceiveData from uart code i posted.

    Thanks.

  • Hello again Deep, I hope you've had a nice weekend. 

    When it comes to what to start with you could for instance base your BLE MCU on the central_uart sample. To get an understanding of the sample and UART API I would generally recommend the DevAcademy and the sample documentation, though you can of course ask here as well.

    Have you gotten any further since last week?

    Regards,

    Elfving

Reply
  • Hello again Deep, I hope you've had a nice weekend. 

    When it comes to what to start with you could for instance base your BLE MCU on the central_uart sample. To get an understanding of the sample and UART API I would generally recommend the DevAcademy and the sample documentation, though you can of course ask here as well.

    Have you gotten any further since last week?

    Regards,

    Elfving

Children
No Data
Related