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

Error when using c++ with TWI

I am trying to use gcc to compile a c++ code for nRF52. I am using the TWI library and am getting the error below. Can anyone help me rewriting this macro so that it compiles normally ?

Compiling file: main.cpp
In file included from main.cpp:6:0:
../nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/twi_master/nrf_drv_twi.h:91:1: error: invalid conversion from 'void*' to 'NRF_TWIM_Type*' [-fpermissive]
 }
 ^
main.cpp:28:40: note: in expansion of macro 'NRF_DRV_TWI_INSTANCE'
 static const nrf_drv_twi_t m_twi_GPS = NRF_DRV_TWI_INSTANCE(0);
Parents
  • Hi,

    In this line in the header file:

    .reg          = {NRF_DRV_TWI_PERIPHERAL(id)},       \
    

    we assign things to a union, but without specifying which particular element in the union. Some compilers might not like that. Can you please try to change

    #define NRF_DRV_TWI_INSTANCE(id)                        \
    {                                                       \
        .reg          = {NRF_DRV_TWI_PERIPHERAL(id)},       \
        .drv_inst_idx = CONCAT_3(TWI, id, _INSTANCE_INDEX), \
        .use_easy_dma = CONCAT_3(TWI, id, _USE_EASY_DMA)    \
    }
    

    to

    #define NRF_DRV_TWI_INSTANCE(id)                        \
    {                                                       \
        .reg          = {.p_twi = NRF_DRV_TWI_PERIPHERAL(id)},         \
        .drv_inst_idx = CONCAT_3(TWI, id, _INSTANCE_INDEX), \
        .use_easy_dma = CONCAT_3(TWI, id, _USE_EASY_DMA)    \
    }
    

    in nrf_drw_twi.h?

Reply
  • Hi,

    In this line in the header file:

    .reg          = {NRF_DRV_TWI_PERIPHERAL(id)},       \
    

    we assign things to a union, but without specifying which particular element in the union. Some compilers might not like that. Can you please try to change

    #define NRF_DRV_TWI_INSTANCE(id)                        \
    {                                                       \
        .reg          = {NRF_DRV_TWI_PERIPHERAL(id)},       \
        .drv_inst_idx = CONCAT_3(TWI, id, _INSTANCE_INDEX), \
        .use_easy_dma = CONCAT_3(TWI, id, _USE_EASY_DMA)    \
    }
    

    to

    #define NRF_DRV_TWI_INSTANCE(id)                        \
    {                                                       \
        .reg          = {.p_twi = NRF_DRV_TWI_PERIPHERAL(id)},         \
        .drv_inst_idx = CONCAT_3(TWI, id, _INSTANCE_INDEX), \
        .use_easy_dma = CONCAT_3(TWI, id, _USE_EASY_DMA)    \
    }
    

    in nrf_drw_twi.h?

Children
Related