diff --git a/arch/arm/src/s32k1xx/s32k1xx_lpi2c.c b/arch/arm/src/s32k1xx/s32k1xx_lpi2c.c index 367d4644a6..fbe22edddb 100644 --- a/arch/arm/src/s32k1xx/s32k1xx_lpi2c.c +++ b/arch/arm/src/s32k1xx/s32k1xx_lpi2c.c @@ -454,8 +454,9 @@ s32k1xx_lpi2c_modifyreg(struct s32k1xx_lpi2c_priv_s *priv, #ifdef CONFIG_S32K1XX_LPI2C_DYNTIMEO static uint32_t s32k1xx_lpi2c_toticks(int msgc, struct i2c_msg_s *msgs) { - size_t bytecount = 0; int i; + size_t bytecount = 0; + uint32_t tick = 0; /* Count the number of bytes left to process */ @@ -465,10 +466,16 @@ static uint32_t s32k1xx_lpi2c_toticks(int msgc, struct i2c_msg_s *msgs) } /* Then return a number of microseconds based on a user provided scaling - * factor. + * factor. It must not be 0. */ - return USEC2TICK(CONFIG_S32K1XX_LPI2C_DYNTIMEO_USECPERBYTE * bytecount); + tick = USEC2TICK(CONFIG_S32K1XX_LPI2C_DYNTIMEO_USECPERBYTE * bytecount); + if (tick == 0) + { + tick = 1; + } + + return tick; } #endif