標(biāo)題:
STM32F303vct6,多通道adc,dma源程序
[打印本頁]
作者:
chaohu118
時(shí)間:
2019-1-17 12:42
標(biāo)題:
STM32F303vct6,多通道adc,dma源程序
F303vct6,多通道adc,dma
1.gpio.c文件內(nèi)容需要改,按你們的實(shí)際接線
2.查詢狀態(tài)指令<255/STATUS_?中下劃線為非法字符,會(huì)導(dǎo)致串口命令解析出問題;我現(xiàn)在去掉了下劃線改為:<255/STATUS?
STM32單片機(jī)源程序如下:
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "adc1.h"
#include "adc2.h"
#include "usart1.h"
#include "ws_spi3.h"
#include "spi1.h"
#include "string.h"
#include "gpio.h"
#include "usart2.h"
#include "usart3.h"
#include <math.h>
#include "w5500.h"
#include "W5500_conf.h"
#include "socket.h"
#include "utility.h"
#include <stdio.h>
#include "tcp_demo.h"
#include "instruct.h"
#include "instructADC.h"
#include "dac.h"
int paInputMin[3]={10,10,10};
int paInputMax[3]={550,550,550};
int paOutputRatio[3]={150,150,150};
int paOutputMin[3]={10,1500,100};
int pa1inPutmax;
int pa2inputmax;
int pa3inputmin;
int pa1OutPutmin;
int pa2Outputmin;
int pa3Outputmin;
int dataRatio;
int MaxTempter=90;
int remateLocalold=0;
int Errornumber1,Errornumber2;
u8 pa1ContrlState, pa2ContrlState, pa3ContrlState;
/** @addtogroup STM32F30x_StdPeriph_Examples
* @{
*/
/** @addtogroup Basic_example
* @{
*/
#ifdef __GNUC__
/* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf
set to 'Yes') calls __io_putchar() */
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif /* __GNUC__ */
__IO uint32_t TimingDelay = 0;
u32 i=0;
u8 j;
float m,temp;
int main(void)
{
/*!< At this stage the microcontroller clock setting is already configured,
this is done through SystemInit() function which is called from startup
file (startup_stm32f30x.s) before to branch to application main.
To reconfigure the default setting of SystemInit() function, refer to
system_stm32f30x.c file
*/
//resent STm32
// __set_FAULTMASK(1);
// NVIC_SystemReset();
uart1_init(115200);
uart2_init(115200);
uart3_init(115200);
adc1_init();
adc2_init();
// SPI3_Configuration();
// SPI1_Configuration();
GPIO_Config();
DAC_Config();
DAC1_out(1800);
DAC2_out(1500);
gpio_for_w5500_config(); /*初始化MCU相關(guān)引腳*/
reset_w5500(); /*硬復(fù)位W5500*/
set_w5500_mac(); /*配置MAC地址*/
set_w5500_ip(); /*配置IP地址*/
socket_buf_init(txsize, rxsize); /*初始化8個(gè)Socket的發(fā)送接收緩存大小*/
printf(" 源地網(wǎng)絡(luò)適配版作為TCP 服務(wù)器,建立偵聽,等待PC作為TCP Client建立連接 \r\n");
printf(" W5500監(jiān)聽端口為: %d \r\n",local_port);
printf(" 連接成功后,TCP Client發(fā)送數(shù)據(jù)給W5500,W5500將返回對(duì)應(yīng)數(shù)據(jù) \r\n");
while (1)
{
loopback_tcps(SOCK_TCPS, local_port);/*TCP_Server 數(shù)據(jù)回環(huán)測試程序*/
getADCpara();
//異常保護(hù)
if(ALLerror_open==0)
{
PAERROR();
}
Delay(5);
usart1_cmd();
if(controlState())
{
if(remateLocalold==0)
{
SetPA1RFONOFF(0);
SetPA2RFONOFF(0);
SetPA3RFONOFF(0);
for(i=0;i<3;i++)
{
Tempter_errorState[i]=0;
output_errorState[i]=0;
input_errorState[i]=0;
}
clearchan1();
}
remateLocalold=1;
}
else
{
localCTR1();
remateLocalold=0;
}
Delay(5);
}
// }
}
/**
* @brief Inserts a delay time.
* @param nTime: specifies the delay time length, in milliseconds.
* @retval None
*/
void Delay(__IO uint32_t nTime)
{
TimingDelay = nTime;
while(TimingDelay != 0);
}
void localCTR1(void)
{
u8 i,PA1statan,PA2statan,PA3statan;
///////////////// remate to local///////////////////////////////
if(remateLocalold==1)
{
SetPA1RFONOFF(0);PA1statan=0;
SetPA2RFONOFF(0);PA2statan=0;
SetPA3RFONOFF(0);PA3statan=0;
for(i=0;i<3;i++)
{
Tempter_errorState[i]=0;
output_errorState[i]=0;
input_errorState[i]=0;
}
clearchan1();
}
//////////////////////pA1 local /////////////////////////////////
if(Tempter_errorState[0]==0&&output_errorState[0]==0&&input_errorState[0]==0)
{
if( remotePA1RFONOFF())
{
SetPA1RFONOFF(1);
}
else
{
SetPA1RFONOFF(0);
}
}
else
{
SetPA1RFONOFF(0);
}
if(GetPA1RFONOFF()==0&&remotePA1RFONOFF()==0)
{
Tempter_errorState[0]=0;
output_errorState[0]=0;
input_errorState[0]=0;
clearchan1();
}
//////////////////////pA2 local /////////////////////////////////
if(!Tempter_errorState[1]&&!output_errorState[1]&&!input_errorState[1])
{
if( remotePA2RFONOFF())
{
SetPA2RFONOFF(1);
}
else
{
SetPA2RFONOFF(0);
}
}
else
{
SetPA2RFONOFF(0);
}
if(GetPA2RFONOFF()==0&&remotePA2RFONOFF()==0)
{
Tempter_errorState[1]=0;
output_errorState[1]=0;
input_errorState[1]=0;
}
//////////////////////pA3 local /////////////////////////////////
if(!Tempter_errorState[2]&&!output_errorState[2]&&!input_errorState[2])
{
if( remotePA3RFONOFF())
{
SetPA3RFONOFF(1);
PA3statan=1;
}
else
{
SetPA3RFONOFF(0);
PA3statan=0;
}
}
else
{
SetPA3RFONOFF(0);
PA3statan=0;
}
if(GetPA3RFONOFF()==0&&remotePA3RFONOFF()==0)
{
Tempter_errorState[2]=0;
output_errorState[2]=0;
input_errorState[2]=0;
}
}
void TimingDelay_Decrement(void)
{
if (TimingDelay != 0x00)
{
TimingDelay--;
}
}
void PAERROR(void)
{
int panumber;
int pa2inputmax=2000;//將PA2、PA3兩個(gè)輸入輸出門限提前
int pa3inputmax=2000;
int pa2oOutputmin=900;
int pa3oOutputmin=90;
int un=0;
double voldata=0;
for(panumber=0;panumber<3;panumber++)
{
if(TestTempter[panumber]> MaxTempter ||Tempter_errorState[panumber]==1 )//wendu
{
Tempter_errorState[panumber] = 1;
SetPARFONOFF(panumber+1,0);
}
else
{
Tempter_errorState[panumber] = 0;
}
if(input_errorState[panumber]==1)
{
}
else if(panumber==0)
{
input_errorState[panumber]=0;
}
else if(panumber==1)
{
if(PaPower[1]>pa2inputmax)
{
input_errorState[panumber]=1;
InputPA2Dispay(1);
}
}
else if(panumber==2)
{
if(PaPower[4]> pa3inputmax)
{
input_errorState[panumber]=1;
//InputPA3Dispay(1);
}
}
//output power+
if(output_errorState[panumber]==1)
{
}
else if(panumber==0)
{
output_errorState[panumber]=0;
if(PA1IsOrNotError()==1)
{
output_errorState[panumber]=1;
}
}
else if(panumber==1)//0:no,1:red,2 green
{
voldata= PaPower[3]-PaPower[2];
if(PaPower[2]>pa2oOutputmin)
{
output_errorState[panumber]=0;
OutputPA2Dispay(0);
if(PaPower[1]<pa2inputmax)
{
input_errorState[panumber]=0;
InputPA2Dispay(0);
Errornumber1=0;
}
}
else if(PaPower[2]<pa2oOutputmin && voldata<50)//todo 50
{
Errornumber1++;
if(Errornumber1>6)
{
output_errorState[panumber]=1;
OutputPA2Dispay(1);
un=10;
}
}
else
{
output_errorState[panumber]=0;
OutputPA2Dispay(2);
Errornumber1=0;
if(PaPower[1]<pa2inputmax)
{
input_errorState[panumber]=0;
InputPA2Dispay(2);
}
}
}
else if(panumber==2)
{
if(PaPower[7]<1)
{
PaPower[7]=1;
}
dataRatio=PaPower[6]*100/PaPower[7];
if(PaPower[6]<pa3oOutputmin)
{
output_errorState[panumber]=0;
if(PaPower[4]<pa3inputmax)
{
Errornumber2=0;
input_errorState[panumber]=0;
InputPA3Dispay(0);
}
OutputPA3Dispay(0);
}
else if(PaPower[6]>pa3oOutputmin && dataRatio<180)//pulse is off
{
//printf("%d\r\n",dataRatio);
Errornumber2++;
if(Errornumber2>5)
{
output_errorState[panumber]=1;
//OutputPA3Dispay(1);
}
}
else
{
Errornumber2=0;
output_errorState[panumber]=0;
OutputPA3Dispay(2);
if(PaPower[4]<pa3inputmax)
{
input_errorState[panumber]=0;
InputPA3Dispay(2);
}
}
}
}
}
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t* file, uint32_t line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* Infinite loop */
while (1)
{
}
}
#endif
PUTCHAR_PROTOTYPE
{
/* Place your implementation of fputc here */
/* e.g. write a character to the USART */
USART_SendData(EVAL_COM1, (uint8_t) ch);
/* Loop until the end of transmission */
while (USART_GetFlagStatus(EVAL_COM1, USART_FLAG_TC) == RESET)
{
}
return ch;
}
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
復(fù)制代碼
所有資料51hei提供下載:
監(jiān)控程序_10.29.7z
(306.32 KB, 下載次數(shù): 53)
2019-1-17 16:08 上傳
點(diǎn)擊文件名下載附件
dmaadc
下載積分: 黑幣 -5
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1