stm32h7 udp server with adc

Dependencies:   ADE7912

Files at this revision

API Documentation at this revision

Comitter:
yuliyasm
Date:
Wed Oct 28 15:35:16 2020 +0000
Parent:
4:55a7bfd3a297
Commit message:
new

Changed in this revision

ADE7912.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
main.h Show annotated file Show diff for this revision Revisions of this file
--- a/ADE7912.lib	Wed Oct 28 14:04:06 2020 +0000
+++ b/ADE7912.lib	Wed Oct 28 15:35:16 2020 +0000
@@ -1,1 +1,1 @@
-https://os.mbed.com/users/yuliyasm/code/ADE7912/#f480200c8600
+https://os.mbed.com/users/yuliyasm/code/ADE7912/#1d62b3be52e8
--- a/main.cpp	Wed Oct 28 14:04:06 2020 +0000
+++ b/main.cpp	Wed Oct 28 15:35:16 2020 +0000
@@ -6,6 +6,9 @@
 #include "stdlib.h"
 #include "EthernetInterface.h"
 #include "LWIPStack.h"
+#include "dma.h"
+#include "spi.h"
+#include "gpio.h"
 
 EthernetInterface net;
 
@@ -13,6 +16,9 @@
 Thread thread;
 int out_buffer[2];
 
+uint32_t bufFR = 0xAA;
+uint8_t str4byte[3]; 
+
 
 void UDP_thread()
 {
@@ -31,70 +37,63 @@
 //        out_buffer = {rand(), rand()};
 //        sock.recvfrom(&receive, &out_buffer, sizeof(out_buffer));
 //        printf(out_buffer);
-        if (0 > sock.sendto(receive, out_buffer, sizeof(out_buffer))) {
+        if (0 > sock.sendto(receive, str4byte, sizeof(str4byte))) {
             printf("Error sending data\n");
         }
-//        printf(out_buffer[0]+'0');
+        printf("Update %d, %d, %d \n", str4byte[0], str4byte[1], str4byte[2]);
         ThisThread::sleep_for(2000);
     }
 }
 
