简体   繁体   中英

error: argument of type "int" is incompatible with parameter of type "uint8_t *"

I'm trying to write a I2C application with HAL on STM32F401RE. When I write data, I get this error. Here is my code.

HAL_StatusTypeDef HAL_I2C_Mem_Write(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t *pData, uint16_t Size, uint32_t Timeout)

HAL_I2C_Mem_Write(hi2c, MPU9250_ADDRESS, PWR_MGMT_1, 0x01, 1, 100);

Where 0x01 is must be (uint8_t *) form. How can I convert or cast it?

You are passing 0x01 (a value of type int ) to a function expecting a uint8_t* . (the * means that it is expecting a pointer not a value.) Which isn't possible as you can't point a pointer to a variable that doesn't exist.

You need to add a variable with that value and pass it as:

uint8_t data = 0x01;
HAL_I2C_Mem_Write(hi2c, MPU9250_ADDRESS, PWR_MGMT_1, &data, 1, 100);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM