修改解决多个帧头以及错误处理
This commit is contained in:
6
.vscode/settings.json
vendored
Normal file
6
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"files.associations": {
|
||||||
|
"UART.C": "cpp",
|
||||||
|
"CAN.C": "cpp"
|
||||||
|
}
|
||||||
|
}
|
||||||
22
CAN.C
22
CAN.C
@@ -150,19 +150,15 @@ void CAN_vInit(void)
|
|||||||
|
|
||||||
/// General Configuration of the Node 0:
|
/// General Configuration of the Node 0:
|
||||||
/// - set INIT and CCE
|
/// - set INIT and CCE
|
||||||
/// - enable interrupt generation upon a change of BOFF or EWARN or upon a
|
|
||||||
/// set of LLE, LOE or INIT
|
|
||||||
/// - alert interrupt node pointer: MultiCAN SRN 0
|
|
||||||
|
|
||||||
//-----------CAN_NCR0 = 0x00000049-------------------------------------
|
//-----------CAN_NCR0 = 0x00000041-------------------------------------
|
||||||
|
|
||||||
CAN_vWriteCANAddress(CAN_NCR0); // Addressing CAN_NCR0
|
CAN_vWriteCANAddress(CAN_NCR0); // Addressing CAN_NCR0
|
||||||
CAN_DATA0 = 0x49; // load NODE 0 control register[7-0]
|
CAN_DATA0 = 0x41; // load NODE 0 control register[7-0]
|
||||||
CAN_vWriteEN(D0_VALID+ADR_INC); // Data0 is Valid for transmission and
|
CAN_vWriteEN(D0_VALID+ADR_INC); // Data0 is Valid for transmission and
|
||||||
// Write is EnabledCAN Address pointing
|
// Write is EnabledCAN Address pointing
|
||||||
// to the CAN_NSR0.
|
// to the CAN_NSR0.
|
||||||
|
|
||||||
|
|
||||||
// CAN Address pointing to the CAN_NIPR0
|
// CAN Address pointing to the CAN_NIPR0
|
||||||
CAN_ADCON = ADR_INC; // Auto Increment the current address(+1)
|
CAN_ADCON = ADR_INC; // Auto Increment the current address(+1)
|
||||||
|
|
||||||
@@ -197,16 +193,16 @@ void CAN_vInit(void)
|
|||||||
|
|
||||||
/// Configuration of the Node 0 Baud Rate:
|
/// Configuration of the Node 0 Baud Rate:
|
||||||
/// - required baud rate = 250.000 kbaud
|
/// - required baud rate = 250.000 kbaud
|
||||||
/// - real baud rate = 250.000 kbaud
|
/// - real baud rate = 252.632 kbaud
|
||||||
/// - sample point = 75.00 %
|
/// - sample point = 80.00 %
|
||||||
/// - there are 11 time quanta before sample point
|
/// - there are 7 time quanta before sample point
|
||||||
/// - there are 4 time quanta after sample point
|
/// - there are 2 time quanta after sample point
|
||||||
/// - the (re)synchronization jump width is 2 time quanta
|
/// - the (re)synchronization jump width is 2 time quanta
|
||||||
|
|
||||||
//-----------CAN_NBTR0 = 0x00003A4B-------------------------------------
|
//-----------CAN_NBTR0 = 0x00001652-------------------------------------
|
||||||
|
|
||||||
CAN_DATA0 = 0x4B; // load NBTR0_SJW, BRP
|
CAN_DATA0 = 0x52; // load NBTR0_SJW, BRP
|
||||||
CAN_DATA1 = 0x3A; // load NBTR0_DIV8, TSEG2, TSEG1
|
CAN_DATA1 = 0x16; // load NBTR0_DIV8, TSEG2, TSEG1
|
||||||
CAN_vWriteEN(D0_VALID+D1_VALID+ADR_INC); // Data0, 1 are valid for
|
CAN_vWriteEN(D0_VALID+D1_VALID+ADR_INC); // Data0, 1 are valid for
|
||||||
// transmission and Write is
|
// transmission and Write is
|
||||||
// Enabled with Auto
|
// Enabled with Auto
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -320,7 +320,7 @@
|
|||||||
<tvExp>0</tvExp>
|
<tvExp>0</tvExp>
|
||||||
<tvExpOptDlg>0</tvExpOptDlg>
|
<tvExpOptDlg>0</tvExpOptDlg>
|
||||||
<bDave2>0</bDave2>
|
<bDave2>0</bDave2>
|
||||||
<PathWithFileName>..\20250115_IO采集\UART.C</PathWithFileName>
|
<PathWithFileName>..\..\20250115_IO采集\UART.C</PathWithFileName>
|
||||||
<FilenameWithoutPath>UART.C</FilenameWithoutPath>
|
<FilenameWithoutPath>UART.C</FilenameWithoutPath>
|
||||||
<RteFlg>0</RteFlg>
|
<RteFlg>0</RteFlg>
|
||||||
<bShared>0</bShared>
|
<bShared>0</bShared>
|
||||||
|
|||||||
@@ -414,7 +414,7 @@
|
|||||||
<File>
|
<File>
|
||||||
<FileName>UART.C</FileName>
|
<FileName>UART.C</FileName>
|
||||||
<FileType>1</FileType>
|
<FileType>1</FileType>
|
||||||
<FilePath>..\20250115_IO采集\UART.C</FilePath>
|
<FilePath>..\..\20250115_IO采集\UART.C</FilePath>
|
||||||
</File>
|
</File>
|
||||||
</Files>
|
</Files>
|
||||||
</Group>
|
</Group>
|
||||||
|
|||||||
54
UART.C
54
UART.C
@@ -211,7 +211,10 @@ void UART_viIsr(void) interrupt UARTINT
|
|||||||
static uint8_t state = 0;
|
static uint8_t state = 0;
|
||||||
static uint8_t receive = 0;
|
static uint8_t receive = 0;
|
||||||
static uint8_t sbus_buff[25];
|
static uint8_t sbus_buff[25];
|
||||||
SBusData *tmp_sbus_data;
|
uint8_t i = 0;
|
||||||
|
uint8_t start_index = 0;
|
||||||
|
|
||||||
|
// SBusData *tmp_sbus_data;
|
||||||
// USER CODE END
|
// USER CODE END
|
||||||
SFR_PAGE(_su0, SST0); // switch to page 0
|
SFR_PAGE(_su0, SST0); // switch to page 0
|
||||||
if (TI)
|
if (TI)
|
||||||
@@ -249,22 +252,39 @@ void UART_viIsr(void) interrupt UARTINT
|
|||||||
case 1:
|
case 1:
|
||||||
if(cnt_sbus >= 24)
|
if(cnt_sbus >= 24)
|
||||||
{
|
{
|
||||||
if(0x0 == char_data[0])
|
if(0x0 == char_data[0])
|
||||||
{
|
{
|
||||||
cnt_sbus = 0;
|
cnt_sbus = 0;
|
||||||
receive = 0;
|
receive = 0;
|
||||||
sbus_buff[cnt_sbus] = char_data[0];
|
sbus_buff[cnt_sbus] = char_data[0];
|
||||||
state = 0;
|
state = 0;
|
||||||
tmp_sbus_data = parseSBusData(sbus_buff);
|
parseSBusData(sbus_buff);
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
else if( (0x0f == char_data[0]) && (10 != cnt_sbus) )//<2F><>Ϊ<EFBFBD><CEAA>10<31><30><EFBFBD>ֽ<EFBFBD>Ϊ0x0F<30><46><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD>Բ<EFBFBD><D4B2><EFBFBD><EFBFBD><EFBFBD>0
|
{
|
||||||
{
|
sbus_buff[cnt_sbus] = char_data[0];
|
||||||
receive = 0;
|
for (i = 1; i < cnt_sbus; i++)
|
||||||
cnt_sbus = 0;
|
{
|
||||||
sbus_buff[cnt_sbus] = char_data[0];
|
if (sbus_buff[i] == 0x0f)
|
||||||
cnt_sbus++;
|
{
|
||||||
state = 1;
|
start_index = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* we found a second start marker */
|
||||||
|
if (start_index != 0)
|
||||||
|
{
|
||||||
|
/* shift everything in the buffer and reset the state machine */
|
||||||
|
for (i = 0; i < cnt_sbus - start_index; i++) {
|
||||||
|
sbus_buff[i] = sbus_buff[i + start_index];
|
||||||
|
}
|
||||||
|
|
||||||
|
cnt_sbus -= start_index;
|
||||||
|
state = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
261
UART1.C
261
UART1.C
@@ -1,261 +0,0 @@
|
|||||||
//****************************************************************************
|
|
||||||
// @Module UART1 (Serial Interface)
|
|
||||||
// @Filename UART1.C
|
|
||||||
// @Project CL2.0.dav
|
|
||||||
//----------------------------------------------------------------------------
|
|
||||||
// @Controller Infineon XC886CLM-8FF
|
|
||||||
//
|
|
||||||
// @Compiler Keil
|
|
||||||
//
|
|
||||||
// @Codegenerator 1.3
|
|
||||||
//
|
|
||||||
// @Description: This file contains functions that use the UART1 module.
|
|
||||||
//
|
|
||||||
//----------------------------------------------------------------------------
|
|
||||||
// @Date 2024/10/31 19:17:02
|
|
||||||
//
|
|
||||||
//****************************************************************************
|
|
||||||
|
|
||||||
// USER CODE BEGIN (UART1_General,1)
|
|
||||||
|
|
||||||
// USER CODE END
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//****************************************************************************
|
|
||||||
// @Project Includes
|
|
||||||
//****************************************************************************
|
|
||||||
|
|
||||||
#include "MAIN.H"
|
|
||||||
|
|
||||||
// USER CODE BEGIN (UART1_General,2)
|
|
||||||
|
|
||||||
// USER CODE END
|
|
||||||
|
|
||||||
|
|
||||||
//****************************************************************************
|
|
||||||
// @Macros
|
|
||||||
//****************************************************************************
|
|
||||||
|
|
||||||
// USER CODE BEGIN (UART1_General,3)
|
|
||||||
|
|
||||||
// USER CODE END
|
|
||||||
|
|
||||||
|
|
||||||
//****************************************************************************
|
|
||||||
// @Defines
|
|
||||||
//****************************************************************************
|
|
||||||
|
|
||||||
// USER CODE BEGIN (UART1_General,4)
|
|
||||||
|
|
||||||
// USER CODE END
|
|
||||||
|
|
||||||
|
|
||||||
//****************************************************************************
|
|
||||||
// @Typedefs
|
|
||||||
//****************************************************************************
|
|
||||||
|
|
||||||
// USER CODE BEGIN (UART1_General,5)
|
|
||||||
|
|
||||||
// USER CODE END
|
|
||||||
|
|
||||||
|
|
||||||
//****************************************************************************
|
|
||||||
// @Imported Global Variables
|
|
||||||
//****************************************************************************
|
|
||||||
|
|
||||||
// USER CODE BEGIN (UART1_General,6)
|
|
||||||
|
|
||||||
// USER CODE END
|
|
||||||
|
|
||||||
|
|
||||||
//****************************************************************************
|
|
||||||
// @Global Variables
|
|
||||||
//****************************************************************************
|
|
||||||
|
|
||||||
// USER CODE BEGIN (UART1_General,7)
|
|
||||||
|
|
||||||
// USER CODE END
|
|
||||||
|
|
||||||
|
|
||||||
//****************************************************************************
|
|
||||||
// @External Prototypes
|
|
||||||
//****************************************************************************
|
|
||||||
|
|
||||||
// USER CODE BEGIN (UART1_General,8)
|
|
||||||
|
|
||||||
// USER CODE END
|
|
||||||
|
|
||||||
|
|
||||||
//****************************************************************************
|
|
||||||
// @Prototypes Of Local Functions
|
|
||||||
//****************************************************************************
|
|
||||||
|
|
||||||
// USER CODE BEGIN (UART1_General,9)
|
|
||||||
|
|
||||||
// USER CODE END
|
|
||||||
|
|
||||||
|
|
||||||
//****************************************************************************
|
|
||||||
// @Function void UART1_vInit(void)
|
|
||||||
//
|
|
||||||
//----------------------------------------------------------------------------
|
|
||||||
// @Description This is the initialization function of the UART1 function
|
|
||||||
// library. It is assumed that the SFRs used by this library
|
|
||||||
// are in their reset state.
|
|
||||||
//
|
|
||||||
// The following SFR fields will be initialized:
|
|
||||||
// - register SCON
|
|
||||||
// - bits SMOD and EX2
|
|
||||||
//
|
|
||||||
//----------------------------------------------------------------------------
|
|
||||||
// @Returnvalue None
|
|
||||||
//
|
|
||||||
//----------------------------------------------------------------------------
|
|
||||||
// @Parameters None
|
|
||||||
//
|
|
||||||
//----------------------------------------------------------------------------
|
|
||||||
// @Date 2024/10/31
|
|
||||||
//
|
|
||||||
//****************************************************************************
|
|
||||||
|
|
||||||
// USER CODE BEGIN (UART1_Init,1)
|
|
||||||
|
|
||||||
// USER CODE END
|
|
||||||
|
|
||||||
void UART1_vInit(void)
|
|
||||||
{
|
|
||||||
// USER CODE BEGIN (UART1_Init,2)
|
|
||||||
|
|
||||||
// USER CODE END
|
|
||||||
|
|
||||||
/// -----------------------------------------------------------------------
|
|
||||||
/// UART1 settings
|
|
||||||
/// -----------------------------------------------------------------------
|
|
||||||
/// Pin TXD1_1 (P3.1) is selected for transmission
|
|
||||||
/// Pin RXD1_1 (P3.2) is selected for reception
|
|
||||||
/// Receiver enabled
|
|
||||||
/// UART1 interrupt is enabled
|
|
||||||
/// Ignore Normal divider overflow interrupt
|
|
||||||
/// Mode 1: 8-bit data, 1 start bit, 1 stop bit, variable baud rate
|
|
||||||
/// Receiver interrupt flag RI_1 will only be activated if a valid stop
|
|
||||||
/// bit was received
|
|
||||||
/// BRG is selected for baudrate generation
|
|
||||||
|
|
||||||
SFR_PAGE(_pp2, noSST); // switch to page 2 without saving
|
|
||||||
P3_ALTSEL0 |= (ubyte)0x02; // configure alternate function register 0
|
|
||||||
P3_ALTSEL1 |= (ubyte)0x02; // configure alternate function register 1
|
|
||||||
SFR_PAGE(_pp0, noSST); // switch to page 0 without saving
|
|
||||||
P3_DIR |= (ubyte)0x02; // set output direction
|
|
||||||
|
|
||||||
|
|
||||||
SFR_PAGE(_su3, noSST); // switch to page 3 without saving
|
|
||||||
MODPISEL1 |= (ubyte)0x08; // configure peripheral input select register
|
|
||||||
SFR_PAGE(_su0, noSST); // switch to page 0 without saving
|
|
||||||
|
|
||||||
SET_RMAP();
|
|
||||||
|
|
||||||
UART1_BCON = 0x00; // reset baudrate timer/reload register
|
|
||||||
UART1_SCON = 0x50; // load serial channel control register
|
|
||||||
|
|
||||||
/// -----------------------------------------------------------------------
|
|
||||||
/// Baudrate generator settings
|
|
||||||
/// -----------------------------------------------------------------------
|
|
||||||
/// input clock = fPCLK
|
|
||||||
/// Fractional divider is disabled
|
|
||||||
/// baudrate = 9.6154 kbaud
|
|
||||||
|
|
||||||
UART1_BG = 0x9B; // load baudrate timer/reload register
|
|
||||||
UART1_BCON |= 0x01; // load baud rate control register
|
|
||||||
|
|
||||||
|
|
||||||
RESET_RMAP();
|
|
||||||
|
|
||||||
|
|
||||||
// USER CODE BEGIN (UART1_Init,3)
|
|
||||||
|
|
||||||
// USER CODE END
|
|
||||||
|
|
||||||
} // End of function UART1_vInit
|
|
||||||
|
|
||||||
|
|
||||||
//****************************************************************************
|
|
||||||
// @Function ubyte UART1_ubGetData8(void)
|
|
||||||
//
|
|
||||||
//----------------------------------------------------------------------------
|
|
||||||
// @Description This function returns the last received 8-bit data unit.
|
|
||||||
// Interrupt flag RI_1 will be cleared.
|
|
||||||
//
|
|
||||||
//----------------------------------------------------------------------------
|
|
||||||
// @Returnvalue received data unit
|
|
||||||
//
|
|
||||||
//----------------------------------------------------------------------------
|
|
||||||
// @Parameters None
|
|
||||||
//
|
|
||||||
//----------------------------------------------------------------------------
|
|
||||||
// @Date 2024/10/31
|
|
||||||
//
|
|
||||||
//****************************************************************************
|
|
||||||
|
|
||||||
ubyte UART1_ubGetData8(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
ubyte ubData;
|
|
||||||
|
|
||||||
_push_(SYSCON0); // push the current RMAP
|
|
||||||
SET_RMAP();
|
|
||||||
|
|
||||||
// Clear the receiver interrupt flag
|
|
||||||
UART1_SCON &= ~(ubyte)0x01;
|
|
||||||
|
|
||||||
|
|
||||||
// Read the received data bits 0..7
|
|
||||||
ubData = (ubyte)UART1_SBUF;
|
|
||||||
|
|
||||||
|
|
||||||
_pop_(SYSCON0); // restore the old RMAP
|
|
||||||
|
|
||||||
// Return the received data byte
|
|
||||||
return(ubData);
|
|
||||||
|
|
||||||
} // End of function UART1_ubGetData8
|
|
||||||
//****************************************************************************
|
|
||||||
// @Function void UART1_vSendData8(ubyte ubData)
|
|
||||||
//
|
|
||||||
//----------------------------------------------------------------------------
|
|
||||||
// @Description This function transmits an 8-bit data unit. At first
|
|
||||||
// interrupt flag TI_1 is cleared, then buffer SBUF is written.
|
|
||||||
//
|
|
||||||
//----------------------------------------------------------------------------
|
|
||||||
// @Returnvalue None
|
|
||||||
//
|
|
||||||
//----------------------------------------------------------------------------
|
|
||||||
// @Parameters ubData:
|
|
||||||
// data to be transmitted
|
|
||||||
//
|
|
||||||
//----------------------------------------------------------------------------
|
|
||||||
// @Date 2024/10/31
|
|
||||||
//
|
|
||||||
//****************************************************************************
|
|
||||||
|
|
||||||
void UART1_vSendData8(ubyte ubData)
|
|
||||||
{
|
|
||||||
|
|
||||||
_push_(SYSCON0); // push the current RMAP
|
|
||||||
SET_RMAP();
|
|
||||||
|
|
||||||
// Clear the transmitter interrupt flag
|
|
||||||
UART1_SCON &= ~(ubyte)0x02;
|
|
||||||
|
|
||||||
// Write the transmit data byte, this initiates the transmission.
|
|
||||||
UART1_SBUF = ubData;
|
|
||||||
|
|
||||||
_pop_(SYSCON0); // restore the old RMAP
|
|
||||||
|
|
||||||
} // End of function UART1_vSendData8
|
|
||||||
|
|
||||||
|
|
||||||
// USER CODE BEGIN (UART1_General,10)
|
|
||||||
|
|
||||||
// USER CODE END
|
|
||||||
|
|
||||||
153
UART1.H
153
UART1.H
@@ -1,153 +0,0 @@
|
|||||||
//****************************************************************************
|
|
||||||
// @Module UART1 (Serial Interface)
|
|
||||||
// @Filename UART1.H
|
|
||||||
// @Project CL2.0.dav
|
|
||||||
//----------------------------------------------------------------------------
|
|
||||||
// @Controller Infineon XC886CLM-8FF
|
|
||||||
//
|
|
||||||
// @Compiler Keil
|
|
||||||
//
|
|
||||||
// @Codegenerator 1.3
|
|
||||||
//
|
|
||||||
// @Description: This file contains all function prototypes and macros for
|
|
||||||
// the UART1 module.
|
|
||||||
//
|
|
||||||
//----------------------------------------------------------------------------
|
|
||||||
// @Date 2024/10/31 19:17:02
|
|
||||||
//
|
|
||||||
//****************************************************************************
|
|
||||||
|
|
||||||
// USER CODE BEGIN (UART1_Header,1)
|
|
||||||
|
|
||||||
// USER CODE END
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef _UART1_H_
|
|
||||||
#define _UART1_H_
|
|
||||||
|
|
||||||
//****************************************************************************
|
|
||||||
// @Project Includes
|
|
||||||
//****************************************************************************
|
|
||||||
|
|
||||||
// USER CODE BEGIN (UART1_Header,2)
|
|
||||||
|
|
||||||
// USER CODE END
|
|
||||||
|
|
||||||
|
|
||||||
//****************************************************************************
|
|
||||||
// @Macros
|
|
||||||
//****************************************************************************
|
|
||||||
|
|
||||||
// USER CODE BEGIN (UART1_Header,3)
|
|
||||||
|
|
||||||
// USER CODE END
|
|
||||||
|
|
||||||
|
|
||||||
//****************************************************************************
|
|
||||||
// @Defines
|
|
||||||
//****************************************************************************
|
|
||||||
|
|
||||||
// USER CODE BEGIN (UART1_Header,4)
|
|
||||||
|
|
||||||
// USER CODE END
|
|
||||||
|
|
||||||
|
|
||||||
//****************************************************************************
|
|
||||||
// @Typedefs
|
|
||||||
//****************************************************************************
|
|
||||||
|
|
||||||
// USER CODE BEGIN (UART1_Header,5)
|
|
||||||
|
|
||||||
// USER CODE END
|
|
||||||
|
|
||||||
|
|
||||||
//****************************************************************************
|
|
||||||
// @Imported Global Variables
|
|
||||||
//****************************************************************************
|
|
||||||
|
|
||||||
// USER CODE BEGIN (UART1_Header,6)
|
|
||||||
|
|
||||||
// USER CODE END
|
|
||||||
|
|
||||||
|
|
||||||
//****************************************************************************
|
|
||||||
// @Global Variables
|
|
||||||
//****************************************************************************
|
|
||||||
|
|
||||||
// USER CODE BEGIN (UART1_Header,7)
|
|
||||||
|
|
||||||
// USER CODE END
|
|
||||||
|
|
||||||
|
|
||||||
//****************************************************************************
|
|
||||||
// @Prototypes Of Global Functions
|
|
||||||
//****************************************************************************
|
|
||||||
|
|
||||||
void UART1_vInit(void);
|
|
||||||
ubyte UART1_ubGetData8(void);
|
|
||||||
void UART1_vSendData8(ubyte ubData);
|
|
||||||
|
|
||||||
// USER CODE BEGIN (UART1_Header,8)
|
|
||||||
|
|
||||||
// USER CODE END
|
|
||||||
|
|
||||||
|
|
||||||
//****************************************************************************
|
|
||||||
// @Macro UART1_vRxEnable()
|
|
||||||
//
|
|
||||||
//----------------------------------------------------------------------------
|
|
||||||
// @Description This macro releases the receive function of the UART1 by
|
|
||||||
// setting bit REN_1.
|
|
||||||
//
|
|
||||||
//----------------------------------------------------------------------------
|
|
||||||
// @Returnvalue None
|
|
||||||
//
|
|
||||||
//----------------------------------------------------------------------------
|
|
||||||
// @Parameters None
|
|
||||||
//
|
|
||||||
//----------------------------------------------------------------------------
|
|
||||||
// @Date 2024/10/31
|
|
||||||
//
|
|
||||||
//****************************************************************************
|
|
||||||
|
|
||||||
// RMAP should be set before calling this macro.
|
|
||||||
|
|
||||||
#define UART1_vRxEnable() REN_1 = 1
|
|
||||||
|
|
||||||
|
|
||||||
//****************************************************************************
|
|
||||||
// @Macro UART1_vRxDisable()
|
|
||||||
//
|
|
||||||
//----------------------------------------------------------------------------
|
|
||||||
// @Description This macro disables the receive function of the UART1 by
|
|
||||||
// clearing bit REN_1.
|
|
||||||
// Note: Any data that is currently being received is received
|
|
||||||
// to completion, including the setting of interrupt flag RI_1.
|
|
||||||
//
|
|
||||||
//----------------------------------------------------------------------------
|
|
||||||
// @Returnvalue None
|
|
||||||
//
|
|
||||||
//----------------------------------------------------------------------------
|
|
||||||
// @Parameters None
|
|
||||||
//
|
|
||||||
//----------------------------------------------------------------------------
|
|
||||||
// @Date 2024/10/31
|
|
||||||
//
|
|
||||||
//****************************************************************************
|
|
||||||
|
|
||||||
// RMAP should be set before calling this macro.
|
|
||||||
|
|
||||||
#define UART1_vRxDisable() REN_1 = 0
|
|
||||||
|
|
||||||
|
|
||||||
//****************************************************************************
|
|
||||||
// @Interrupt Vectors
|
|
||||||
//****************************************************************************
|
|
||||||
|
|
||||||
|
|
||||||
// USER CODE BEGIN (UART1_Header,9)
|
|
||||||
|
|
||||||
// USER CODE END
|
|
||||||
|
|
||||||
#endif // ifndef _UART1_H_
|
|
||||||
22
User.c
22
User.c
@@ -17,9 +17,6 @@ bit FlgOneTime = 0;
|
|||||||
ubyte uart2RxFlag = 0;
|
ubyte uart2RxFlag = 0;
|
||||||
uword RgCanPerid = 50;
|
uword RgCanPerid = 50;
|
||||||
|
|
||||||
ubyte can_error_cnt = 0;
|
|
||||||
ubyte can_error_flg = 0;
|
|
||||||
|
|
||||||
//PWM 20181227
|
//PWM 20181227
|
||||||
ubyte PwmH[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
|
ubyte PwmH[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
@@ -52,7 +49,7 @@ SBusData* parseSBusData(const uint8_t *input_data)
|
|||||||
sbus_data.channels[10] = (input_data[14] >> 6 | input_data[15] << 2 | input_data[15] << 10) & 0x07FF;
|
sbus_data.channels[10] = (input_data[14] >> 6 | input_data[15] << 2 | input_data[15] << 10) & 0x07FF;
|
||||||
sbus_data.channels[11] = (input_data[16] >> 1 | input_data[17] << 7) & 0x07FF;
|
sbus_data.channels[11] = (input_data[16] >> 1 | input_data[17] << 7) & 0x07FF;
|
||||||
sbus_data.channels[12] = (input_data[17] >> 4 | input_data[18] << 4) & 0x07FF;
|
sbus_data.channels[12] = (input_data[17] >> 4 | input_data[18] << 4) & 0x07FF;
|
||||||
sbus_data.channels[13] = (input_data[18] >> 7 | input_data[19] << 1 | input_data[20] << 9) & 0x07FF;
|
sbus_data.channels[13] = (input_data[18] >> 7 | input_data[19] << 1 | input_data[19] << 9) & 0x07FF;
|
||||||
sbus_data.channels[14] = (input_data[20] >> 2 | input_data[21] << 6) & 0x07FF;
|
sbus_data.channels[14] = (input_data[20] >> 2 | input_data[21] << 6) & 0x07FF;
|
||||||
sbus_data.channels[15] = (input_data[21] >> 5 | input_data[22] << 3) & 0x07FF;
|
sbus_data.channels[15] = (input_data[21] >> 5 | input_data[22] << 3) & 0x07FF;
|
||||||
|
|
||||||
@@ -355,6 +352,9 @@ void sbusCanDecode(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//CAN<41><4E><EFBFBD>ͽ<EFBFBD><CDBD><EFBFBD>
|
//CAN<41><4E><EFBFBD>ͽ<EFBFBD><CDBD><EFBFBD>
|
||||||
void CanRXTX(void)
|
void CanRXTX(void)
|
||||||
{
|
{
|
||||||
@@ -426,8 +426,8 @@ void CanRXTX(void)
|
|||||||
|
|
||||||
// sbus_temp[1] = 3;
|
// sbus_temp[1] = 3;
|
||||||
detectLedState(&blink_detector, sbus_temp[0], &sbus_temp[1]);
|
detectLedState(&blink_detector, sbus_temp[0], &sbus_temp[1]);
|
||||||
// UnRemoteControlOutput_2.bit_data.enable = blink_detector.current_state;//
|
UnRemoteControlOutput_2.bit_data.enable = blink_detector.current_state;//
|
||||||
// UnRemoteControlOutput_2.bit_data.reserve1 = sbus_temp[1];
|
UnRemoteControlOutput_2.bit_data.reserve1 = sbus_temp[1];
|
||||||
|
|
||||||
|
|
||||||
if( (MATCH_CMD == UnInfCan_1.ArrData.ArrRX[0][0]) || (CHANGE_CMD == UnInfCan_1.ArrData.ArrRX[0][0]) )//<2F><>Ƶ<EFBFBD><C6B5><EFBFBD><EFBFBD><EFBFBD>л<EFBFBD>
|
if( (MATCH_CMD == UnInfCan_1.ArrData.ArrRX[0][0]) || (CHANGE_CMD == UnInfCan_1.ArrData.ArrRX[0][0]) )//<2F><>Ƶ<EFBFBD><C6B5><EFBFBD><EFBFBD><EFBFBD>л<EFBFBD>
|
||||||
@@ -480,16 +480,6 @@ void CanRXTX(void)
|
|||||||
CanTransmit(DF_SwTx,(ubyte *)&UnRemoteControlOutput_1.arr[0]);
|
CanTransmit(DF_SwTx,(ubyte *)&UnRemoteControlOutput_1.arr[0]);
|
||||||
CanTransmit(DF_SwTx1,(ubyte *)&UnRemoteControlOutput_2.arr[0]);
|
CanTransmit(DF_SwTx1,(ubyte *)&UnRemoteControlOutput_2.arr[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if( (0x40 == can_error_cnt) || (0x80 == can_error_cnt) )//20250625<32>ж<EFBFBD><D0B6>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ߴ<EFBFBD><DFB4><EFBFBD>
|
|
||||||
{
|
|
||||||
can_error_flg = can_error_cnt;
|
|
||||||
CAN_vInit();
|
|
||||||
can_error_cnt = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user