-SPI_HandleTypeDef hspi1;
+
+void ADC_thread(){
+    struct ADE7912_Inst *ade = New_ADE7912(&hspi1);
+    struct ADE7912_Phase_Settings a_phase;
+    a_phase.CS_pin = PHASE_A_CS_Pin;
+    a_phase.CS_port = PHASE_A_CS_GPIO_Port;
+    ADE7912_PhaseInit(ade, &a_phase, PHASE_A);
+    ADE7912_EnablePhase(ade, PHASE_A);
+    //SCB_DisableDCache();
+    
+    uint32_t tickCount = osKernelSysTick();
+  /* Infinite loop */
+  for(;;)
+  {     
+        ADE7912_UpdateData(ade);
+
+        bufFR  = (int32_t)(ADE7912_GetCurrent(ade, PHASE_A) * 1000);
+        sprintf( (char *)str4byte, "%03d", (short)bufFR  );
+        
+//        TransmitUARTPackage(&huart3, str_cur+1, 12);
+//        TransmitUARTPackage(&huart3, str4byte, 3);
+//        TransmitUARTPackage(&huart3, str_vol+1, 12);
+        
+        bufFR  = (ADE7912_GetVoltage(ade, PHASE_A) * 1000);
+        sprintf( (char *)str4byte, "%03d", (short)bufFR  );
+        
+//        TransmitUARTPackage(&huart3, str4byte, 3);
+//        TransmitUARTPackage(&huart3, str_temp+1, 9);
+        
+        bufFR  = (ADE7912_GetTemp(ade, PHASE_A) * 1);
+        sprintf( (char *)str4byte, "%03d", (short)bufFR  );
+        
+//        TransmitUARTPackage(&huart3, str4byte, 3);
+//        TransmitUARTPackage(&huart3, str_space+1, 2);
+        
+        ThisThread::sleep_for(1000);
+        
+  }
+    }
 
 int main()
 {
+    MX_GPIO_Init();
+    MX_DMA_Init();
+    MX_SPI1_Init();
+    
     thread.start(UDP_thread);
 
-
-    hspi1.Instance = SPI1;
-    hspi1.Init.Mode = SPI_MODE_MASTER;
-    hspi1.Init.Direction = SPI_DIRECTION_2LINES;
-    hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
-    hspi1.Init.CLKPolarity = SPI_POLARITY_HIGH;
-    hspi1.Init.CLKPhase = SPI_PHASE_2EDGE;
-    hspi1.Init.NSS = SPI_NSS_SOFT;
-    hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_256;
-    hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
-    hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
-    hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
-    hspi1.Init.CRCPolynomial = 0x0;
-    hspi1.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;
-    hspi1.Init.NSSPolarity = SPI_NSS_POLARITY_LOW;
-    hspi1.Init.FifoThreshold = SPI_FIFO_THRESHOLD_01DATA;
-    hspi1.Init.TxCRCInitializationPattern = SPI_CRC_INITIALIZATION_ALL_ZERO_PATTERN;
-    hspi1.Init.RxCRCInitializationPattern = SPI_CRC_INITIALIZATION_ALL_ZERO_PATTERN;
-    hspi1.Init.MasterSSIdleness = SPI_MASTER_SS_IDLENESS_00CYCLE;
-    hspi1.Init.MasterInterDataIdleness = SPI_MASTER_INTERDATA_IDLENESS_00CYCLE;
-    hspi1.Init.MasterReceiverAutoSusp = SPI_MASTER_RX_AUTOSUSP_DISABLE;
-    hspi1.Init.MasterKeepIOState = SPI_MASTER_KEEP_IO_STATE_DISABLE;
-    hspi1.Init.IOSwap = SPI_IO_SWAP_DISABLE;
-
-
-    uint32_t buf = 0xAA;
-
-    struct ADE7912_Inst *ade = New_ADE7912(&hspi1);
-    struct ADE7912_Phase_Settings a_phase;
-    a_phase.CS_pin = SPI1_CS_Pin;
-    a_phase.CS_port = SPI1_CS_GPIO_Port;
-    
-    
-    ADE7912_PhaseInit(ade, &a_phase, PHASE_A);
-
-    ADE7912_EnablePhase(ade, PHASE_A);
-
-    uint32_t tickCount = osKernelSysTick();
-    /* Infinite loop */
-    for(;;) {
-        ADE7912_UpdateData(ade);
-        out_buffer[0] = (int32_t)(ADE7912_GetCurrent(ade, PHASE_A) * 1000);
-        out_buffer[1] = (ADE7912_GetVoltage(ade, PHASE_A) * 1000);
-        
-        printf("Update ");
-        printf("%d, ",out_buffer[0]);
-        printf("%d\n",out_buffer[1]);
-
-        ThisThread::sleep_for(1000);
-    }
+    thread.start(ADC_thread);
 
     //while (true) {
 //        led1 = !led1;
--- a/main.h	Wed Oct 28 14:04:06 2020 +0000
+++ b/main.h	Wed Oct 28 15:35:16 2020 +0000
@@ -10,10 +10,10 @@
   * <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
   * All rights reserved.</center></h2>
   *
-  * This software component is licensed by ST under Ultimate Liberty license
-  * SLA0044, the "License"; You may not use this file except in compliance with
-  * the License. You may obtain a copy of the License at:
-  *                             www.st.com/SLA0044
+  * This software component is licensed by ST under BSD 3-Clause license,
+  * the "License"; You may not use this file except in compliance with the
+  * License. You may obtain a copy of the License at:
+  *                        opensource.org/licenses/BSD-3-Clause
   *
   ******************************************************************************
   */
@@ -51,25 +51,33 @@
 /* USER CODE END EM */
 
 /* Exported functions prototypes ---------------------------------------------*/
-void Error_Handler(void);
+//void Error_Handler();
 
 /* USER CODE BEGIN EFP */
-//extern UART_HandleTypeDef huart3;
-//extern SPI_HandleTypeDef hspi1;
+
 /* USER CODE END EFP */
 
 /* Private defines -----------------------------------------------------------*/
-#define G_LED_Pin GPIO_PIN_0
-#define G_LED_GPIO_Port GPIOB
-#define R_LED_Pin GPIO_PIN_14
-#define R_LED_GPIO_Port GPIOB
-#define SPI1_CS_Pin GPIO_PIN_14
-#define SPI1_CS_GPIO_Port GPIOD
-#define DReady_Pin GPIO_PIN_15
-#define DReady_GPIO_Port GPIOD
-#define DReady_EXTI_IRQn EXTI15_10_IRQn
-#define Y_LED_Pin GPIO_PIN_1
-#define Y_LED_GPIO_Port GPIOE
+#define B1_Pin GPIO_PIN_13
+#define B1_GPIO_Port GPIOC
+#define LD1_Pin GPIO_PIN_0
+#define LD1_GPIO_Port GPIOB
+#define LD3_Pin GPIO_PIN_14
+#define LD3_GPIO_Port GPIOB
+#define STLINK_RX_Pin GPIO_PIN_8
+#define STLINK_RX_GPIO_Port GPIOD
+#define STLINK_TX_Pin GPIO_PIN_9
+#define STLINK_TX_GPIO_Port GPIOD
+#define USB_OTG_FS_PWR_EN_Pin GPIO_PIN_10
+#define USB_OTG_FS_PWR_EN_GPIO_Port GPIOD
+#define PHASE_A_CS_Pin GPIO_PIN_14
+#define PHASE_A_CS_GPIO_Port GPIOD
+#define PHASE_B_CS_Pin GPIO_PIN_15
+#define PHASE_B_CS_GPIO_Port GPIOD
+#define USB_OTG_FS_OVCR_Pin GPIO_PIN_7
+#define USB_OTG_FS_OVCR_GPIO_Port GPIOG
+#define LD2_Pin GPIO_PIN_1
+#define LD2_GPIO_Port GPIOE
 /* USER CODE BEGIN Private defines */
 
 /* USER CODE END Private defines */