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
  • Okay, I took what you said and used a debugger. The code stops working at ble_stack_init(). It does not get to err_code. Also, sorry, here is the full code.

    int main(void)
    {
    	uart_config(); 
    
    	printf("\nTWI Sensor Example\r\n");
    	//BT
    	uint32_t err_code;
    	bool erase_bonds;
    	uint8_t buffer[BLE_NUS_MAX_DATA_LEN] = {0};
    	twi_init(); //not BT
    	printf("TWI");
    	MC3610 MC; //not BT
    	MC.start(); //not BT
    
    	// 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
    
    	#ifdef TEST_MODE //TEST_MODE must be defined in the options for IDE
    	jazz_unit_test_mcube();
    	#endif
    
    	while(1) {
    		mc3610_acc_t rawData = MC.readRawAccel();
    		printf("%*.4f,%*.4f,%*.4f\r\n",6,rawData.XAxis_g,6,rawData.YAxis_g,6,rawData.ZAxis_g); 
    		sprintf((char*)buffer,"%.4f,%.4f,%.4f\r\n", rawData.XAxis_g, rawData.YAxis_g, rawData.ZAxis_g);
    		
    		if(m_conn_handle != BLE_CONN_HANDLE_INVALID)
    		{
    			err_code = ble_nus_string_send(&m_nus, buffer, sizeof(buffer));
    			if (err_code != NRF_ERROR_INVALID_STATE)
    			{
    				APP_ERROR_CHECK(err_code);
    			}
    		}
    
    		power_manage(); //puts it in sleep mode. can be woken with interrupt
    
    		nrf_delay_ms(10);
    
    	}
    }
    
Reply
  • Okay, I took what you said and used a debugger. The code stops working at ble_stack_init(). It does not get to err_code. Also, sorry, here is the full code.

    int main(void)
    {
    	uart_config(); 
    
    	printf("\nTWI Sensor Example\r\n");
    	//BT
    	uint32_t err_code;
    	bool erase_bonds;
    	uint8_t buffer[BLE_NUS_MAX_DATA_LEN] = {0};
    	twi_init(); //not BT
    	printf("TWI");
    	MC3610 MC; //not BT
    	MC.start(); //not BT
    
    	// 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
    
    	#ifdef TEST_MODE //TEST_MODE must be defined in the options for IDE
    	jazz_unit_test_mcube();
    	#endif
    
    	while(1) {
    		mc3610_acc_t rawData = MC.readRawAccel();
    		printf("%*.4f,%*.4f,%*.4f\r\n",6,rawData.XAxis_g,6,rawData.YAxis_g,6,rawData.ZAxis_g); 
    		sprintf((char*)buffer,"%.4f,%.4f,%.4f\r\n", rawData.XAxis_g, rawData.YAxis_g, rawData.ZAxis_g);
    		
    		if(m_conn_handle != BLE_CONN_HANDLE_INVALID)
    		{
    			err_code = ble_nus_string_send(&m_nus, buffer, sizeof(buffer));
    			if (err_code != NRF_ERROR_INVALID_STATE)
    			{
    				APP_ERROR_CHECK(err_code);
    			}
    		}
    
    		power_manage(); //puts it in sleep mode. can be woken with interrupt
    
    		nrf_delay_ms(10);
    
    	}
    }
    
Children
No Data
Related