“error #28: expression must have a constant value” – with nRF51822 app_twi

ckeilmicrocontrollernrf51822programming

I have been attempting to copy the nRF51822 app_twi example for own application in order to get a better understanding of how the HAL works.

However, now I have an error now that I don't understand since my code is basically identical to the example.

The error:

src\main.c(170): error:  #28: expression must have a constant value

That function where the error occurs:

void LSM303_read(uint8_t *m_buffer)
{
    static app_twi_transfer_t const transfers[] =
    {
        LSM303_ACC_XYZ_READ(&m_buffer[0])    /* <<<<<<<<<<<< ERROR OCCURS HERE */
        // Additional transfer go in here
    };
    static app_twi_transaction_t const transaction =
    {
    .callback            = twi_read_callback,
    .p_user_data         = NULL,
    .p_transfers         = transfers,
    .number_of_transfers = sizeof(transfers) / sizeof(transfers[0])
    };
}

That function causing the error, which resides in my LSM303.h header file:

extern uint8_t const lsm303_acc_first_reg;

#define LSM303_ACC_READ(p_reg_addr, p_buffer, byte_cnt) \
            APP_TWI_WRITE(LSM303_ADDRESS_ACCEL, p_reg_addr, 1, APP_TWI_NO_STOP), \
            APP_TWI_READ (LSM303_ADDRESS_ACCEL, p_buffer, byte_cnt, 0)

#define LSM303_ACC_XYZ_READ(p_buffer) \
            LSM303_ACC_READ(&lsm303_acc_first_reg, p_buffer, 6)

Not got a clue what the issue is since this is the exact same function used in the app_twi example.

Can anyone give some advice here? (I'm using Keil uvision 5 with SDK v10.0.0)

Edit:
The m_buffer they used (identical to mine)

// Buffer for data read from sensors.
#define BUFFER_SIZE  11
static uint8_t m_buffer[BUFFER_SIZE];

Best Answer

m_buffer is defined as a global in the main program, therefore there is no need to pass it into the lsm303_read function. Doing this means that the m_buffer pointer is not constant at compile time.

Changing the function definition to take no argument resolves the problem:

void LSM303_read(void)