在线时间3 小时
UID3948083
注册时间2023-11-17
NXP金币0
该用户从未签到
新手上路

- 积分
- 47
- 最后登录
- 2023-12-11
|
哪位大神知道为什么,串口第一次发送信息能正常返回,第二次发送就产生异常了。搞了一整天没搞出来。
/*==================================================================================================
* Project : RTD AUTOSAR 4.4
* Platform : CORTEXM
* Peripheral :
* Dependencies : none
*
* Autosar Version : 4.4.0
* Autosar Revision : ASR_REL_4_4_REV_0000
* Autosar Conf.Variant :
* SW Version : 1.0.0
* Build Version : S32K1_RTD_1_0_0_ASR_REL_4_4_REV_0000_20210810
*/
#include "Mcl.h"
#include "Mcu.h"
#include "Uart.h"
#include "Port.h"
#include "Dio.h"
#include "Platform.h"
#include "Lpuart_Uart_Ip_Irq.h"
#include "Lpuart_Uart_Ip.h"
//#include "Flexio_Uart_Ip_Irq.h"
//#include "check_example.h"
#include <string.h>
#define UART_LPUART_INTERNAL_CHANNEL 0U
#define WELCOME_MSG_1 "LED已点亮,灯光明亮啦!\r\n"
#define WELCOME_MSG_2 "LED已熄灭,一片宁静!\r\n"
#define WELCOME_MSG_3 "hello\r\n"
#define BUFFER_SIZE 50U
int flag = 1;
uint8 rxIndex = 0;
uint8 Rx_Buffer[BUFFER_SIZE];
uint8 Rx_Data[BUFFER_SIZE];
uint8 Response[BUFFER_SIZE];
volatile Uart_StatusType Uart_ReceiveStatus = UART_STATUS_TIMEOUT;
volatile Uart_StatusType Uart_TransmitStatus = UART_STATUS_TIMEOUT;
uint32 T_bytesRemaining;
uint32 T_timeout = 0xFFFFFF;
void TestDelay(uint32 delay);
void TestDelay(uint32 delay)
{
static volatile uint32 DelayTimer = 0;
while(DelayTimer<delay)
{
DelayTimer++;
}
DelayTimer=0;
}
boolean User_Str_Cmp(const uint8 * pBuffer1, const uint8 * pBuffer2, const uint32 length)
{
uint32 idx = 0;
for (idx = 0; idx < length; idx++)
{
if(pBuffer1[idx] != pBuffer2[idx])
{
return FALSE;
}
}
return TRUE;
}
void Lpuart_CallBack(const uint8 HwInstance,const Lpuart_Uart_Ip_EventType Event,void *UserData)
{
(void)UserData;
if(HwInstance == UART_LPUART_INTERNAL_CHANNEL)
{
switch(Event)
{
case LPUART_UART_IP_EVENT_RX_FULL:
if((Rx_Buffer[rxIndex] != '\n')&&(rxIndex != (BUFFER_SIZE -2U)))
{
rxIndex++;
Lpuart_Uart_Ip_SetRxBuffer(1,&Rx_Buffer[rxIndex],1U);
// Response[rxIndex] = rxIndex;
// flag = 0;
}
// RX_FULL_num++;
break;
case LPUART_UART_IP_EVENT_TX_EMPTY:
// TX_EMPTY_num++;
break;
case LPUART_UART_IP_EVENT_END_TRANSFER:
flag = 0;
break;
case LPUART_UART_IP_EVENT_ERROR:
// ERROR_num++;
break;
default :
break;
}
}
}
/*!
\brief The main function for the project.
\details The startup initialization sequence is the following:
* - startup asm routine
* - main()
*/
int main(void)
{
/* Write your code here */
/* Initialize the Mcu driver */
Mcu_Init(NULL_PTR);
Mcu_InitClock(McuClockSettingConfig_0);
#if (MCU_NO_PLL == STD_OFF)
while ( MCU_PLL_LOCKED != Mcu_GetPllStatus() )
{
/* Busy wait until the System PLL is locked */
}
Mcu_DistributePllClock();
#endif
Mcu_SetMode(McuModeSettingConf_0);
/* Initialize Mcl module */
Mcl_Init(NULL_PTR);
/* Initialize all pins using the Port driver */
Port_Init(NULL_PTR);
/* Initialize IRQs */
Platform_Init(NULL_PTR);
Platform_InstallIrqHandler(LPUART1_RxTx_IRQn, LPUART_UART_IP_1_IRQHandler, NULL_PTR);
/* Initializes an UART driver*/
Uart_Init(NULL_PTR);
memset(Rx_Buffer, 0, sizeof(Rx_Buffer));
while(true)
{
Uart_AsyncReceive(UART_LPUART_INTERNAL_CHANNEL, Rx_Buffer, 1);
while(flag);
/* Append string terminator to the received data */
rxIndex++;
Rx_Buffer[rxIndex] = 0U;
memcpy(Rx_Data,Rx_Buffer,rxIndex);
Uart_AsyncSend(UART_LPUART_INTERNAL_CHANNEL, Rx_Data, 10);
/* Reset the buffer index to start a new reception */
rxIndex = 0U;
memset(Rx_Buffer, 0, sizeof(Rx_Buffer));
}
Uart_Deinit();
Mcl_DeInit();
// Exit_Example((T_Uart_Status1 == E_OK) && (T_Uart_Status2 == E_OK));
return (0U);
}

|
|