在线咨询
eetop公众号 创芯大讲堂 创芯人才网
切换到宽版

EETOP 创芯网论坛 (原名:电子顶级开发网)

手机号码,快捷登录

手机号码,快捷登录

找回密码

  登录   注册  

快捷导航
搜帖子
芯片精品文章合集(500篇!)    创芯人才网--重磅上线啦!
查看: 3532|回复: 1

为何我的uart 不能接收

[复制链接]
发表于 2006-8-25 10:03:57 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册

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;
}
发表于 2006-8-28 17:43:29 | 显示全部楼层

RE:

好久没有接触“direct hardware”了,下面是我的拙见:

首先申明,我不太了解“xuartlite_l.h”, 呵呵
你应该做的是一个自发自收的程序,发送显然是可行的,因为你可以选择对发送内容不处理(应该在发送中断里)。但是接收语句“RecvBuffer[Index] = XUartLite_RecvByte(UartliteBaseAddress); ” 的执行应该在你的接收中断向量中。正常的情况是:每接收到一个byte的信息,执行接收语句,上面的程序不满足这一点,你的程序顺序执行发收最多只能收到最后一个byte。或者根本没有

正确的做法是把接收处理和接收中断向量关联起来
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

站长推荐 上一条 /1 下一条

关闭

小黑屋| 关于我们| 联系我们| 在线咨询| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2024-3-29 22:49 , Processed in 0.042872 second(s), 10 queries , Gzip On, Redis On.

eetop公众号 创芯大讲堂 创芯人才网
快速回复 返回顶部 返回列表