Страницы

Ярлыки

ДШИ-200 (1) КСВУ-6 (1) ЛЧМ (1) МДР-23 (1) микроконтроллер (1) перенаправление (1) С (1) структуры (1) учебный курс (1) AC/DC (1) ADC (1) ADS1248 (1) Altium (1) Altuim (1) Amolifer (1) ARM (1) assembler (2) Asynchronous (1) at command (3) at#eaddr (1) at#epassw (1) at#esmtp (1) at#euser (1) at#gprs (1) at#selint=2 (1) at#sgact (1) at#tcpatcmdseq (1) ATX (1) AVR (2) bit (1) boost (1) boot (2) bootlloader (1) C (6) C# (7) C++ (1) CMSIS (1) command (1) CP2101 (1) CSD (1) Danfoss (6) DBGMCU (1) debug (1) debug.ini (1) delegate (1) Discovery (1) DMA (1) DRV8805 (1) DWT (1) e-mail (1) email (1) Exel (1) exFAT (1) FC-051 (1) gl868-dual (2) gl868-dual cmux (1) GPIO (2) GSM (1) I2C (1) IAR (1) ID (1) Invoke (1) Keil (3) LabVIEW (1) Linux (1) LMP7721 (1) LoRa (3) mdmread (1) memory (1) MODBUS (1) Operation Amplifer (1) pack (1) printf (2) printf() (1) RCC (1) retargetting (1) RFM95/96/87/98(W) (1) RS232 (4) RS485 (1) RSAPI.DLL (1) RSS (1) RTC (2) send (2) SerialPort (1) Silabs (1) spl (1) standard peripherals library (1) startup (1) stepper (2) STlink (1) STlink/V2 (2) STM32 (10) stm32 stm32f10x (1) STM32DBG.IN (1) STM32F (19) STM32F103 (4) struct (1) Structure (1) system (1) SystemInit (1) Task (1) telit (5) thread (4) TIM (1) Type Cast (1) UART (1) uni-trend (1) USART (6) USB (1) UT61B (1) viewer (1)

пятница, 1 июля 2016 г.

ADC to UART convertion with STM32F030

Structure for command of control ADC start & setting  is sting with 6 byte

1 -  set/reset  autostart for ADC conversion ( 1 - single start ADC, other - autostart)

2 - HI byte for delay (msec) ADC start (hex mode)
3 - LO byte for delay(msec) ADC  start (hex mode)

4 - HI byte for ADC sample number  (hex mode)
5 - LO byte for ADC sample number  (hex mode)

6 - 0xFF - end byte


Structure for ADC send result of measurement

1 - HI digit of ADC result in ASCII format (0x30...0x39)
1 - MI digit of ADC result in ASCII format (0x30...0x39)
1 - MI digit of ADC result in ASCII format (0x30...0x39)
1 - LO digit of ADC result in ASCII format (0x30...0x39)
5 - 0x0D
6 - 0x0A










Keil code for main.c


/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "stm32f0xx_hal.h"
#include "adc.h"
#include "dma.h"
#include "usart.h"
#include "gpio.h"

/* USER CODE BEGIN Includes */
#define ADC_0V_VALUE                            0
#define ADC_1V_VALUE                            1241
#define ADC_2V_VALUE                            2482
#define ADC_3V_VALUE                            3723
/* USER CODE END Includes */

/* Private variables ---------------------------------------------------------*/

/* USER CODE BEGIN PV */
/* Private variables ---------------------------------------------------------*/
uint8_t uart_tx[7]={0,0,0,0,0,0xD,0xA};
uint32_t adcResultall,adcResult = 0;
uint32_t iii,adc_samlpe=1000,autostart=0,adc_delay=1;
uint32_t i_0, i_1, i_2;
uint8_t TxData[6]={0};
uint8_t RxData[6]={0};

uint8_t aaa[5]={0};
/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
void Error_Handler(void);

/* USER CODE BEGIN PFP */
/* Private function prototypes -----------------------------------------------*/
void adc_string(uint32_t adc)
{
//uint8_t aaa[5]={0};
aaa[0]=adc/10000;
aaa[0]=aaa[0] &0xF;
uart_tx[0]=aaa[0]|0x30;
aaa[1]=(adc-aaa[0]*10000)/1000;
aaa[1]=aaa[1] &0xF;
uart_tx[1]=aaa[1]|0x30;
    aaa[2]=(adc-aaa[0]*10000-aaa[1]*1000)/100;
aaa[2]=aaa[2] &0xF;
 uart_tx[2]=aaa[2]|0x30;
 aaa[3]=(adc-aaa[0]*10000-aaa[1]*1000-aaa[2]*100)/10;
aaa[3]=aaa[3] &0xF;
uart_tx[3]=aaa[3]|0x30;
aaa[4]=(adc-aaa[0]*10000-aaa[1]*1000-aaa[2]*100-aaa[3]*10);
aaa[4]=aaa[4] &0xF;
 uart_tx[4]=aaa[4]|0x30;
uart_tx[5]=0x0D;
uart_tx[6]=0x0A;
}
/* USER CODE END PFP */

/* USER CODE BEGIN 0 */

/* USER CODE END 0 */

int main(void)
{

  /* USER CODE BEGIN 1 */

  /* USER CODE END 1 */

  /* MCU Configuration----------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* Configure the system clock */
  SystemClock_Config();

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_DMA_Init();
  MX_ADC_Init();
  MX_USART1_UART_Init();

  /* USER CODE BEGIN 2 */

  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
HAL_UART_Receive_DMA(&huart1, RxData, 6);  


if(RxData[5]==0xFF)  //
{
    RxData[5]=0x00;
adc_samlpe = 256*RxData[3] + RxData[4];
adc_delay = 256*RxData[1] + RxData[2];
adcResult = 0;
adcResultall = 0;
HAL_Delay(1+adc_delay);
for(i_1=0;i_1 < adc_samlpe+1; i_1++)
{
HAL_ADC_Start(&hadc);
HAL_ADC_PollForConversion(&hadc, 1000);
adcResult = adcResult + HAL_ADC_GetValue(&hadc);
HAL_ADC_Stop(&hadc);
}
adcResultall = adcResult/(adc_samlpe+1);
adc_string(adcResultall);
TxData[0] = uart_tx[1];
TxData[1] = uart_tx[2];
TxData[2] = uart_tx[3];
TxData[3] = uart_tx[4];
TxData[4] = 0x0D;
TxData[5] = 0x0A;
HAL_UART_Transmit_DMA(&huart1, TxData, 6);
for(i_2=0; i_2 <= 5; i_2++)
{
RxData[i_2] = 0;
}
}

  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */

  }
  /* USER CODE END 3 */

}



Комментариев нет:

Отправить комментарий

ваше мнение...