- 校正舵机中位、转向符号和阿克曼后轮差速模型\n- 增加航向角速度辅助及遥控通道调试开关\n- 将速度环提升至 200Hz,并按实际 dt 计算 PI 积分\n- 将 IMU 启动校准缩短为 2 秒\n- 为 USART3 增加 DMA 发送和 MCU 采样时间戳
983 lines
44 KiB
C
983 lines
44 KiB
C
#include "usartx.h"
|
||
SEND_DATA Send_Data;
|
||
RECEIVE_DATA Receive_Data;
|
||
extern int Time_count;
|
||
|
||
//Sample timestamps written by the acquisition tasks (see usartx.h).
|
||
//Session ID stays constant for one MCU boot; a fixed nonzero marker is
|
||
//enough for the host to detect a restart (counter cleared to 0).
|
||
//<2F>ɲɼ<C9B2><C9BC><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4>IJ<EFBFBD><C4B2><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>(<28><> usartx.h)<29><><EFBFBD>ỰID<49>ڱ<EFBFBD><DAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>䣬
|
||
//<2F>̶<EFBFBD><CCB6><EFBFBD>0ֵ<30><D6B5><EFBFBD>ϴ<EFBFBD><CFB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʶ<EFBFBD><CAB6><EFBFBD>ػ<EFBFBD><D8BB><EFBFBD>
|
||
volatile unsigned long long g_speed_sample_time_us = 0;
|
||
volatile unsigned long long g_imu_sample_time_us = 0;
|
||
volatile unsigned int g_session_id = 0xA5A5A5A5U;
|
||
|
||
/**************************************************************************
|
||
Function: Usartx3, Usartx1,Usartx5 and CAN send data task
|
||
Input : none
|
||
Output : none
|
||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>3<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>5<EFBFBD><EFBFBD>CAN<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
<EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD> ֵ<><D6B5><EFBFBD><EFBFBD>
|
||
**************************************************************************/
|
||
void data_task(void *pvParameters)
|
||
{
|
||
u32 lastWakeTime = getSysTickCnt();
|
||
|
||
while(1)
|
||
{
|
||
//The task is run at 200hz. Only ROS (USART3) is sent, via non-blocking DMA.
|
||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>200Hz<48><7A>Ƶ<EFBFBD><C6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֻ<EFBFBD><D6BB>ROS(<28><><EFBFBD><EFBFBD>3)<29><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>DMA<4D><41><EFBFBD>巢<EFBFBD>͡<EFBFBD>
|
||
vTaskDelayUntil(&lastWakeTime, F2T(RATE_200_HZ));
|
||
//Assign the data to be sent
|
||
//<2F><>Ҫ<EFBFBD><D2AA><EFBFBD>з<EFBFBD><D0B7>͵<EFBFBD><CDB5><EFBFBD><EFBFBD>ݽ<EFBFBD><DDBD>и<EFBFBD>ֵ
|
||
data_transition();
|
||
USART3_SEND(); //Serial port 3 (ROS) sends data //<2F><><EFBFBD><EFBFBD>3(ROS)<29><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
}
|
||
}
|
||
/**************************************************************************
|
||
Function: The data sent by the serial port is assigned
|
||
Input : none
|
||
Output : none
|
||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڷ<EFBFBD><EFBFBD>͵<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݽ<EFBFBD><EFBFBD>и<EFBFBD>ֵ
|
||
<EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD> ֵ<><D6B5><EFBFBD><EFBFBD>
|
||
**************************************************************************/
|
||
void data_transition(void)
|
||
{
|
||
Send_Data.Sensor_Str.Frame_Header = FRAME_HEADER; //Frame_header //֡ͷ
|
||
Send_Data.Sensor_Str.Frame_Tail = FRAME_TAIL; //Frame_tail //֡β
|
||
|
||
//According to different vehicle types, different kinematics algorithms were selected to carry out the forward kinematics solution,
|
||
//and the three-axis velocity was obtained from each wheel velocity
|
||
//<2F><><EFBFBD>ݲ<EFBFBD>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1>ͬ<EFBFBD>˶<EFBFBD>ѧ<EFBFBD>㷨<EFBFBD><E3B7A8><EFBFBD><EFBFBD><EFBFBD>˶<EFBFBD>ѧ<EFBFBD><D1A7><EFBFBD>⣬<EFBFBD>Ӹ<EFBFBD><D3B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٶ<EFBFBD><D9B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٶ<EFBFBD>
|
||
switch(Car_Mode)
|
||
{
|
||
case Mec_Car:
|
||
Send_Data.Sensor_Str.X_speed = ((MOTOR_A.Encoder+MOTOR_B.Encoder+MOTOR_C.Encoder+MOTOR_D.Encoder)/4)*1000;
|
||
Send_Data.Sensor_Str.Y_speed = ((MOTOR_A.Encoder-MOTOR_B.Encoder+MOTOR_C.Encoder-MOTOR_D.Encoder)/4)*1000;
|
||
Send_Data.Sensor_Str.Z_speed = ((-MOTOR_A.Encoder-MOTOR_B.Encoder+MOTOR_C.Encoder+MOTOR_D.Encoder)/4/(Axle_spacing+Wheel_spacing))*1000;
|
||
break;
|
||
|
||
case Omni_Car:
|
||
Send_Data.Sensor_Str.X_speed = ((MOTOR_C.Encoder-MOTOR_B.Encoder)/2/X_PARAMETER)*1000;
|
||
Send_Data.Sensor_Str.Y_speed = ((MOTOR_A.Encoder*2-MOTOR_B.Encoder-MOTOR_C.Encoder)/3)*1000;
|
||
Send_Data.Sensor_Str.Z_speed = ((MOTOR_A.Encoder+MOTOR_B.Encoder+MOTOR_C.Encoder)/3/Omni_turn_radiaus)*1000;
|
||
break;
|
||
|
||
case Akm_Car:
|
||
Send_Data.Sensor_Str.X_speed = ((MOTOR_A.Encoder+MOTOR_B.Encoder)/2)*1000;
|
||
Send_Data.Sensor_Str.Y_speed = 0;
|
||
Send_Data.Sensor_Str.Z_speed = ((MOTOR_B.Encoder-MOTOR_A.Encoder)/Wheel_spacing)*1000;
|
||
break;
|
||
|
||
case Diff_Car:
|
||
Send_Data.Sensor_Str.X_speed = ((MOTOR_A.Encoder+MOTOR_B.Encoder)/2)*1000;
|
||
Send_Data.Sensor_Str.Y_speed = 0;
|
||
Send_Data.Sensor_Str.Z_speed = ((MOTOR_B.Encoder-MOTOR_A.Encoder)/Wheel_spacing)*1000;
|
||
break;
|
||
|
||
case FourWheel_Car:
|
||
Send_Data.Sensor_Str.X_speed = ((MOTOR_A.Encoder+MOTOR_B.Encoder+MOTOR_C.Encoder+MOTOR_D.Encoder)/4)*1000;
|
||
Send_Data.Sensor_Str.Y_speed = 0;
|
||
Send_Data.Sensor_Str.Z_speed = ((-MOTOR_B.Encoder-MOTOR_A.Encoder+MOTOR_C.Encoder+MOTOR_D.Encoder)/2/(Axle_spacing+Wheel_spacing))*1000;
|
||
break;
|
||
|
||
case Tank_Car:
|
||
Send_Data.Sensor_Str.X_speed = ((MOTOR_A.Encoder+MOTOR_B.Encoder)/2)*1000;
|
||
Send_Data.Sensor_Str.Y_speed = 0;
|
||
Send_Data.Sensor_Str.Z_speed = ((MOTOR_B.Encoder-MOTOR_A.Encoder)/(Wheel_spacing)*1000);
|
||
break;
|
||
}
|
||
|
||
//The acceleration of the triaxial acceleration //<2F><><EFBFBD>ٶȼ<D9B6><C8BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٶ<EFBFBD>
|
||
Send_Data.Sensor_Str.Accelerometer.X_data= accel[1]; //The accelerometer Y-axis is converted to the ros coordinate X axis //<2F><><EFBFBD>ٶȼ<D9B6>Y<EFBFBD><59>ת<EFBFBD><D7AA><EFBFBD><EFBFBD>ROS<4F><53><EFBFBD><EFBFBD>X<EFBFBD><58>
|
||
Send_Data.Sensor_Str.Accelerometer.Y_data=-accel[0]; //The accelerometer X-axis is converted to the ros coordinate y axis //<2F><><EFBFBD>ٶȼ<D9B6>X<EFBFBD><58>ת<EFBFBD><D7AA><EFBFBD><EFBFBD>ROS<4F><53><EFBFBD><EFBFBD>Y<EFBFBD><59>
|
||
Send_Data.Sensor_Str.Accelerometer.Z_data= accel[2]; //The accelerometer Z-axis is converted to the ros coordinate Z axis //<2F><><EFBFBD>ٶȼ<D9B6>Z<EFBFBD><5A>ת<EFBFBD><D7AA><EFBFBD><EFBFBD>ROS<4F><53><EFBFBD><EFBFBD>Z<EFBFBD><5A>
|
||
|
||
//The Angle velocity of the triaxial velocity //<2F><><EFBFBD>ٶȼ<D9B6><C8BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٶ<EFBFBD>
|
||
Send_Data.Sensor_Str.Gyroscope.X_data= gyro[1]; //The Y-axis is converted to the ros coordinate X axis //<2F><><EFBFBD>ٶȼ<D9B6>Y<EFBFBD><59>ת<EFBFBD><D7AA><EFBFBD><EFBFBD>ROS<4F><53><EFBFBD><EFBFBD>X<EFBFBD><58>
|
||
Send_Data.Sensor_Str.Gyroscope.Y_data=-gyro[0]; //The X-axis is converted to the ros coordinate y axis //<2F><><EFBFBD>ٶȼ<D9B6>X<EFBFBD><58>ת<EFBFBD><D7AA><EFBFBD><EFBFBD>ROS<4F><53><EFBFBD><EFBFBD>Y<EFBFBD><59>
|
||
if(Flag_Stop==0)
|
||
//If the motor control bit makes energy state, the z-axis velocity is sent normall
|
||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λʹ<CEBB><CAB9>״̬<D7B4><CCAC><EFBFBD><EFBFBD>ô<EFBFBD><C3B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Z<EFBFBD><5A><EFBFBD><EFBFBD>ٶ<EFBFBD>
|
||
Send_Data.Sensor_Str.Gyroscope.Z_data=gyro[2];
|
||
else
|
||
//If the robot is static (motor control dislocation), the z-axis is 0
|
||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ǿ<EFBFBD>ֹ<EFBFBD>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λʧ<CEBB>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD><EFBFBD>ô<EFBFBD><C3B4><EFBFBD>͵<EFBFBD>Z<EFBFBD><5A><EFBFBD><EFBFBD>ٶ<EFBFBD>Ϊ0
|
||
Send_Data.Sensor_Str.Gyroscope.Z_data=0;
|
||
|
||
//Battery voltage (this is a thousand times larger floating point number, which will be reduced by a thousand times as well as receiving the data).
|
||
//<2F><>ص<EFBFBD>ѹ(<28><><EFBFBD>ォ<EFBFBD><EFBDAB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŵ<EFBFBD>һǧ<D2BB><C7A7><EFBFBD><EFBFBD><EFBFBD>䣬<EFBFBD><E4A3AC>Ӧ<EFBFBD><D3A6><EFBFBD>ڽ<EFBFBD><DABD>ն<EFBFBD><D5B6>ڽ<EFBFBD><DABD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD>ݺ<EFBFBD>Ҳ<EFBFBD><D2B2><EFBFBD><EFBFBD>Сһǧ<D2BB><C7A7>)
|
||
Send_Data.Sensor_Str.Power_Voltage = Voltage*1000;
|
||
|
||
Send_Data.buffer[0]=Send_Data.Sensor_Str.Frame_Header; //Frame_heade //֡ͷ
|
||
Send_Data.buffer[1]=Flag_Stop; //Car software loss marker //С<><D0A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܱ<EFBFBD>־λ
|
||
|
||
//The three-axis speed of / / car is split into two eight digit Numbers
|
||
//С<><D0A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٶ<EFBFBD>,<2C><><EFBFBD>ᶼ<EFBFBD><E1B6BC><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>8λ<38><CEBB><EFBFBD><EFBFBD><EFBFBD>ٷ<EFBFBD><D9B7><EFBFBD>
|
||
Send_Data.buffer[2]=Send_Data.Sensor_Str.X_speed >>8;
|
||
Send_Data.buffer[3]=Send_Data.Sensor_Str.X_speed ;
|
||
Send_Data.buffer[4]=Send_Data.Sensor_Str.Y_speed>>8;
|
||
Send_Data.buffer[5]=Send_Data.Sensor_Str.Y_speed;
|
||
Send_Data.buffer[6]=Send_Data.Sensor_Str.Z_speed >>8;
|
||
Send_Data.buffer[7]=Send_Data.Sensor_Str.Z_speed ;
|
||
|
||
//The acceleration of the triaxial axis of / / imu accelerometer is divided into two eight digit reams
|
||
//IMU<4D><55><EFBFBD>ٶȼ<D9B6><C8BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٶ<EFBFBD>,<2C><><EFBFBD>ᶼ<EFBFBD><E1B6BC><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>8λ<38><CEBB><EFBFBD><EFBFBD><EFBFBD>ٷ<EFBFBD><D9B7><EFBFBD>
|
||
Send_Data.buffer[8]=Send_Data.Sensor_Str.Accelerometer.X_data>>8;
|
||
Send_Data.buffer[9]=Send_Data.Sensor_Str.Accelerometer.X_data;
|
||
Send_Data.buffer[10]=Send_Data.Sensor_Str.Accelerometer.Y_data>>8;
|
||
Send_Data.buffer[11]=Send_Data.Sensor_Str.Accelerometer.Y_data;
|
||
Send_Data.buffer[12]=Send_Data.Sensor_Str.Accelerometer.Z_data>>8;
|
||
Send_Data.buffer[13]=Send_Data.Sensor_Str.Accelerometer.Z_data;
|
||
|
||
//The axis of the triaxial velocity of the / /imu is divided into two eight digits
|
||
//IMU<4D><55><EFBFBD>ٶȼ<D9B6><C8BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٶ<EFBFBD>,<2C><><EFBFBD>ᶼ<EFBFBD><E1B6BC><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>8λ<38><CEBB><EFBFBD><EFBFBD><EFBFBD>ٷ<EFBFBD><D9B7><EFBFBD>
|
||
Send_Data.buffer[14]=Send_Data.Sensor_Str.Gyroscope.X_data>>8;
|
||
Send_Data.buffer[15]=Send_Data.Sensor_Str.Gyroscope.X_data;
|
||
Send_Data.buffer[16]=Send_Data.Sensor_Str.Gyroscope.Y_data>>8;
|
||
Send_Data.buffer[17]=Send_Data.Sensor_Str.Gyroscope.Y_data;
|
||
Send_Data.buffer[18]=Send_Data.Sensor_Str.Gyroscope.Z_data>>8;
|
||
Send_Data.buffer[19]=Send_Data.Sensor_Str.Gyroscope.Z_data;
|
||
|
||
//Battery voltage, split into two 8 digit Numbers
|
||
//<2F><>ص<EFBFBD>ѹ,<2C><><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>8λ<38><CEBB><EFBFBD>ݷ<EFBFBD><DDB7><EFBFBD>
|
||
Send_Data.buffer[20]=Send_Data.Sensor_Str.Power_Voltage >>8;
|
||
Send_Data.buffer[21]=Send_Data.Sensor_Str.Power_Voltage;
|
||
|
||
//Snapshot the session ID and the two sample timestamps captured by the
|
||
//acquisition tasks. All appended fields are big-endian (high byte first)
|
||
//to match the existing >>8 speed/IMU packing.
|
||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Բɼ<D4B2><C9BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>ĻỰID<49><44><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><D7B7><EFBFBD>ֶ<EFBFBD><D6B6>þ<EFBFBD><C3BE><EFBFBD>(<28><>λ<EFBFBD><CEBB>ǰ)<29><>
|
||
//<2F><><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD> >>8 <20><><EFBFBD>/IMU<4D><55><EFBFBD><EFBFBD><EFBFBD>ʽһ<CABD>¡<EFBFBD>
|
||
Send_Data.Sensor_Str.Session_Id = g_session_id;
|
||
Send_Data.Sensor_Str.Speed_Time_us = g_speed_sample_time_us;
|
||
Send_Data.Sensor_Str.Imu_Time_us = g_imu_sample_time_us;
|
||
|
||
//session_id (uint32, big-endian) //<2F>ỰID
|
||
Send_Data.buffer[22]=(unsigned char)(Send_Data.Sensor_Str.Session_Id>>24);
|
||
Send_Data.buffer[23]=(unsigned char)(Send_Data.Sensor_Str.Session_Id>>16);
|
||
Send_Data.buffer[24]=(unsigned char)(Send_Data.Sensor_Str.Session_Id>>8);
|
||
Send_Data.buffer[25]=(unsigned char)(Send_Data.Sensor_Str.Session_Id);
|
||
|
||
//speed_sample_time_us (uint64, big-endian) //<2F>ٶȲ<D9B6><C8B2><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>
|
||
Send_Data.buffer[26]=(unsigned char)(Send_Data.Sensor_Str.Speed_Time_us>>56);
|
||
Send_Data.buffer[27]=(unsigned char)(Send_Data.Sensor_Str.Speed_Time_us>>48);
|
||
Send_Data.buffer[28]=(unsigned char)(Send_Data.Sensor_Str.Speed_Time_us>>40);
|
||
Send_Data.buffer[29]=(unsigned char)(Send_Data.Sensor_Str.Speed_Time_us>>32);
|
||
Send_Data.buffer[30]=(unsigned char)(Send_Data.Sensor_Str.Speed_Time_us>>24);
|
||
Send_Data.buffer[31]=(unsigned char)(Send_Data.Sensor_Str.Speed_Time_us>>16);
|
||
Send_Data.buffer[32]=(unsigned char)(Send_Data.Sensor_Str.Speed_Time_us>>8);
|
||
Send_Data.buffer[33]=(unsigned char)(Send_Data.Sensor_Str.Speed_Time_us);
|
||
|
||
//imu_sample_time_us (uint64, big-endian) //IMU<4D><55><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>
|
||
Send_Data.buffer[34]=(unsigned char)(Send_Data.Sensor_Str.Imu_Time_us>>56);
|
||
Send_Data.buffer[35]=(unsigned char)(Send_Data.Sensor_Str.Imu_Time_us>>48);
|
||
Send_Data.buffer[36]=(unsigned char)(Send_Data.Sensor_Str.Imu_Time_us>>40);
|
||
Send_Data.buffer[37]=(unsigned char)(Send_Data.Sensor_Str.Imu_Time_us>>32);
|
||
Send_Data.buffer[38]=(unsigned char)(Send_Data.Sensor_Str.Imu_Time_us>>24);
|
||
Send_Data.buffer[39]=(unsigned char)(Send_Data.Sensor_Str.Imu_Time_us>>16);
|
||
Send_Data.buffer[40]=(unsigned char)(Send_Data.Sensor_Str.Imu_Time_us>>8);
|
||
Send_Data.buffer[41]=(unsigned char)(Send_Data.Sensor_Str.Imu_Time_us);
|
||
|
||
//Data check digit calculation, Pattern 1 is a data check. Now covers the
|
||
//42 payload bytes (0..41) preceding the checksum.
|
||
//<2F><><EFBFBD><EFBFBD>У<EFBFBD><D0A3>λ<EFBFBD><CEBB><EFBFBD>㣬ģʽ1<CABD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD>顣<EFBFBD><E9A1A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD><D0A3>ǰ 42 <20>ֽ<EFBFBD>(0..41)<29><>
|
||
Send_Data.buffer[42]=Check_Sum(42,1);
|
||
|
||
Send_Data.buffer[43]=Send_Data.Sensor_Str.Frame_Tail; //Frame_tail //֡β
|
||
}
|
||
/**************************************************************************
|
||
Function: Serial port 1 sends data
|
||
Input : none
|
||
Output : none
|
||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
<EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD> ֵ<><D6B5><EFBFBD><EFBFBD>
|
||
**************************************************************************/
|
||
void USART1_SEND(void)
|
||
{
|
||
unsigned char i = 0;
|
||
|
||
for(i=0; i<SEND_DATA_SIZE; i++)
|
||
{
|
||
usart1_send(Send_Data.buffer[i]);
|
||
}
|
||
}
|
||
/**************************************************************************
|
||
Function: Serial port 3 sends data
|
||
Input : none
|
||
Output : none
|
||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>3<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
<EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD> ֵ<><D6B5><EFBFBD><EFBFBD>
|
||
**************************************************************************/
|
||
void USART3_SEND(void)
|
||
{
|
||
//Non-blocking DMA transmit of the 24-byte frame. If the previous transfer
|
||
//is still running, skip this cycle rather than busy-wait.
|
||
//DMA<4D><41><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>24<32>ֽ<EFBFBD>֡<EFBFBD><D6A1><EFBFBD><EFBFBD>һ֡δ<D6A1><CEB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڣ<EFBFBD><DAA3><EFBFBD>æ<EFBFBD>ȴ<EFBFBD><C8B4><EFBFBD>
|
||
if(DMA_GetCmdStatus(DMA1_Stream3) != DISABLE) return;
|
||
|
||
DMA_ClearFlag(DMA1_Stream3, DMA_FLAG_TCIF3 | DMA_FLAG_HTIF3 |
|
||
DMA_FLAG_TEIF3 | DMA_FLAG_DMEIF3 | DMA_FLAG_FEIF3);
|
||
DMA_SetCurrDataCounter(DMA1_Stream3, SEND_DATA_SIZE);
|
||
DMA_Cmd(DMA1_Stream3, ENABLE);
|
||
}
|
||
/**************************************************************************
|
||
Function: Serial port 5 sends data
|
||
Input : none
|
||
Output : none
|
||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>5<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
<EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD> ֵ<><D6B5><EFBFBD><EFBFBD>
|
||
**************************************************************************/
|
||
void USART5_SEND(void)
|
||
{
|
||
unsigned char i = 0;
|
||
for(i=0; i<SEND_DATA_SIZE; i++)
|
||
{
|
||
usart5_send(Send_Data.buffer[i]);
|
||
}
|
||
}
|
||
/**************************************************************************
|
||
Function: CAN sends data
|
||
Input : none
|
||
Output : none
|
||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܣ<EFBFBD>CAN<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
<EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
<EFBFBD><EFBFBD> <20><> ֵ<><D6B5><EFBFBD><EFBFBD>
|
||
**************************************************************************/
|
||
void CAN_SEND(void)
|
||
{
|
||
u8 CAN_SENT[8],i;
|
||
|
||
for(i=0;i<8;i++)
|
||
{
|
||
CAN_SENT[i]=Send_Data.buffer[i];
|
||
}
|
||
CAN1_Send_Num(0x101,CAN_SENT);
|
||
|
||
for(i=0;i<8;i++)
|
||
{
|
||
CAN_SENT[i]=Send_Data.buffer[i+8];
|
||
}
|
||
CAN1_Send_Num(0x102,CAN_SENT);
|
||
|
||
for(i=0;i<8;i++)
|
||
{
|
||
CAN_SENT[i]=Send_Data.buffer[i+16];
|
||
}
|
||
CAN1_Send_Num(0x103,CAN_SENT);
|
||
}
|
||
/**************************************************************************
|
||
Function: Serial port 1 initialization
|
||
Input : none
|
||
Output : none
|
||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>
|
||
<EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
<EFBFBD><EFBFBD> <20><> ֵ<><D6B5><EFBFBD><EFBFBD>
|
||
**************************************************************************/
|
||
void uart1_init(u32 bound)
|
||
{
|
||
GPIO_InitTypeDef GPIO_InitStructure;
|
||
USART_InitTypeDef USART_InitStructure;
|
||
NVIC_InitTypeDef NVIC_InitStructure;
|
||
|
||
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); //Enable the gpio clock //ʹ<><CAB9>GPIOʱ<4F><CAB1>
|
||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); //Enable the Usart clock //ʹ<><CAB9>USARTʱ<54><CAB1>
|
||
|
||
GPIO_PinAFConfig(GPIOA,GPIO_PinSource9,GPIO_AF_USART1);
|
||
GPIO_PinAFConfig(GPIOA,GPIO_PinSource10 ,GPIO_AF_USART1);
|
||
|
||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9|GPIO_Pin_10;
|
||
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF; //<2F><><EFBFBD>ģʽ
|
||
GPIO_InitStructure.GPIO_OType=GPIO_OType_PP; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz; //<2F><><EFBFBD><EFBFBD>50MHZ
|
||
GPIO_InitStructure.GPIO_PuPd=GPIO_PuPd_UP; //<2F><><EFBFBD><EFBFBD>
|
||
GPIO_Init(GPIOA, &GPIO_InitStructure); //<2F><>ʼ<EFBFBD><CABC>
|
||
|
||
//UsartNVIC configuration //UsartNVIC<49><43><EFBFBD><EFBFBD>
|
||
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
|
||
//Preempt priority //<2F><>ռ<EFBFBD><D5BC><EFBFBD>ȼ<EFBFBD>
|
||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1 ;
|
||
//Subpriority //<2F><><EFBFBD><EFBFBD><EFBFBD>ȼ<EFBFBD>
|
||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
|
||
//Enable the IRQ channel //IRQͨ<51><CDA8>ʹ<EFBFBD><CAB9>
|
||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||
//Initialize the VIC register with the specified parameters
|
||
//<2F><><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD>IJ<EFBFBD><C4B2><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>VIC<49>Ĵ<EFBFBD><C4B4><EFBFBD>
|
||
NVIC_Init(&NVIC_InitStructure);
|
||
|
||
//USART Initialization Settings <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
USART_InitStructure.USART_BaudRate = bound; //Port rate //<2F><><EFBFBD>ڲ<EFBFBD><DAB2><EFBFBD><EFBFBD><EFBFBD>
|
||
USART_InitStructure.USART_WordLength = USART_WordLength_8b; //The word length is 8 bit data format //<2F>ֳ<EFBFBD>Ϊ8λ<38><CEBB><EFBFBD>ݸ<EFBFBD>ʽ
|
||
USART_InitStructure.USART_StopBits = USART_StopBits_1; //A stop bit //һ<><D2BB>ֹͣλ
|
||
USART_InitStructure.USART_Parity = USART_Parity_No; //Prosaic parity bits //<2F><><EFBFBD><EFBFBD>żУ<C5BC><D0A3>λ
|
||
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; //No hardware data flow control //<2F><>Ӳ<EFBFBD><D3B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; //Sending and receiving mode //<2F>շ<EFBFBD>ģʽ
|
||
USART_Init(USART1, &USART_InitStructure); //Initialize serial port 1 //<2F><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1
|
||
|
||
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE); //Open the serial port to accept interrupts //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڽ<EFBFBD><DABD><EFBFBD><EFBFBD>ж<EFBFBD>
|
||
USART_Cmd(USART1, ENABLE); //Enable serial port 1 //ʹ<>ܴ<EFBFBD><DCB4><EFBFBD>1
|
||
}
|
||
/**************************************************************************
|
||
Function: Serial port 2 initialization
|
||
Input : none
|
||
Output : none
|
||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>2<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>
|
||
<EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD> ֵ<><D6B5><EFBFBD><EFBFBD>
|
||
**************************************************************************/
|
||
void uart2_init(u32 bound)
|
||
{
|
||
GPIO_InitTypeDef GPIO_InitStructure;
|
||
USART_InitTypeDef USART_InitStructure;
|
||
NVIC_InitTypeDef NVIC_InitStructure;
|
||
|
||
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE); //Enable the gpio clock //ʹ<><CAB9>GPIOʱ<4F><CAB1>
|
||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE); //Enable the Usart clock //ʹ<><CAB9>USARTʱ<54><CAB1>
|
||
|
||
GPIO_PinAFConfig(GPIOD,GPIO_PinSource5,GPIO_AF_USART2);
|
||
GPIO_PinAFConfig(GPIOD,GPIO_PinSource6 ,GPIO_AF_USART2);
|
||
|
||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5|GPIO_Pin_6;
|
||
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF; //<2F><><EFBFBD>ģʽ
|
||
GPIO_InitStructure.GPIO_OType=GPIO_OType_PP; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz; //<2F><><EFBFBD><EFBFBD>50MHZ
|
||
GPIO_InitStructure.GPIO_PuPd=GPIO_PuPd_UP; //<2F><><EFBFBD><EFBFBD>
|
||
GPIO_Init(GPIOD, &GPIO_InitStructure); //<2F><>ʼ<EFBFBD><CABC>
|
||
|
||
//UsartNVIC configuration //UsartNVIC<49><43><EFBFBD><EFBFBD>
|
||
NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
|
||
//Preempt priority //<2F><>ռ<EFBFBD><D5BC><EFBFBD>ȼ<EFBFBD>
|
||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1 ;
|
||
//Subpriority //<2F><><EFBFBD><EFBFBD><EFBFBD>ȼ<EFBFBD>
|
||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
|
||
//Enable the IRQ channel //IRQͨ<51><CDA8>ʹ<EFBFBD><CAB9>
|
||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||
//Initialize the VIC register with the specified parameters
|
||
//<2F><><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD>IJ<EFBFBD><C4B2><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>VIC<49>Ĵ<EFBFBD><C4B4><EFBFBD>
|
||
NVIC_Init(&NVIC_InitStructure);
|
||
|
||
//USART Initialization Settings <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
USART_InitStructure.USART_BaudRate = bound; //Port rate //<2F><><EFBFBD>ڲ<EFBFBD><DAB2><EFBFBD><EFBFBD><EFBFBD>
|
||
USART_InitStructure.USART_WordLength = USART_WordLength_8b; //The word length is 8 bit data format //<2F>ֳ<EFBFBD>Ϊ8λ<38><CEBB><EFBFBD>ݸ<EFBFBD>ʽ
|
||
USART_InitStructure.USART_StopBits = USART_StopBits_1; //A stop bit //һ<><D2BB>ֹͣ
|
||
USART_InitStructure.USART_Parity = USART_Parity_No; //Prosaic parity bits //<2F><><EFBFBD><EFBFBD>żУ<C5BC><D0A3>λ
|
||
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; //No hardware data flow control //<2F><>Ӳ<EFBFBD><D3B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; //Sending and receiving mode //<2F>շ<EFBFBD>ģʽ
|
||
USART_Init(USART2, &USART_InitStructure); //Initialize serial port 2 //<2F><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>2
|
||
|
||
USART_ITConfig(USART2, USART_IT_RXNE, ENABLE); //Open the serial port to accept interrupts //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڽ<EFBFBD><DABD><EFBFBD><EFBFBD>ж<EFBFBD>
|
||
USART_Cmd(USART2, ENABLE); //Enable serial port 2 //ʹ<>ܴ<EFBFBD><DCB4><EFBFBD>2
|
||
}
|
||
/**************************************************************************
|
||
Function: Serial port 3 initialization
|
||
Input : none
|
||
Output : none
|
||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>3<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>
|
||
<EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD> ֵ<><D6B5><EFBFBD><EFBFBD>
|
||
**************************************************************************/
|
||
void uart3_init(u32 bound)
|
||
{
|
||
GPIO_InitTypeDef GPIO_InitStructure;
|
||
USART_InitTypeDef USART_InitStructure;
|
||
NVIC_InitTypeDef NVIC_InitStructure;
|
||
|
||
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE); //Enable the gpio clock //ʹ<><CAB9>GPIOʱ<4F><CAB1>
|
||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE); //Enable the Usart clock //ʹ<><CAB9>USARTʱ<54><CAB1>
|
||
|
||
GPIO_PinAFConfig(GPIOD,GPIO_PinSource8,GPIO_AF_USART3);
|
||
GPIO_PinAFConfig(GPIOD,GPIO_PinSource9,GPIO_AF_USART3);
|
||
|
||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8|GPIO_Pin_9;
|
||
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF; //<2F><><EFBFBD>ģʽ
|
||
GPIO_InitStructure.GPIO_OType=GPIO_OType_PP; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz; //<2F><><EFBFBD><EFBFBD>50MHZ
|
||
GPIO_InitStructure.GPIO_PuPd=GPIO_PuPd_UP; //<2F><><EFBFBD><EFBFBD>
|
||
GPIO_Init(GPIOD, &GPIO_InitStructure); //<2F><>ʼ<EFBFBD><CABC>
|
||
|
||
//UsartNVIC configuration //UsartNVIC<49><43><EFBFBD><EFBFBD>
|
||
NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;
|
||
//Preempt priority //<2F><>ռ<EFBFBD><D5BC><EFBFBD>ȼ<EFBFBD>
|
||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=2 ;
|
||
//Preempt priority //<2F><>ռ<EFBFBD><D5BC><EFBFBD>ȼ<EFBFBD>
|
||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
|
||
//Enable the IRQ channel //IRQͨ<51><CDA8>ʹ<EFBFBD><CAB9>
|
||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||
//Initialize the VIC register with the specified parameters
|
||
//<2F><><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD>IJ<EFBFBD><C4B2><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>VIC<49>Ĵ<EFBFBD><C4B4><EFBFBD>
|
||
NVIC_Init(&NVIC_InitStructure);
|
||
|
||
//USART Initialization Settings <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
USART_InitStructure.USART_BaudRate = bound; //Port rate //<2F><><EFBFBD>ڲ<EFBFBD><DAB2><EFBFBD><EFBFBD><EFBFBD>
|
||
USART_InitStructure.USART_WordLength = USART_WordLength_8b; //The word length is 8 bit data format //<2F>ֳ<EFBFBD>Ϊ8λ<38><CEBB><EFBFBD>ݸ<EFBFBD>ʽ
|
||
USART_InitStructure.USART_StopBits = USART_StopBits_1; //A stop bit //һ<><D2BB>ֹͣ
|
||
USART_InitStructure.USART_Parity = USART_Parity_No; //Prosaic parity bits //<2F><><EFBFBD><EFBFBD>żУ<C5BC><D0A3>λ
|
||
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; //No hardware data flow control //<2F><>Ӳ<EFBFBD><D3B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; //Sending and receiving mode //<2F>շ<EFBFBD>ģʽ
|
||
USART_Init(USART3, &USART_InitStructure); //Initialize serial port 3 //<2F><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>3
|
||
|
||
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE); //Open the serial port to accept interrupts //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڽ<EFBFBD><DABD><EFBFBD><EFBFBD>ж<EFBFBD>
|
||
USART_Cmd(USART3, ENABLE); //Enable serial port 3 //ʹ<>ܴ<EFBFBD><DCB4><EFBFBD>3
|
||
|
||
uart3_dma_tx_init(); //Init DMA for USART3 TX //<2F><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>3<EFBFBD><33><EFBFBD><EFBFBD>DMA
|
||
}
|
||
/**************************************************************************
|
||
Function: USART3 TX DMA initialization (memory->peripheral, one-shot per frame)
|
||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>3<EFBFBD><EFBFBD><EFBFBD><EFBFBD>DMA<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>-><3E><><EFBFBD>裬ÿ֡<C3BF><D6A1><EFBFBD><EFBFBD>һ<EFBFBD>Σ<EFBFBD>
|
||
DMA1 Stream3 Channel4 is the TX request line for USART3 on STM32F407.
|
||
STM32F407 <20>ϴ<EFBFBD><CFB4><EFBFBD>3<EFBFBD>ķ<EFBFBD><C4B7><EFBFBD>DMA<4D><41><EFBFBD><EFBFBD>ΪDMA1_Stream3_Channel4<6C><34>
|
||
**************************************************************************/
|
||
void uart3_dma_tx_init(void)
|
||
{
|
||
DMA_InitTypeDef DMA_InitStructure;
|
||
|
||
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1, ENABLE);
|
||
|
||
DMA_DeInit(DMA1_Stream3);
|
||
while(DMA_GetCmdStatus(DMA1_Stream3) != DISABLE);
|
||
|
||
DMA_InitStructure.DMA_Channel = DMA_Channel_4;
|
||
DMA_InitStructure.DMA_PeripheralBaseAddr = (u32)&USART3->DR;
|
||
DMA_InitStructure.DMA_Memory0BaseAddr = (u32)Send_Data.buffer;
|
||
DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral;
|
||
DMA_InitStructure.DMA_BufferSize = SEND_DATA_SIZE;
|
||
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
|
||
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
|
||
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
|
||
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
|
||
DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
|
||
DMA_InitStructure.DMA_Priority = DMA_Priority_Medium;
|
||
DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable;
|
||
DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull;
|
||
DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
|
||
DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
|
||
DMA_Init(DMA1_Stream3, &DMA_InitStructure);
|
||
|
||
USART_DMACmd(USART3, USART_DMAReq_Tx, ENABLE);
|
||
}
|
||
/**************************************************************************
|
||
Function: Serial port 5 initialization
|
||
Input : none
|
||
Output : none
|
||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>5<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>
|
||
<EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD> ֵ<><D6B5><EFBFBD><EFBFBD>
|
||
**************************************************************************/
|
||
void uart5_init(u32 bound)
|
||
{
|
||
GPIO_InitTypeDef GPIO_InitStructure;
|
||
USART_InitTypeDef USART_InitStructure;
|
||
NVIC_InitTypeDef NVIC_InitStructure;
|
||
|
||
//PC12 TX
|
||
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE); //Enable the gpio clock //ʹ<><CAB9>GPIOʱ<4F><CAB1>
|
||
//PD2 RX
|
||
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE); //Enable the gpio clock //ʹ<><CAB9>GPIOʱ<4F><CAB1>
|
||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART5, ENABLE); //Enable the Usart clock //ʹ<><CAB9>USARTʱ<54><CAB1>
|
||
|
||
GPIO_PinAFConfig(GPIOC,GPIO_PinSource12,GPIO_AF_UART5);
|
||
GPIO_PinAFConfig(GPIOD,GPIO_PinSource2 ,GPIO_AF_UART5);
|
||
|
||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
|
||
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF; //<2F><><EFBFBD>ģʽ
|
||
GPIO_InitStructure.GPIO_OType=GPIO_OType_PP; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz; //<2F><><EFBFBD><EFBFBD>50MHZ
|
||
GPIO_InitStructure.GPIO_PuPd=GPIO_PuPd_UP; //<2F><><EFBFBD><EFBFBD>
|
||
GPIO_Init(GPIOC, &GPIO_InitStructure); //<2F><>ʼ<EFBFBD><CABC>
|
||
|
||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
|
||
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF; //<2F><><EFBFBD>ģʽ
|
||
GPIO_InitStructure.GPIO_OType=GPIO_OType_PP; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz; //<2F><><EFBFBD><EFBFBD>50MHZ
|
||
GPIO_InitStructure.GPIO_PuPd=GPIO_PuPd_UP; //<2F><><EFBFBD><EFBFBD>
|
||
GPIO_Init(GPIOD, &GPIO_InitStructure); //<2F><>ʼ<EFBFBD><CABC>
|
||
|
||
//UsartNVIC configuration //UsartNVIC<49><43><EFBFBD><EFBFBD>
|
||
NVIC_InitStructure.NVIC_IRQChannel = UART5_IRQn;
|
||
//Preempt priority //<2F><>ռ<EFBFBD><D5BC><EFBFBD>ȼ<EFBFBD>
|
||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=2 ;
|
||
//Preempt priority //<2F><>ռ<EFBFBD><D5BC><EFBFBD>ȼ<EFBFBD>
|
||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
|
||
//Enable the IRQ channel //IRQͨ<51><CDA8>ʹ<EFBFBD><CAB9>
|
||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||
//Initialize the VIC register with the specified parameters
|
||
//<2F><><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD>IJ<EFBFBD><C4B2><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>VIC<49>Ĵ<EFBFBD><C4B4><EFBFBD>
|
||
NVIC_Init(&NVIC_InitStructure);
|
||
|
||
//USART Initialization Settings <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
USART_InitStructure.USART_BaudRate = bound; //Port rate //<2F><><EFBFBD>ڲ<EFBFBD><DAB2><EFBFBD><EFBFBD><EFBFBD>
|
||
USART_InitStructure.USART_WordLength = USART_WordLength_8b; //The word length is 8 bit data format //<2F>ֳ<EFBFBD>Ϊ8λ<38><CEBB><EFBFBD>ݸ<EFBFBD>ʽ
|
||
USART_InitStructure.USART_StopBits = USART_StopBits_1; //A stop bit //һ<><D2BB>ֹͣ
|
||
USART_InitStructure.USART_Parity = USART_Parity_No; //Prosaic parity bits //<2F><><EFBFBD><EFBFBD>żУ<C5BC><D0A3>λ
|
||
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; //No hardware data flow control //<2F><>Ӳ<EFBFBD><D3B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; //Sending and receiving mode //<2F>շ<EFBFBD>ģʽ
|
||
USART_Init(UART5, &USART_InitStructure); //Initialize serial port 5 //<2F><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>5
|
||
USART_ITConfig(UART5, USART_IT_RXNE, ENABLE); //Open the serial port to accept interrupts //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڽ<EFBFBD><DABD><EFBFBD><EFBFBD>ж<EFBFBD>
|
||
USART_Cmd(UART5, ENABLE); //Enable serial port 5 //ʹ<>ܴ<EFBFBD><DCB4><EFBFBD>5
|
||
}
|
||
/**************************************************************************
|
||
Function: Serial port 1 receives interrupted
|
||
Input : none
|
||
Output : none
|
||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
||
<EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
<EFBFBD><EFBFBD> <20><> ֵ<><D6B5><EFBFBD><EFBFBD>
|
||
**************************************************************************/
|
||
int USART1_IRQHandler(void)
|
||
{
|
||
if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET) //Check if data is received //<2F>ж<EFBFBD><D0B6>Ƿ<EFBFBD><C7B7><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD>
|
||
{
|
||
u8 Usart_Receive;
|
||
static u8 Count;
|
||
static u8 rxbuf[11];
|
||
int check=0,error=1,i;
|
||
|
||
Usart_Receive = USART_ReceiveData(USART1); //Read the data //<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
|
||
if(Time_count<CONTROL_STARTUP_DELAY_COUNT)
|
||
// Data is not processed until the 2 second startup delay expires.
|
||
//<2F><><EFBFBD><EFBFBD>2<EFBFBD><32>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
return 0;
|
||
|
||
//Fill the array with serial data
|
||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
rxbuf[Count]=Usart_Receive;
|
||
|
||
//Ensure that the first data in the array is FRAME_HEADER
|
||
//ȷ<><C8B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ΪFRAME_HEADER
|
||
if(Usart_Receive == FRAME_HEADER||Count>0)
|
||
Count++;
|
||
else
|
||
Count=0;
|
||
|
||
if (Count == 11) //Verify the length of the packet //<2F><>֤<EFBFBD><D6A4><EFBFBD>ݰ<EFBFBD><DDB0>ij<EFBFBD><C4B3><EFBFBD>
|
||
{
|
||
Count=0; //Prepare for the serial port data to be refill into the array //Ϊ<><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><D7BC>
|
||
if(rxbuf[10] == FRAME_TAIL) //Verify the frame tail of the packet //<2F><>֤<EFBFBD><D6A4><EFBFBD>ݰ<EFBFBD><DDB0><EFBFBD>֡β
|
||
{
|
||
for(i=0; i<9; i++)
|
||
{
|
||
//XOR bit check, used to detect data error
|
||
//<2F><><EFBFBD>λУ<CEBB>飬<EFBFBD><E9A3AC><EFBFBD>ڼ<EFBFBD><DABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>
|
||
check=rxbuf[i]^check;
|
||
}
|
||
if(check==rxbuf[9])
|
||
//XOR bit check successful
|
||
//<2F><><EFBFBD>λУ<CEBB><D0A3>ɹ<EFBFBD>
|
||
error=0;
|
||
|
||
if(error==0)
|
||
{
|
||
float Vz;
|
||
if(Usart1_ON_Flag==0)
|
||
{
|
||
//Serial port 1 controls flag position 1, other flag position 0
|
||
//<2F><><EFBFBD><EFBFBD>1<EFBFBD><31><EFBFBD>Ʊ<EFBFBD>־λ<D6BE><CEBB>1<EFBFBD><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־λ<D6BE><CEBB>0
|
||
//Usart_ON_Flag=1;
|
||
Usart1_ON_Flag=1;
|
||
APP_ON_Flag=0;
|
||
PS2_ON_Flag=0;
|
||
Remote_ON_Flag=0;
|
||
CAN_ON_Flag=0;
|
||
}
|
||
command_lost_count=0; //CAN/<2F><><EFBFBD>ڿ<EFBFBD><DABF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EEB6AA><CAA7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
|
||
//Calculate the 3-axis target velocity from the serial data, which is divided into 8-bit high and 8-bit low units mm/s
|
||
//<2F>Ӵ<EFBFBD><D3B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD>ٶȣ<D9B6><C8A3>ָ<EFBFBD>8λ<38>͵<EFBFBD>8λ <20><>λmm/s
|
||
Move_X=XYZ_Target_Speed_transition(rxbuf[3],rxbuf[4]);
|
||
Move_Y=XYZ_Target_Speed_transition(rxbuf[5],rxbuf[6]);
|
||
Vz =XYZ_Target_Speed_transition(rxbuf[7],rxbuf[8]);
|
||
// Ackermann: pass the raw rotation speed wz [rad/s] straight
|
||
// through. Drive_Motor derives curvature kappa = wz/v itself,
|
||
// so no front-wheel-angle pre-conversion here.
|
||
Move_Z=Vz;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
return 0;
|
||
}
|
||
/**************************************************************************
|
||
Function: Refresh the OLED screen
|
||
Input : none
|
||
Output : none
|
||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>2<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
||
<EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD> ֵ<><D6B5><EFBFBD><EFBFBD>
|
||
**************************************************************************/
|
||
int USART2_IRQHandler(void)
|
||
{
|
||
int Usart_Receive;
|
||
if(USART_GetITStatus(USART2, USART_IT_RXNE) != RESET) //Check if data is received //<2F>ж<EFBFBD><D0B6>Ƿ<EFBFBD><C7B7><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD>
|
||
{
|
||
static u8 Flag_PID,i,j,Receive[50],Last_Usart_Receive;
|
||
static float Data;
|
||
|
||
Usart_Receive=USART2->DR; //Read the data //<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
|
||
|
||
if(Deviation_Count<CONTROL_DELAY)
|
||
// Data is not processed until the 2 second startup delay expires.
|
||
//<2F><><EFBFBD><EFBFBD>2<EFBFBD><32>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
return 0;
|
||
|
||
if(Usart_Receive==0x41&&Last_Usart_Receive==0x41&&APP_ON_Flag==0)
|
||
//10 seconds after startup, press the forward button of APP to enter APP control mode
|
||
//The APP controls the flag position 1 and the other flag position 0
|
||
//<2F><><EFBFBD><EFBFBD>10<31><30>֮<EFBFBD><EFBFBD><F3A3ACB0><EFBFBD>APP<50><50>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>APP<50><50><EFBFBD><EFBFBD>ģʽ
|
||
//APP<50><50><EFBFBD>Ʊ<EFBFBD>־λ<D6BE><CEBB>1<EFBFBD><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־λ<D6BE><CEBB>0
|
||
PS2_ON_Flag=0,Remote_ON_Flag=0,APP_ON_Flag=1,CAN_ON_Flag=0,Usart1_ON_Flag=0,Usart5_ON_Flag=0;
|
||
Last_Usart_Receive=Usart_Receive;
|
||
|
||
if(Usart_Receive==0x4B)
|
||
//Enter the APP steering control interface
|
||
//<2F><><EFBFBD><EFBFBD>APPת<50><D7AA><EFBFBD><EFBFBD>ƽ<EFBFBD><C6BD><EFBFBD>
|
||
Turn_Flag=1;
|
||
else if(Usart_Receive==0x49||Usart_Receive==0x4A)
|
||
// Enter the APP direction control interface
|
||
//<2F><><EFBFBD><EFBFBD>APP<50><50><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƽ<EFBFBD><C6BD><EFBFBD>
|
||
Turn_Flag=0;
|
||
|
||
if(Turn_Flag==0)
|
||
{
|
||
//App rocker control interface command
|
||
//APPҡ<50>˿<EFBFBD><CBBF>ƽ<EFBFBD><C6BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
if(Usart_Receive>=0x41&&Usart_Receive<=0x48)
|
||
{
|
||
Flag_Direction=Usart_Receive-0x40;
|
||
}
|
||
else if(Usart_Receive<=8)
|
||
{
|
||
Flag_Direction=Usart_Receive;
|
||
}
|
||
else Flag_Direction=0;
|
||
}
|
||
else if(Turn_Flag==1)
|
||
{
|
||
//APP steering control interface command
|
||
//APPת<50><D7AA><EFBFBD><EFBFBD>ƽ<EFBFBD><C6BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
if (Usart_Receive==0x43) Flag_Left=0,Flag_Right=1; //Right rotation //<2F><><EFBFBD><EFBFBD>ת
|
||
else if(Usart_Receive==0x47) Flag_Left=1,Flag_Right=0; //Left rotation //<2F><><EFBFBD><EFBFBD>ת
|
||
else Flag_Left=0,Flag_Right=0;
|
||
if (Usart_Receive==0x41||Usart_Receive==0x45) Flag_Direction=Usart_Receive-0x40;
|
||
else Flag_Direction=0;
|
||
}
|
||
if(Usart_Receive==0x58) RC_Velocity=RC_Velocity+100; //Accelerate the keys, +100mm/s //<2F><><EFBFBD>ٰ<EFBFBD><D9B0><EFBFBD><EFBFBD><EFBFBD>+100mm/s
|
||
if(Usart_Receive==0x59) RC_Velocity=RC_Velocity-100; //Slow down buttons, -100mm/s //<2F><><EFBFBD>ٰ<EFBFBD><D9B0><EFBFBD><EFBFBD><EFBFBD>-100mm/s
|
||
|
||
// The following is the communication with the APP debugging interface
|
||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>APP<50><50><EFBFBD>Խ<EFBFBD><D4BD><EFBFBD>ͨѶ
|
||
if(Usart_Receive==0x7B) Flag_PID=1; //The start bit of the APP parameter instruction //APP<50><50><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD>ʼλ
|
||
if(Usart_Receive==0x7D) Flag_PID=2; //The APP parameter instruction stops the bit //APP<50><50><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>ֹͣλ
|
||
|
||
if(Flag_PID==1) //Collect data //<2F>ɼ<EFBFBD><C9BC><EFBFBD><EFBFBD><EFBFBD>
|
||
{
|
||
Receive[i]=Usart_Receive;
|
||
i++;
|
||
}
|
||
if(Flag_PID==2) //Analyze the data //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
{
|
||
if(Receive[3]==0x50) PID_Send=1;
|
||
else if(Receive[1]!=0x23)
|
||
{
|
||
for(j=i;j>=4;j--)
|
||
{
|
||
Data+=(Receive[j-1]-48)*pow(10,i-j);
|
||
}
|
||
switch(Receive[1])
|
||
{
|
||
case 0x30: RC_Velocity=Data;break;
|
||
case 0x31: Velocity_KP=Data;break;
|
||
case 0x32: Velocity_KI=Data;break;
|
||
case 0x33: break;
|
||
case 0x34: break;
|
||
case 0x35: break;
|
||
case 0x36: break;
|
||
case 0x37: break;
|
||
case 0x38: break;
|
||
}
|
||
}
|
||
//Relevant flag position is cleared
|
||
//<2F><>ر<EFBFBD>־λ<D6BE><CEBB><EFBFBD><EFBFBD>
|
||
Flag_PID=0;
|
||
i=0;
|
||
j=0;
|
||
Data=0;
|
||
memset(Receive, 0, sizeof(u8)*50); //Clear the array to zero//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
}
|
||
if(RC_Velocity<0) RC_Velocity=0;
|
||
}
|
||
return 0;
|
||
}
|
||
/**************************************************************************
|
||
Function: Serial port 3 receives interrupted
|
||
Input : none
|
||
Output : none
|
||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>3<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
||
<EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD> ֵ<><D6B5><EFBFBD><EFBFBD>
|
||
**************************************************************************/
|
||
float test_movz = 0;
|
||
int USART3_IRQHandler(void)
|
||
{
|
||
static u8 Count=0;
|
||
u8 Usart_Receive;
|
||
|
||
if(USART_GetITStatus(USART3, USART_IT_RXNE) != RESET) //Check if data is received //<2F>ж<EFBFBD><D0B6>Ƿ<EFBFBD><C7B7><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD>
|
||
{
|
||
Usart_Receive = USART_ReceiveData(USART3);//Read the data //<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
|
||
if(Time_count<CONTROL_STARTUP_DELAY_COUNT)
|
||
// Data is not processed until the 2 second startup delay expires.
|
||
//<2F><><EFBFBD><EFBFBD>2<EFBFBD><32>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
return 0;
|
||
|
||
//Fill the array with serial data
|
||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
Receive_Data.buffer[Count]=Usart_Receive;
|
||
|
||
// Ensure that the first data in the array is FRAME_HEADER
|
||
//ȷ<><C8B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ΪFRAME_HEADER
|
||
if(Usart_Receive == FRAME_HEADER||Count>0)
|
||
Count++;
|
||
else
|
||
Count=0;
|
||
|
||
if (Count == 11) //Verify the length of the packet //<2F><>֤<EFBFBD><D6A4><EFBFBD>ݰ<EFBFBD><DDB0>ij<EFBFBD><C4B3><EFBFBD>
|
||
{
|
||
Count=0; //Prepare for the serial port data to be refill into the array //Ϊ<><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><D7BC>
|
||
if(Receive_Data.buffer[10] == FRAME_TAIL) //Verify the frame tail of the packet //<2F><>֤<EFBFBD><D6A4><EFBFBD>ݰ<EFBFBD><DDB0><EFBFBD>֡β
|
||
{
|
||
//Data exclusionary or bit check calculation, mode 0 is sent data check
|
||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λУ<CEBB><D0A3><EFBFBD><EFBFBD>㣬ģʽ0<CABD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD><D0A3>
|
||
if(Receive_Data.buffer[9] ==Check_Sum(9,0))
|
||
{
|
||
float Vz;
|
||
//All modes flag position 0, USART3 control mode
|
||
//<2F><><EFBFBD><EFBFBD>ģʽ<C4A3><CABD>־λ<D6BE><CEBB>0<EFBFBD><30>ΪUsart3<74><33><EFBFBD><EFBFBD>ģʽ
|
||
PS2_ON_Flag=0;
|
||
Remote_ON_Flag=0;
|
||
APP_ON_Flag=0;
|
||
CAN_ON_Flag=0;
|
||
Usart1_ON_Flag=0;
|
||
Usart5_ON_Flag=0;
|
||
command_lost_count=0; //CAN/<2F><><EFBFBD>ڿ<EFBFBD><DABF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EEB6AA><CAA7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
|
||
//Calculate the target speed of three axis from serial data, unit m/s
|
||
//<2F>Ӵ<EFBFBD><D3B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD>ٶȣ<D9B6> <20><>λm/s
|
||
Move_X=XYZ_Target_Speed_transition(Receive_Data.buffer[3],Receive_Data.buffer[4]);
|
||
Move_Y=XYZ_Target_Speed_transition(Receive_Data.buffer[5],Receive_Data.buffer[6]);
|
||
Vz =XYZ_Target_Speed_transition(Receive_Data.buffer[7],Receive_Data.buffer[8]);
|
||
test_movz = Vz;
|
||
// Ackermann: pass the raw rotation speed wz [rad/s] straight
|
||
// through; Drive_Motor derives curvature kappa = wz/v itself.
|
||
Move_Z=Vz; }
|
||
|
||
}
|
||
}
|
||
}
|
||
return 0;
|
||
}
|
||
|
||
/**************************************************************************
|
||
Function: Serial port 5 receives interrupted
|
||
Input : none
|
||
Output : none
|
||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>5<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
||
<EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD> ֵ<><D6B5><EFBFBD><EFBFBD>
|
||
**************************************************************************/
|
||
int UART5_IRQHandler(void)
|
||
{
|
||
static u8 Count=0;
|
||
u8 Usart_Receive;
|
||
|
||
if(USART_GetITStatus(UART5, USART_IT_RXNE) != RESET) //Check if data is received //<2F>ж<EFBFBD><D0B6>Ƿ<EFBFBD><C7B7><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD>
|
||
{
|
||
Usart_Receive = USART_ReceiveData(UART5);//Read the data //<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
|
||
if(Time_count<CONTROL_STARTUP_DELAY_COUNT)
|
||
// Data is not processed until 10 seconds after startup
|
||
//<2F><><EFBFBD><EFBFBD>10<31><30>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
return 0;
|
||
|
||
//Fill the array with serial data
|
||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
Receive_Data.buffer[Count]=Usart_Receive;
|
||
|
||
// Ensure that the first data in the array is FRAME_HEADER
|
||
//ȷ<><C8B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ΪFRAME_HEADER
|
||
if(Usart_Receive == FRAME_HEADER||Count>0)
|
||
Count++;
|
||
else
|
||
Count=0;
|
||
|
||
if (Count == 11) //Verify the length of the packet //<2F><>֤<EFBFBD><D6A4><EFBFBD>ݰ<EFBFBD><DDB0>ij<EFBFBD><C4B3><EFBFBD>
|
||
{
|
||
Count=0; //Prepare for the serial port data to be refill into the array //Ϊ<><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><D7BC>
|
||
if(Receive_Data.buffer[10] == FRAME_TAIL) //Verify the frame tail of the packet //<2F><>֤<EFBFBD><D6A4><EFBFBD>ݰ<EFBFBD><DDB0><EFBFBD>֡β
|
||
{
|
||
//Data exclusionary or bit check calculation, mode 0 is sent data check
|
||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λУ<CEBB><D0A3><EFBFBD><EFBFBD>㣬ģʽ0<CABD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD><D0A3>
|
||
if(Receive_Data.buffer[9] ==Check_Sum(9,0))
|
||
{
|
||
float Vz;
|
||
//All modes flag position 0, USART3 control mode
|
||
//<2F><><EFBFBD><EFBFBD>ģʽ<C4A3><CABD>־λ<D6BE><CEBB>0<EFBFBD><30>ΪUsart5<74><35><EFBFBD><EFBFBD>ģʽ
|
||
PS2_ON_Flag=0;
|
||
Remote_ON_Flag=0;
|
||
APP_ON_Flag=0;
|
||
CAN_ON_Flag=0;
|
||
Usart5_ON_Flag=0;
|
||
command_lost_count=0; //CAN/<2F><><EFBFBD>ڿ<EFBFBD><DABF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EEB6AA><CAA7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
|
||
//Calculate the target speed of three axis from serial data, unit m/s
|
||
//<2F>Ӵ<EFBFBD><D3B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD>ٶȣ<D9B6> <20><>λm/s
|
||
Move_X=XYZ_Target_Speed_transition(Receive_Data.buffer[3],Receive_Data.buffer[4]);
|
||
Move_Y=XYZ_Target_Speed_transition(Receive_Data.buffer[5],Receive_Data.buffer[6]);
|
||
Vz =XYZ_Target_Speed_transition(Receive_Data.buffer[7],Receive_Data.buffer[8]);
|
||
// Ackermann: pass the raw rotation speed wz [rad/s] straight
|
||
// through; Drive_Motor derives curvature kappa = wz/v itself.
|
||
Move_Z=Vz; }
|
||
|
||
}
|
||
}
|
||
}
|
||
return 0;
|
||
}
|
||
/**************************************************************************
|
||
Function: After the top 8 and low 8 figures are integrated into a short type data, the unit reduction is converted
|
||
Input : 8 bits high, 8 bits low
|
||
Output : The target velocity of the robot on the X/Y/Z axis
|
||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><EFBFBD>ǰ<EFBFBD><EFBFBD><EFBFBD>ٶ<EFBFBD>Vx<EFBFBD><EFBFBD>Ŀ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٶ<EFBFBD>Vz<EFBFBD><EFBFBD>ת<EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><EFBFBD>ת<EFBFBD><EFBFBD>
|
||
<EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><EFBFBD>ǰ<EFBFBD><EFBFBD><EFBFBD>ٶ<EFBFBD>Vx<EFBFBD><EFBFBD>Ŀ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٶ<EFBFBD>Vz<EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><EFBFBD>m/s<><73>rad/s
|
||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD> ֵ<><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD><D0A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0>ת<EFBFBD>ǣ<EFBFBD><C7A3><EFBFBD>λ<EFBFBD><CEBB>rad
|
||
**************************************************************************/
|
||
|
||
float test_z=0;
|
||
float Vz_to_Akm_Angle(float Vx, float Vz)
|
||
{
|
||
float R, CenterAngle;
|
||
|
||
/* Move_Z is the vehicle center steering angle in radians. */
|
||
if(Vz!=0 && Vx!=0)
|
||
{
|
||
/* R is the turning radius of the vehicle centerline. */
|
||
/* Vx sets radius magnitude only; Vz owns the steering direction. */
|
||
R=float_abs(Vx)/float_abs(Vz);
|
||
CenterAngle=(Vz >= 0.0f ? 1.0f : -1.0f) * atan(Axle_spacing/R);
|
||
}
|
||
else
|
||
{
|
||
CenterAngle=0;
|
||
}
|
||
test_z = CenterAngle;
|
||
return CenterAngle;
|
||
}
|
||
/**************************************************************************
|
||
Function: After the top 8 and low 8 figures are integrated into a short type data, the unit reduction is converted
|
||
Input : 8 bits high, 8 bits low
|
||
Output : The target velocity of the robot on the X/Y/Z axis
|
||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĸ<EFBFBD>8λ<EFBFBD>͵<EFBFBD>8λ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϳ<EFBFBD>һ<EFBFBD><EFBFBD>short<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݺ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><EFBFBD>ԭ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
<EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>8λ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>8λ
|
||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD> ֵ<><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>X/Y/Z<><5A><EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD>ٶ<EFBFBD>
|
||
**************************************************************************/
|
||
float XYZ_Target_Speed_transition(u8 High,u8 Low)
|
||
{
|
||
//Data conversion intermediate variable
|
||
//<2F><><EFBFBD><EFBFBD>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD>м<EFBFBD><D0BC><EFBFBD><EFBFBD>
|
||
short transition;
|
||
|
||
//<2F><><EFBFBD><EFBFBD>8λ<38>͵<EFBFBD>8λ<38><CEBB><EFBFBD>ϳ<EFBFBD>һ<EFBFBD><D2BB>16λ<36><CEBB>short<72><74><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
//The high 8 and low 8 bits are integrated into a 16-bit short data
|
||
transition=((High<<8)+Low);
|
||
return
|
||
transition/1000+(transition%1000)*0.001; //Unit conversion, mm/s->m/s //<2F><>λת<CEBB><D7AA>, mm/s->m/s
|
||
}
|
||
/**************************************************************************
|
||
Function: Serial port 1 sends data
|
||
Input : The data to send
|
||
Output : none
|
||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
<EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD> ֵ<><D6B5><EFBFBD><EFBFBD>
|
||
**************************************************************************/
|
||
void usart1_send(u8 data)
|
||
{
|
||
USART1->DR = data;
|
||
while((USART1->SR&0x40)==0);
|
||
}
|
||
/**************************************************************************
|
||
Function: Serial port 2 sends data
|
||
Input : The data to send
|
||
Output : none
|
||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>2<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
<EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD> ֵ<><D6B5><EFBFBD><EFBFBD>
|
||
**************************************************************************/
|
||
void usart2_send(u8 data)
|
||
{
|
||
USART2->DR = data;
|
||
while((USART2->SR&0x40)==0);
|
||
}
|
||
/**************************************************************************
|
||
Function: Serial port 3 sends data
|
||
Input : The data to send
|
||
Output : none
|
||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>3<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
<EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD> ֵ<><D6B5><EFBFBD><EFBFBD>
|
||
**************************************************************************/
|
||
void usart3_send(u8 data)
|
||
{
|
||
USART3->DR = data;
|
||
while((USART3->SR&0x40)==0);
|
||
}
|
||
|
||
/**************************************************************************
|
||
Function: Serial port 5 sends data
|
||
Input : The data to send
|
||
Output : none
|
||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>5<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
<EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD> ֵ<><D6B5><EFBFBD><EFBFBD>
|
||
**************************************************************************/
|
||
void usart5_send(u8 data)
|
||
{
|
||
UART5->DR = data;
|
||
while((UART5->SR&0x40)==0);
|
||
}
|
||
/**************************************************************************
|
||
Function: Calculates the check bits of data to be sent/received
|
||
Input : Count_Number: The first few digits of a check; Mode: 0-Verify the received data, 1-Validate the sent data
|
||
Output : Check result
|
||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>/<2F><><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD><D0A3><EFBFBD><EFBFBD>
|
||
<EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Count_Number<EFBFBD><EFBFBD>У<EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><EFBFBD>λ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Mode<EFBFBD><EFBFBD>0-<2D>Խ<EFBFBD><D4BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݽ<EFBFBD><DDBD><EFBFBD>У<EFBFBD>飬1-<2D>Է<EFBFBD><D4B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݽ<EFBFBD><DDBD><EFBFBD>У<EFBFBD><D0A3>
|
||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD> ֵ<><D6B5>У<EFBFBD><D0A3><EFBFBD><EFBFBD>
|
||
**************************************************************************/
|
||
u8 Check_Sum(unsigned char Count_Number,unsigned char Mode)
|
||
{
|
||
unsigned char check_sum=0,k;
|
||
|
||
//Validate the data to be sent
|
||
//<2F><>Ҫ<EFBFBD><D2AA><EFBFBD>͵<EFBFBD><CDB5><EFBFBD><EFBFBD>ݽ<EFBFBD><DDBD><EFBFBD>У<EFBFBD><D0A3>
|
||
if(Mode==1)
|
||
for(k=0;k<Count_Number;k++)
|
||
{
|
||
check_sum=check_sum^Send_Data.buffer[k];
|
||
}
|
||
|
||
//Verify the data received
|
||
//<2F>Խ<EFBFBD><D4BD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݽ<EFBFBD><DDBD><EFBFBD>У<EFBFBD><D0A3>
|
||
if(Mode==0)
|
||
for(k=0;k<Count_Number;k++)
|
||
{
|
||
check_sum=check_sum^Receive_Data.buffer[k];
|
||
}
|
||
return check_sum;
|
||
}
|
||
|
||
|
||
|