]> mj.ucw.cz Git - home-hw.git/commitdiff
More I2C debugging
authorMartin Mares <mj@ucw.cz>
Fri, 29 Jun 2018 21:22:11 +0000 (23:22 +0200)
committerMartin Mares <mj@ucw.cz>
Fri, 29 Jun 2018 21:22:11 +0000 (23:22 +0200)
Inc/usb.h
Inc/util.h
Src/bmp085.c
Src/main.c

index 6d5eaf417ba6d195e67a399026bf53d1384200d9..2aea056771dd35497642f44e313e4379364599c4 100644 (file)
--- a/Inc/usb.h
+++ b/Inc/usb.h
@@ -2,7 +2,7 @@
 
 #define USB_SELF_POWERED
 #define USB_NUM_CONFIGURATIONS 1
-#define USB_DEBUG
+#undef USB_DEBUG
 
 /*** USB state structure ***/
 
index 6772a50adeec9b177b3e9d1cdff0c9ffb5015379..827cc9c4a09082cf23336f38c7de54c5b3de9ace 100644 (file)
@@ -24,7 +24,7 @@ static inline void put_u16_le(byte *p, u16 x)
 
 // debug.c
 
-#undef DEBUG_SEMIHOSTING
+#define DEBUG_SEMIHOSTING
 
 void debug_printf(const char *fmt, ...);
 void debug_puts(const char *s);
index 76f548f16230d46bc5e1a05990a86e8399fdae5e..76c64811c940059b964fc2fe257e735eda795a5c 100644 (file)
@@ -23,7 +23,7 @@ static uint bmp_read(uint reg, uint bytes)
   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))
     ;
@@ -41,6 +41,7 @@ static uint bmp_read(uint reg, uint bytes)
     }
   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))
@@ -51,24 +52,31 @@ static uint bmp_read(uint reg, uint bytes)
     }
   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);
        }
     }
@@ -178,17 +186,20 @@ void bmp_step(void)
     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;
     }
index e2769f28a80d9b21d157df368d6bc03692020fb1..7b5b75d0e3921e514183d9feb8bd79c6cdc78492 100644 (file)
@@ -123,7 +123,7 @@ int main(void)
   MX_USB_PCD_Init();
   MX_TIM4_Init();
   /* USER CODE BEGIN 2 */
-  display_init();
+  //display_init();
   usb_start(&usb);
   bmp_init();
 
@@ -131,10 +131,12 @@ int main(void)
   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 */
 
@@ -144,7 +146,14 @@ int main(void)
   {
     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;
@@ -160,13 +169,6 @@ int main(void)
     // 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 */