|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
为何我的uart 不能接收
我试着写了一个串口发送和接收的小程序,发现发现过程是好的,可为什么会接到不到呢?感觉上不应该出现这种情况,请大侠帮看看。
#include "xparameters.h"
#include "xstatus.h"
#include "xuartlite_l.h"
/************************** Constant Definitions *****************************/
#define UARTLITE_BASEADDR XPAR_RS232_UART_BASEADDR
#define TEST_BUFFER_SIZE 16
/************************** Function Prototypes ******************************/
XStatus UartLiteLowLevelExample(Xuint32 UartliteBaseAddress);
/************************** Variable Definitions *****************************/
/*
* The following buffers are used in this example to send and receive data
* with the UART.
*/
Xuint8 SendBuffer[TEST_BUFFER_SIZE]; /* Buffer for Transmitting Data */
Xuint8 RecvBuffer[TEST_BUFFER_SIZE]; /* Buffer for Receiving Data */
/*****************************************************************************/
int main(void)
{
XStatus Status;
/*
* Run the UartLite Low level example , specify the BaseAddress that is
* generated in xparameters.h
*/
Status = UartLiteLowLevelExample(UARTLITE_BASEADDR);
if (Status != XST_SUCCESS)
{
return XST_FAILURE;
}
return XST_SUCCESS;
}
/*****************************************************************************/
XStatus UartLiteLowLevelExample(Xuint32 UartliteBaseAddress)
{
int Index;
/*
* Initialize the send buffer bytes with a pattern to send and the
* the receive buffer bytes to zero
*/
for (Index = 0; Index < TEST_BUFFER_SIZE; Index++)
{
SendBuffer[Index] = Index + 'B';
RecvBuffer[Index] = 0;
}
/*
* Send the entire transmit buffer.,此处是工作的
*/
for (Index = 0; Index < TEST_BUFFER_SIZE; Index++)
{
XUartLite_SendByte(UartliteBaseAddress, SendBuffer[Index]);
printf("%d***",SendBuffer[Index]);
}
/*
* Receive the entire buffer's worth. Note that the RecvByte function
* blocks waiting for a character.此外为什么没有接收???
*/
for (Index = 0; Index < TEST_BUFFER_SIZE; Index++)
{
RecvBuffer[Index] = XUartLite_RecvByte(UartliteBaseAddress);
printf("%d###",RecvBuffer[Index]);
}
/*
* Check the receive buffer data against the send buffer and verify the
* data was correctly received
*/
for (Index = 0; Index < TEST_BUFFER_SIZE; Index++)
{
if (SendBuffer[Index] != RecvBuffer[Index])
{
return XST_FAILURE;
}
}
return XST_SUCCESS;
} |
|