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

Can I use NUS service without having the UART pins configured/connected?

Hello,

I want to use the NUS service on my BLE communication. I don't have pins connected for UART, do I need to have them? When I try to run the device, my program initializes all the blocks being used (bsp, uart, spi, ble_stack, etc) and when it tries to print after all the initialization it goes to the app_error. Which is weird because before I also have some prints that are passed by.

Hope someone can help me, using nrf51 on a custom board with SD130v2.1.

edit1: I tried to debug the error, and it's saying that the error is the 0x0000000C caused on line 690 (function : uart_event_handle, case : APP_UART_COMMUNICATION_ERROR) which has the following code:

APP_ERROR_HANDLER(p_event->data.error_communication);

Thank you, Jorge

  • Hi this is somewhat confusing, as 0x0C would be NRF_ERROR_DATA_SIZE. How much data are you sending per package? AS far as I know the package may not exceed 23 Byte, having only 20Byte of payload and 3byte for header

  • If you mean sending via BLE, I'm still not sending anything. Because my device don't even advertises. And if it is that data size I have set it to max of 20, but only sending 15 or less if connected.

    I tried to comment all the printfs, but the problem remains the same. If I comment the uart initialization the program goes to that loop on the debug but appears with all the values = 0.

    I have the one central and one peripheral side. The central side seems to be working well, but the peripheral goes to the app_error with the same configurations of pins, which I think it shouldn't happen.

  • Generally This problem comes when you use any printf() or app_uart_put() before calling uart_init() one try to check is there any such statements either in main or in other source files

  • my main :

    int main(void)
    {
    	bool erase_bonds;
    
        // Initialize.
    	APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_OP_QUEUE_SIZE, false);
    	
    	init_all(erase_bonds);
    

    and the init_all function:

    static void init_all(bool bonds)
    {
    	uart_init();
    	//printf("[MAIN : INIT] uart_init() -> ok\r\n");
    	buttons_leds_init(&bonds);
    	//printf("[MAIN : INIT] buttons_led_init() -> ok\r\n");
    	ble_stack_init();
    	//printf("[MAIN : INIT] ble_stack_init() -> ok\r\n");
    	gap_params_init();
    	//printf("[MAIN : INIT] gap_params_init() -> ok\r\n");
    	conn_params_init();
    	//printf("[MAIN : INIT] conn_params_init() -> ok \r\n");
    	services_init();
    	//printf("[MAIN : INIT] services_init() -> ok \r\n");
    	advertising_init();
    	//printf("[MAIN : INIT] advertising_init() - > ok\r\n");
    	spi_init();
    	//printf("[MAIN : INIT] spi_init() -> ok\r\n");
    	nrf_delay_ms(500);
    	//printf("[MAIN : INIT] Every module ok.\r\n");	
    		
    }
    

    so the first initialization is the uart module. And I even comented all the printf from my software, because they were only for debug purposes.

  • Hi,

    You should not use nrf_delay_ms to delay, instead use a timer. Please see the application timer tutorial. nrf_delay uses a sequence of __nop to implement the delay. This means that the processor will be running and using a lot of current, additionally it will conflict with the SoftDevice which needs to be able to freely schedule its activities.

Related