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

Segger shows error passing pointer to multiple byte array for i2c driver send/receive multiple bytes

Hi,

I have been having trouble getting any read/writes going with my Infineon TLV493D magnetic sensor over i2c. I suspect it may be a cast or syntax thing that I can't get to the bottom of. 

As I understand it, when calling nrf_drv_twi_rx the size of the buffer array is the number of bytes the master tries to read from the slave. However, I always get a warning from the compiler: expected 'uint8_t * {aka unsigned char *}' but argument is of type 'uint8_t (*)[7] {aka unsigned char (*)[7]}' when I try to pass an array of size 7 to read 7 bytes. I then use that information to write 4 bytes to send to the sensor, and same warning arises for nrf_drv_twi_tx. Is that the right function to use for reading/writing multiple bytes? I understand nrfx_ is the new driver version and will replace all when I get this solved... just trying to get off the ground at this point. 

Some things I have noticed trying to diagnose this are that if I try to declare a byte to send as a const I will get error 16 (invalid address). The only thing that works is casting as static, but not static const. Even though the function itself in nrf_drv_twi.h appears to ask for a const* this doesn't seem to work when I try to pass that. 

I attached a code snippet because the whole file is long. Also I built this from the twi example file in SDK 15.2

/* TWI instance ID. */
#define TWI_INSTANCE_ID             0
#define MAG_SDA_PIN                 NRF_GPIO_PIN_MAP(0,26)
#define MAG_SCL_PIN                 NRF_GPIO_PIN_MAP(0,27)

/* Indicates if operation on TWI has ended. */
static volatile bool m_xfer_done = false;

/* TWI instance. */
static const nrf_drv_twi_t m_twi = NRF_DRV_TWI_INSTANCE(TWI_INSTANCE_ID);

/* Buffer for samples read from temperature sensor. *///
static    uint8_t    m_sample[7];                     // sensor data buffer to create application
static    uint8_t    sensorbitmap[10];                // initial register read and store
static    uint8_t    MAG_SENSOR_ADDRESS = 0x3f;
static    uint8_t    sendrecovery = 0xFF;             // startup send recovery bits
static    uint8_t    sendreset = 0x00;                // startup send reset bits

....later on we call the following...

    err_code = nrf_drv_twi_rx(&m_twi, MAG_SENSOR_ADDRESS, &sensorbitmap, sizeof(sensorbitmap));                  //  Read and store sensorbitmap for later use
    APP_ERROR_CHECK(err_code);                                                                                                                     //
    NRF_LOG_INFO(err_code); 

.... and use it to send this...

void mag_sensor_set_mode(void)
{
    ret_code_t err_code;

const uint8_t write_registers[4] =                                                                    
    { 0x00,
      0x00 | MAG_SENSOR_IICADDR | INT_DISABLE | FAST_MODE_DISABLE | LOW_POWER_MODE_ENABLE,
      sensorbitmap[8],
      TEMPERATURE_ENABLE | LOW_POWER_PERIOD_12MS | PARITY_TEST_DISABLE | (sensorbitmap[9] & 0x0F)
    };

    SEGGER_RTT_printf(0, "write_registers: %d\n", write_registers);

    err_code = nrf_drv_twi_tx(&m_twi, MAG_SENSOR_ADDRESS, write_registers, sizeof(write_registers), true);
    APP_ERROR_CHECK(err_code);
    NRF_LOG_INFO(err_code);
   
    while (m_xfer_done == false);
}

Any help is greatly appreciated!

Parents Reply Children
Related