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

Porting ble_app_uart into twi_master_with_slave

Hi,

I am using the nRF52 with code from SDK 9.2, as well as the S132 softdevice. I basically ported code from the ble_uart_app into the twi_example to send data over bluetooth.

I tried to port the ble_uart functions from the main file, as well as the libraries it used. Once I finished porting the libraries, the code can build just fine, but the UART does not output any printfs. More importantly, the nordic does not begin advertisement.

I included my main function code just in case:

int main(void)
{
	uart_config();
  	twi_init(); 
    printf("\nTWI Sensor Example\r\n");
	//BT
	uint32_t err_code;
    bool erase_bonds;
    uint8_t buffer[BLE_NUS_MAX_DATA_LEN] = {0};
		
    // Initialize.
    APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_MAX_TIMERS, APP_TIMER_OP_QUEUE_SIZE, false);
    buttons_leds_init(&erase_bonds);
    ble_stack_init();
    gap_params_init();
    services_init();
    advertising_init();
    conn_params_init();
	err_code = ble_advertising_start(BLE_ADV_MODE_FAST);
    APP_ERROR_CHECK(err_code);
	//BT end
}
Parents
  • well you should have something to stop main() just exiting. Currently you start advertising and if that's your real code, as soon as that's done, you're off the end of main and depending on what you're building with you could run into a loop, which would work, or a load of shutdown code, which wouldn't.

    If you have an infinite loop elsewhere then either

    1. You're in it already - ie does twi_init() start the infinite loop, in which case you're never going to get to the rest of the code or

    2. Your infinite loop is triggered later by a timer or connection and you've already left main() before you get there.

    just putting while(1) __wfe() at the end of main is a good idea.

    If you have a debugger, use it. If you don't, then you're just going to have to start commenting things out piece by piece until you find out where you are. I never know why people debug with UART, too hard.

Reply
  • well you should have something to stop main() just exiting. Currently you start advertising and if that's your real code, as soon as that's done, you're off the end of main and depending on what you're building with you could run into a loop, which would work, or a load of shutdown code, which wouldn't.

    If you have an infinite loop elsewhere then either

    1. You're in it already - ie does twi_init() start the infinite loop, in which case you're never going to get to the rest of the code or

    2. Your infinite loop is triggered later by a timer or connection and you've already left main() before you get there.

    just putting while(1) __wfe() at the end of main is a good idea.

    If you have a debugger, use it. If you don't, then you're just going to have to start commenting things out piece by piece until you find out where you are. I never know why people debug with UART, too hard.

Children
No Data
Related