]> mj.ucw.cz Git - home-hw.git/commitdiff
SSR: A simple test
authorMartin Mares <mj@ucw.cz>
Tue, 7 Aug 2018 20:35:09 +0000 (22:35 +0200)
committerMartin Mares <mj@ucw.cz>
Tue, 7 Aug 2018 20:35:09 +0000 (22:35 +0200)
ssr/Src/main.c

index 19fe3c7a350087bd1acfff5013d15b7166cbba83..3a3f0341944cb5ab0e841951b74bae71c0ea5633 100644 (file)
@@ -133,15 +133,40 @@ int main(void)
   /* USER CODE BEGIN WHILE */
   while (1)
   {
   /* USER CODE BEGIN WHILE */
   while (1)
   {
-    if (rx_packet_state == 1 && !tx_packet_state)
+    static byte led_state;
+    if (led_state)
+      {
+       LL_GPIO_SetOutputPin(LED_GPIO_Port, LED_Pin);
+       LL_GPIO_SetOutputPin(SSR1_GPIO_Port, SSR1_Pin);
+       LL_GPIO_SetOutputPin(SSR2_GPIO_Port, SSR2_Pin);
+       LL_GPIO_SetOutputPin(SSR3_GPIO_Port, SSR3_Pin);
+       LL_GPIO_SetOutputPin(SSR4_GPIO_Port, SSR4_Pin);
+      }
+    else
       {
       {
-       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;
+       LL_GPIO_ResetOutputPin(LED_GPIO_Port, LED_Pin);
+       static byte xxx;
+       switch (xxx)
+         {
+         case 0:
+           LL_GPIO_ResetOutputPin(SSR1_GPIO_Port, SSR1_Pin);
+           break;
+         case 1:
+           LL_GPIO_ResetOutputPin(SSR2_GPIO_Port, SSR2_Pin);
+           break;
+         case 2:
+           LL_GPIO_ResetOutputPin(SSR3_GPIO_Port, SSR3_Pin);
+           break;
+         case 3:
+           LL_GPIO_ResetOutputPin(SSR4_GPIO_Port, SSR4_Pin);
+           break;
+         }
+       xxx = (xxx+1) % 4;
+      }
+    led_state ^= 1;
 
 
+    if (rx_packet_state == 1 && !tx_packet_state)
+      {
        tx_packet_state = 1;
        put_u32_be(tx_packet, 42);
        usb_ep_send(&usb, 0x82, tx_packet, 12);
        tx_packet_state = 1;
        put_u32_be(tx_packet, 42);
        usb_ep_send(&usb, 0x82, tx_packet, 12);
@@ -151,7 +176,8 @@ int main(void)
 
     // debug_printf("Counter = %d\n", cnt);
 
 
     // debug_printf("Counter = %d\n", cnt);
 
-    __WFI();
+    //__WFI();
+    LL_mDelay(1000);
 
   /* USER CODE END WHILE */
 
 
   /* USER CODE END WHILE */
 
@@ -330,11 +356,11 @@ static void MX_GPIO_Init(void)
   LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOB);
   LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOA);
 
   LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOB);
   LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOA);
 
-  /**/
-  LL_GPIO_ResetOutputPin(LED_GPIO_Port, LED_Pin);
+  /* LED output is OC, active low, defaults to high */
+  LL_GPIO_SetOutputPin(LED_GPIO_Port, LED_Pin);
 
 
-  /**/
-  LL_GPIO_ResetOutputPin(GPIOB, SSR3_Pin|SSR4_Pin|SSR1_Pin|SSR2_Pin);
+  /* SSR outputs are OC, active low, default to high */
+  LL_GPIO_SetOutputPin(GPIOB, SSR3_Pin|SSR4_Pin|SSR1_Pin|SSR2_Pin);
 
   /**/
   GPIO_InitStruct.Pin = LED_Pin;
 
   /**/
   GPIO_InitStruct.Pin = LED_Pin;