您好,我使用的是MPC5748G。
我在软件提供的例子“lwip”上添加了uart通信,实现通过UDP接收然后通过Uart传出数据。一开始发送数据后,Uart有返回数据,等成功的运行了20分钟左右,程序突然断开,且再启动后无法通过Uart返回数据,rebuild后也无法实现。以下是我在lwip例子中添加的uart的配置和代码:
uart组件配置:
uart引脚配置:
时钟配置:
代码补全(udpecho.c):
/*-----lixu------------------------------------------------------------------------------*/
#define TIMEOUT 100UL
#define BUFFER_SIZE 256UL
//uint8_t buff[BUFFER_SIZE]; uint8_t bufferIdx;
void uartRxCallback(void *driverState, uart_event_t event, void *userData) {
/* Unused parameters */
(void)driverState;
(void)userData;
/* Check the event type */
if (event == UART_EVENT_RX_FULL)
{
/* The reception stops when newline is received or the buffer is full */
if ((buffer[bufferIdx] != '\n') && (bufferIdx != (BUFFER_SIZE - 2U)))
{
/* Update the buffer index and the rx buffer */
bufferIdx++;
UART_SetRxBuffer(&uart_pal1_instance, &buffer[bufferIdx], 1U);
}
}
}
/*-----------------------------------------------------------------------------------*/
udpecho_thread( )下添加
/* Initialize UART PAL over LINFlexD */
UART_Init(&uart_pal1_instance, &uart_pal1_Config0);
/* Send the received data back */ UART_SendDataBlocking(&uart_pal1_instance, buffer, strlen((char *)buffer), TIMEOUT);
错误现象:
运行工程,使用网络传输助手发送数据,uart和udp都没有接收到数据(原来例子中的udp发送没有关掉,所以发送数据时udp和uart应该都可以返回数据),程序断开。
另一现象:
当注释掉UART_SendDataBlocking( )函数时,udp可以返回数据。
想请教一下大家有没有知道这个问题的原因及解决方法。
望回复,谢谢!
此问题已解决,找到问题错误出现在哪里。可以进行通信,但是uart转发数据总是丢第二位,有待解决,望有经验者指点一下。