当前位置:网站首页>Anonymous upper computer V7 waveform display

Anonymous upper computer V7 waveform display

2022-07-23 12:35:00 Alone, sir

Set the corresponding... According to the anonymous upper computer's flexible format frame Frame head

Because the format is relatively simple, the original code is directly pasted for reference ( General debugging pid Both are data comparison and debugging , So I only wrote two functions to send comparison , One int16 And a int32, It's enough )

Be careful : Due to the large sending volume, it is best to configure the serial port dma, The procedure here is stm32 Upper

#ifndef ANO_TC_H
#define ANO_TC_H

#include "main.h"

#define BYTE0(dwTemp)       (*(char *)(&dwTemp))
#define BYTE1(dwTemp)       (*((char *)(&dwTemp) +1))
#define BYTE2(dwTemp)       (*((char *)(&dwTemp) +2))
#define BYTE3(dwTemp)       (*((char *)(&dwTemp) +3))

void AnoTc_Send2Int32(int32_t _a,int32_t _b);
void AnoTc_Send2Int16(int16_t _a,int16_t _b);
void AnoTc_SendF1_Test(void);
#endif
#include "ano_tc.h"
#include <stdio.h>
#include <math.h>


/* communication Interface */
#include "usart.h"
void Ano_Tc_Send_Dma(uint8_t *buf,uint8_t len)
{
	while(huart1.gState!=HAL_UART_STATE_READY);
 if(HAL_UART_Transmit_DMA(&huart1, buf,len)!= HAL_OK) // Judge whether the transmission is normal , If an exception occurs, enter the exception interrupt function 
  {
   Error_Handler();
  }
	
}
/* communication Interface end */



void AnoTc_Send2Int16(int16_t _a,int16_t _b)// Send two  int16  The data of 
{
	static uint8_t DataToSend[10]={0XAA,0XFF,0XF1,4};//4 byte
  uint8_t sc=0;
  uint8_t ac=0;
  uint8_t i=0;

    DataToSend[4]=BYTE0(_a);
    DataToSend[5]=BYTE1(_a);
    DataToSend[6]=BYTE0(_b);
    DataToSend[7]=BYTE1(_b);
    for( i=0;i<DataToSend[3]+4;i++)
    {
        sc+=DataToSend[i];
        ac+=sc;
    }
    DataToSend[8]=sc;
    DataToSend[9]=ac;
		
		Ano_Tc_Send_Dma(DataToSend,10);
}

void AnoTc_Send2Int32(int32_t _a,int32_t _b)// Send two  int32  The data of 
{
static uint8_t DataToSend[14]={0XAA,0XFF,0XF1,8};// Communication protocol decision  8byte
uint8_t sc=0;
uint8_t ac=0;
uint8_t i=0;

    DataToSend[4]=BYTE0(_a);
    DataToSend[5]=BYTE1(_a);
	DataToSend[6]=BYTE2(_a);
	DataToSend[7]=BYTE3(_a);
    DataToSend[8]=BYTE0(_b);
    DataToSend[9]=BYTE1(_b);
	DataToSend[10]=BYTE2(_b);
	DataToSend[11]=BYTE3(_b);
	
    for( i=0;i<DataToSend[3]+4;i++)
    {
        sc+=DataToSend[i];
        ac+=sc;
    }
		
    DataToSend[12]=sc;
    DataToSend[13]=ac;
		
		Ano_Tc_Send_Dma(DataToSend,14);
}

void AnoTc_SendF1_Test(void)
{
    static double i;
    int sum1,sum2;
    i+=0.01;
    if(i==6.28) i=0;
    sum1=(int16_t)(1000*sin(i));
	sum2=(int16_t)(1000*cos(i));
 // AnoTc_Send2Int16(sum2,sum1);
	AnoTc_Send2Int32(sum2,sum1);
}
	

1、 Execute... In a program void AnoTc_SendF1_Test(void)

2、 Set on the anonymous upper computer

  data 1 And data 2 Set to int32 Of

3、 Waveform display

 

 

原网站

版权声明
本文为[Alone, sir]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/204/202207230539204852.html