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

error: #28: expression must have a constant value nordic

I have been attempting to copy the 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 section of code:

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, 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)

Parents
  • static variables must have compile-time constant expressions. even though it's inside the function the variable is static and so if you want to initialise it, you have to do it with something constant.

    You can initialise it with one empty array element and then update array index 0's contents later but you can't statically init it with anything but a compile-time constant.

Reply
  • static variables must have compile-time constant expressions. even though it's inside the function the variable is static and so if you want to initialise it, you have to do it with something constant.

    You can initialise it with one empty array element and then update array index 0's contents later but you can't statically init it with anything but a compile-time constant.

Children
Related