I have been dealing with this for 6 months and im running low on time to finish this project please help me. I want to send 20 bytes of data to a application that i made for my phone with ble. I get the data from sensor's with twi if i did this project in two parts .First i made a project for twi and it worked everything was fine but when i use the same TWI code for ble data sending the TWI part does not work it does not read data at timeout_handler part .My main issue today is that i can send 20 bytes of data correctly and cant update it .I can see everything ( service ,character..) but i cant update the data inside the character. Like it sends random data every time at the begining and does not update by my sensor.
--------------------my data descriptions----------------------------------------
static uint8_t m_custom_value = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17};
static uint16_t fall;
--------------------- this is my timeout handler ---------------------------------
static void notification_timeout_handler(void * p_context)
{
UNUSED_PARAMETER(p_context);
ret_code_t err_code;
bsp_board_led_on(3);
nrf_delay_ms(100);
bsp_board_led_off(3);
MPU6050_FallDet(fall);
m_custom_value = fall;
err_code = ble_cus_custom_value_update(&m_cus, m_custom_value);
APP_ERROR_CHECK(err_code);
}
--------------------- this is value_update function---------------------------------
uint32_t ble_cus_custom_value_update(ble_cus_t * p_cus, uint8_t custom_value)
{
NRF_LOG_INFO("In ble_cus_custom_value_update. \r\n");
if (p_cus == NULL)
{
return NRF_ERROR_NULL;
}
uint32_t err_code = NRF_SUCCESS;
ble_gatts_value_t gatts_value;
// Initialize value struct.
memset(&gatts_value, 0, sizeof(gatts_value));
gatts_value.len = sizeof(custom_value);
gatts_value.offset = 0;
gatts_value.p_value = &custom_value;
// Update database.
err_code = sd_ble_gatts_value_set(p_cus->conn_handle,
p_cus->custom_value_handles.value_handle,
&gatts_value);
if (err_code != NRF_SUCCESS)
{
return err_code;
}
// Send value if connected and notifying.
if ((p_cus->conn_handle != BLE_CONN_HANDLE_INVALID))
{
ble_gatts_hvx_params_t hvx_params;
memset(&hvx_params, 0, sizeof(hvx_params));
hvx_params.handle = p_cus->custom_value_handles.value_handle;
hvx_params.type = BLE_GATT_HVX_NOTIFICATION;
hvx_params.offset = gatts_value.offset;
hvx_params.p_len = &gatts_value.len;
hvx_params.p_data = gatts_value.p_value;
err_code = sd_ble_gatts_hvx(p_cus->conn_handle, &hvx_params);
NRF_LOG_INFO("sd_ble_gatts_hvx result: %x. \r\n", err_code);
}
else
{
err_code = NRF_ERROR_INVALID_STATE;
NRF_LOG_INFO("sd_ble_gatts_hvx result: NRF_ERROR_INVALID_STATE. \r\n");
}
return err_code;
}
-------------------------------------main.c file-------------------------------------
void MPU6050_FallDet(int16_t *Fall){
static int16_t ACCValue[3], GYROValue[3];
static int16_t VAccValue[3], VGyroValue[3];
static int16_t RAccValue[3], RGyroValue[3];
static int16_t cosAccValue[3], cosGyroValue[3];
static int16_t RACC,RACC2;
MPU6050_ReadAcc(&ACCValue[0], &ACCValue[1], &ACCValue[2]);
VAccValue[0]=ACCValue[0]*3.3/1023;
VAccValue[1]=ACCValue[1]*3.3/1023;
VAccValue[2]=ACCValue[2]*3.3/1023;
RAccValue[0]=(VAccValue[0]-1.65)/0.47;
RAccValue[1]=(VAccValue[1]-1.65)/0.47;
RAccValue[2]=(VAccValue[2]-1.65)/0.47;
RACC=RAccValue[0]^2+RAccValue[1]^2+RAccValue[2]^2;
RACC2=RACC^2;
cosAccValue[0]=RAccValue[0]/RACC2;
cosAccValue[1]=RAccValue[1]/RACC2;
cosAccValue[2]=RAccValue[2]/RACC2;
NRF_LOG_INFO("MPU6050 :COS: x = %d y = %d z = %d", cosAccValue[0], cosAccValue[1], cosAccValue[2]);
NRF_LOG_FLUSH();
if( cosAccValue[1] == 1|cosAccValue[1] == -1){
nrf_delay_ms(10);
if( cosAccValue[1] == 1|cosAccValue[1] == -1){
*Fall = 2;
}}
if( cosAccValue[2] == 1|cosAccValue[2] == -1){
nrf_delay_ms(10);
if( cosAccValue[2] == 1|cosAccValue[2] == -1){
nrf_delay_ms(10);
if( cosAccValue[2] == 1|cosAccValue[2] == -1){
*Fall = 1; }}}
return ;
}
---------------------------------------------------------------
maybe i wasnt clear enough but please try to help me i cant think any other think to do i am out of ideas i looked every post at the devzone about ble and i cant solve this.