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;
}
MX_USB_PCD_Init();
MX_TIM4_Init();
/* USER CODE BEGIN 2 */
- display_init();
+ //display_init();
usb_start(&usb);
bmp_init();
LL_TIM_EnableIT_UPDATE(TIM4);
LL_TIM_GenerateEvent_UPDATE(TIM4);
+#if 0
{
byte buf[5] = { 0xff, 0xff, 10, 0xff, 0xff };
display_buffer(buf);
}
+#endif
/* USER CODE END 2 */
{
if (rx_packet_state == 1 && !tx_packet_state)
{
- display_buffer(rx_packet);
+ static byte led_state;
+ if (led_state)
+ LL_GPIO_SetOutputPin(LED_GPIO_Port, LED_Pin);
+ else
+ LL_GPIO_ResetOutputPin(LED_GPIO_Port, LED_Pin);
+ led_state ^= 1;
+
+ // display_buffer(rx_packet);
tx_packet_state = 1;
tx_packet[0] = adjusted_temp >> 8;
tx_packet[1] = adjusted_temp & 0xff;
// debug_printf("Counter = %d\n", cnt);
// display_counter(cnt);
- static byte led_state;
- if (led_state)
- LL_GPIO_SetOutputPin(LED_GPIO_Port, LED_Pin);
- else
- LL_GPIO_ResetOutputPin(LED_GPIO_Port, LED_Pin);
- led_state ^= 1;
-
__WFI();
/* USER CODE END WHILE */