+ else if (bytes == 2)
+ {
+ LL_I2C_ClearFlag_ADDR(I2C1);
+ LL_I2C_AcknowledgeNextData(I2C1, LL_I2C_NACK);
+ while (!LL_I2C_IsActiveFlag_BTF(I2C1))
+ ;
+ LL_I2C_GenerateStopCondition(I2C1);
+ for (uint i=0; i<2; i++)
+ d = (d << 8) | LL_I2C_ReceiveData8(I2C1);
+ }
+ else
+ {
+ LL_I2C_ClearFlag_ADDR(I2C2);
+
+ uint d = 0;
+ for (uint i=0; i<bytes; i++)
+ {
+ if (i < bytes-3 || i == bytes-1)
+ {
+ while (!LL_I2C_IsActiveFlag_RXNE(I2C1))
+ ;
+ }
+ else if (i == bytes-3)
+ {
+ while (!LL_I2C_IsActiveFlag_BTF(I2C1))
+ ;
+ LL_I2C_AcknowledgeNextData(I2C1, LL_I2C_NACK);
+ }
+ else if (i == bytes-2)
+ LL_I2C_GenerateStopCondition(I2C1);
+ d = (d << 8) | LL_I2C_ReceiveData8(I2C1);
+ }
+ }