I2C Read Characteristic

Dear Dialog,

I am studying the tutorial "Create a Custom Profile Service" and try to add the  I2C Read Characteristic into the ble_app_peripheral example. The SDK version is SDK_6.0.18.1182.1.

What I want to achieve is: when the 'Read again' button is clicked in the LightBlue app, 8 bytes of sensor data are retrieved.

However, the results I obtained before were all 'No Value'. I succeeded once at the very beginning, but later I couldn't retrieve the sensor data anymore. I can't find where the problem is. But I

can confirm that my I2C configuration is correct because when I copied the I2C-related code to the ble_app_barebone example, it could broadcast the sensor data normally.

Below is my current code.

I hope you can help check where the issue might be. Thank you very much!

  • Hi Nick,

    Thank you for posting your question online.
    I have requested access via mia personal e-mail on your google drive. 
    Which is the sensor you have connected? Since you do not think that this is an issue of I2C, could we test it with dummy data?

    What I want to achieve is: when the 'Read again' button is clicked in the LightBlue app, 8 bytes of sensor data are retrieved.

    Similar implementation there is on the ble_app_peripheral example on the last characteristic of the last service. Each time we read the characteristic we increment the value by 1. 
    You will need the RI permission on this characteristic in order to do this.

    Best Regards,
    OV_Renesas

  • Hi OV,

    Thank you for your reply. I use the AS73211 sensor. Yes. I  should test it with dummy data.

    For now, could you please help check the codes I provided, cause I am not sure whether the modification on the example is correct.

    Thanks a lot!

  • Hi Nick,

    Thank you for the reply.
    I have not been granted access in order to download your project.
    Please grant access or upload a zip file with the project you are using.

    Best Regards,
    OV_Renesas

  • Hi OV,

    Sorry for that. I have uploaded again. Please download it from here:  www.dropbox.com/.../ble_app_peripheral_APPControl_V1.zip

    Looking forward to your reply. Thanks a lot!

  • Hi Nick,

    Thank you for the reply.
    Indeed the issue was the RI permission on the I2C Characteristic you had created.
    I modified the SVC1_IDX_I2C_VAL_1_VAL permissions on the user_custs1_def.c file:

        // I2C Value 1 Characteristic Value
        [SVC1_IDX_I2C_VAL_1_VAL]           = {SVC1_I2C_VAL_1_UUID_128, ATT_UUID_128_LEN, PERM(RD, ENABLE),  PERM(RI, ENABLE)|
                                                DEF_SVC1_I2C_VAL_1_CHAR_LEN, 0, NULL},
    And I modified the user_svc3_read_non_db_val_handler handler on the user_custs1_impl.c file in order to send dummy data as shown below:
    uint8_t x_val2=0;
    uint8_t y_val2=0;
    uint8_t z_val2=0;
    uint8_t t_val2=0;
    void user_svc3_read_non_db_val_handler(ke_msg_id_t const msgid,
    																							struct custs1_value_req_ind const *param,
    																							ke_task_id_t const dest_id,
    																							ke_task_id_t const src_id)
    {
    							//start measurement
    						//		AS73211_meas();
    
    							// pre-assign response message to results
    								struct custs1_value_req_rsp *rsp = KE_MSG_ALLOC_DYN(CUSTS1_VALUE_REQ_RSP,
                                                        prf_get_task_from_id(TASK_ID_CUSTS1),
                                                        TASK_APP,
                                                        custs1_value_req_rsp,
                                                        8); // x_val, y_val, z_val, t_val 8 bytes in total
    
    							// set connection index and property index
    								rsp->conidx  = app_env[param->conidx].conidx;
    								rsp->att_idx = param->att_idx;
    							// set the length to 8
    								rsp->length  = 8;
    							// set status as no error
    								rsp->status  = ATT_ERR_NO_ERROR;
    								
    
    							// copy measured date into the response meassage
    								memcpy(&rsp->value[0], &x_val2, 2);
    								memcpy(&rsp->value[2], &y_val2, 2);
    								memcpy(&rsp->value[4], &z_val2, 2);
    								memcpy(&rsp->value[6], &t_val2, 2);
    
    								x_val2++;
    								y_val2++;
    								z_val2++;
    								t_val2++;
    							// send response
    								ke_msg_send(rsp);
    }

    I compiled and loaded the FW into the DA14531.
    Please see video below:


    Best Regards,
    OV_Renesas

  • Hi OV,

    Thank you so much! You are right! I can read the sensor data now.

  • Hi OV,

    Sorry. One more question. 

    Now the program can run normally, but when I compile this program into a HEX file and burn it into the OTP of the DA14531, the LightBlue App cannot find the BLE device. I followed this tutorial to burn the HEX file: 10. Boot from OTP (renesas.com)

    I have followed this tutorial before, and after burning, it could run normally, but this time it doesn't work. Could you help me find the problem? Thank you very much!

  • Hi Nick,

    Please create a new ticket regarding this OTP issue since it is not directly related to the initial issue.
    Please share also the schematics on your custom board as well as more information on the procedure you followed in order to flash the FW into the OTP.

    Best Regards,
    OV_Renesas