V2.31
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : main.c
|
||||
* Author : WCH
|
||||
* Version : V1.0.0
|
||||
* Date : 2021/06/06
|
||||
* Version : V1.0.2
|
||||
* Date : 2025/10/27
|
||||
* Description : Main program body.
|
||||
*********************************************************************************
|
||||
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
|
||||
@@ -11,18 +11,25 @@
|
||||
*******************************************************************************/
|
||||
|
||||
/*
|
||||
*@Note
|
||||
*ADC uses DMA sampling routine:
|
||||
*ADC channel 1 (PA1), the rule group channel obtains ADC conversion data
|
||||
*for 1024 consecutive times through DMA.
|
||||
*
|
||||
* APP routine: this routine support USB and UART mode,
|
||||
* and you can choose the command method to jump to the IAP .
|
||||
* Key parameters: CalAddr - address in flash(same in IAP), note that this address needs to be unused.
|
||||
* CheckNum - The value of 'CalAddr' that needs to be modified.
|
||||
* Tips :the routine need IAP software version 1.50.
|
||||
*/
|
||||
|
||||
#include "debug.h"
|
||||
#include "ch32v20x_usbfs_device.h"
|
||||
#include "iap.h"
|
||||
#include "usb_istr.h"
|
||||
#include "usb_desc.h"
|
||||
#include "usb_lib.h"
|
||||
#include "hw_config.h"
|
||||
#include "usb_pwr.h"
|
||||
|
||||
/* Global Variable */
|
||||
u16 TxBuf[1024];
|
||||
s16 Calibrattion_Val = 0;
|
||||
vs16 Calibrattion_Val = 0;
|
||||
|
||||
/*********************************************************************
|
||||
* @fn ADC_Function_Init
|
||||
@@ -157,6 +164,43 @@ u16 Get_ConversionVal(s16 val)
|
||||
return (val + Calibrattion_Val);
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn APP_2_IAP
|
||||
*
|
||||
* @brief APP_2_IAP program.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void APP_2_IAP(void)
|
||||
{
|
||||
NVIC_SystemReset();
|
||||
while(1){
|
||||
}
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn USART3_IT_CFG
|
||||
*
|
||||
* @brief USART3 IT config program.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void USART3_IT_CFG(void)
|
||||
{
|
||||
NVIC_InitTypeDef NVIC_InitStructure = {0};
|
||||
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
|
||||
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
|
||||
|
||||
NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
|
||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||||
NVIC_Init(&NVIC_InitStructure);
|
||||
|
||||
USART_Cmd(USART3, ENABLE);
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn main
|
||||
*
|
||||
@@ -186,17 +230,47 @@ int main(void)
|
||||
Delay_Ms(50);
|
||||
ADC_SoftwareStartConvCmd(ADC1, DISABLE);
|
||||
|
||||
for(i = 0; i < 1024; i++){
|
||||
for(i = 0; i < 64; i++){
|
||||
printf("%04d\r\n", Get_ConversionVal(TxBuf[i]));
|
||||
Delay_Ms(10);
|
||||
}
|
||||
|
||||
while(1);
|
||||
//USB-USART ENABLE
|
||||
Set_USBConfig();
|
||||
USB_Init();
|
||||
USB_Port_Set(DISABLE, DISABLE);
|
||||
Delay_Ms(700);
|
||||
USB_Port_Set(ENABLE, ENABLE);
|
||||
USB_Interrupts_Config();
|
||||
|
||||
USBFS_Init();
|
||||
USART3_CFG(460800);
|
||||
USART3_IT_CFG();
|
||||
|
||||
while(1)
|
||||
{
|
||||
EP2_RecData_Deal();
|
||||
if(*(vu32 *)CalAddr == CheckNum)
|
||||
{
|
||||
Delay_Ms(10);
|
||||
APP_2_IAP();
|
||||
while(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void USART3_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
|
||||
/*********************************************************************
|
||||
* @fn USART3_IRQHandler
|
||||
*
|
||||
* @brief This function handles USART3 global interrupt request.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void USART3_IRQHandler(void)
|
||||
{
|
||||
if( USART_GetFlagStatus(USART3, USART_FLAG_RXNE) != RESET){
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
UART_Rx_Deal();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user