LL_I2C_GenerateStartCondition(I2C1);
while (!LL_I2C_IsActiveFlag_SB(I2C1))
;
- LL_I2C_AcknowledgeNextData(I2C1, LL_I2C_ACK);
+ LL_I2C_DisableBitPOS(I2C1);
LL_I2C_TransmitData8(I2C1, 0xef);
while (!LL_I2C_IsActiveFlag_ADDR(I2C1))
;
}
else if (bytes == 2)
{
+ LL_I2C_EnableBitPOS(I2C1);
LL_I2C_ClearFlag_ADDR(I2C1);
LL_I2C_AcknowledgeNextData(I2C1, LL_I2C_NACK);
while (!LL_I2C_IsActiveFlag_BTF(I2C1))
}
else
{
+ LL_I2C_AcknowledgeNextData(I2C1, LL_I2C_ACK);
LL_I2C_ClearFlag_ADDR(I2C2);
uint d = 0;
for (uint i=0; i<bytes; i++)
{
- if (i < bytes-3 || i == bytes-1)
+ if (i+3 < bytes || i+1 == bytes)
{
+#if 0
while (!LL_I2C_IsActiveFlag_RXNE(I2C1))
;
+#endif
}
- else if (i == bytes-3)
+ else if (i+3 == bytes)
{
while (!LL_I2C_IsActiveFlag_BTF(I2C1))
;
LL_I2C_AcknowledgeNextData(I2C1, LL_I2C_NACK);
}
- else if (i == bytes-2)
- LL_I2C_GenerateStopCondition(I2C1);
+ else if (i+2 == bytes)
+ {
+ while (!LL_I2C_IsActiveFlag_BTF(I2C1))
+ ;
+ LL_I2C_GenerateStopCondition(I2C1);
+ }
d = (d << 8) | LL_I2C_ReceiveData8(I2C1);
}
}
case BMP_TEMP:
if (!LL_GPIO_IsInputPinSet(BMP_DONE_GPIO_Port, BMP_DONE_Pin))
return;
- debug_puts("BMP: Temperature done\n");
- raw_press = bmp_read(0xf6, 2);
+ debug_puts("BMP: Temperature measured\n");
+ raw_temp = bmp_read(0xf6, 2);
+ debug_printf("BMP: Temperature read: %u\n", raw_temp);
bmp_start_measure(0xf4 | (BMP_OSS<<6));
bmp_state++;
break;
case BMP_PRESSURE:
if (!LL_GPIO_IsInputPinSet(BMP_DONE_GPIO_Port, BMP_DONE_Pin))
return;
- debug_puts("BMP: Pressure done\n");
+ debug_puts("BMP: Pressure measured\n");
raw_press = bmp_read(0xf6, 3);
+ debug_printf("BMP: Pressure read: %u\n", raw_press);
bmp_recalc(raw_temp, raw_press, BMP_OSS, bmp_constants, &adjusted_temp, &adjusted_press);
+ debug_printf("BMP: Adjusted temp %u, press %u\n", adjusted_temp, adjusted_press);
bmp_state = BMP_IDLE;
break;
}