This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

C5502的UART传出数据位少的问题



利用csl库进行配置和传输数据,应该是5位数据输出,但第一次传输只有后四位,第二次传输是5位但第一位变成第一次传输的最后一位不是我要的那位数据,附上程序和结果图,求大神指点

程序:

#include <stdio.h>
#include <csl.h>
#include <csl_pll.h>
#include <csl_chip.h>
#include <csl_irq.h>
#include <csl_gpt.h>
#include <csl_uart.h>
#include <csl_uarthal.h>


/* Reference start of interrupt vector table */
/* This symbol is defined in file, vectors.s55 */
extern void VECSTART(void);

Uint16 i = 0;
Uint16 j = 0;

//Uint8 STR_LEN=5;
#define STR_LEN 5
char pbuf[5]={0x11,0x22,0x33,0x44,0x55};
CSLBool returnFlag;
/* 通过定义宏来控制两个外围存储器映射的寄存器,从而实现对GPIO口的控制 */
#define GPIODIR (*(volatile ioport Uint16*)(0x3400))
#define GPIODATA (*(volatile ioport Uint16*)(0x3401))
/*UART的中断程序*/

UART_Setup mySetup = {
75, /* input clock freq */
UART_BAUD_38400, /* baud rate */
UART_WORD8, /* word length */
UART_STOP1, /* stop bits */
UART_DISABLE_PARITY, /* parity */
UART_FIFO_DISABLE, /*DISABLE */
UART_NO_LOOPBACK, /* Loop Back enable */
};


void main(void)
{
/* Initialize CSL library - This is REQUIRED !!! */
CSL_init();

/* PLL configuration structure used to set up PLL interface */
// 主频为300Mhz
PLL_setFreq(1, 0x3, 0, 1, 3, 3, 0);

// IRQ_setVecs((Uint32)(&VECSTART));
// Uart_Config();
/* Configure UART registers using setup structure */
UART_setup(&mySetup);

/* Enable all maskable interrupts */
// IRQ_globalEnable();
// IRQ_globalDisable();

returnFlag=UART_write(&pbuf[0],STR_LEN,0);

}

  • 先量一下时序上第一个数据有没有发出来?还是串口工具显示有问题。

  • 跑csl里的uart例程有问题吗?

  • 请问这个时序数据检测怎么查?串口工具换了两个了同样情况

  • 对了,是自己的板子还是EVM板?

  • 自己的板子和买的外面的开发板都是这样

  • jia ji 说:

    请问这个时序数据检测怎么查?串口工具换了两个了同样情况

    用示波器量uart TX, RX管脚上的波形。

  • 有问题,还是错位

    csl的例程如下

    #include <stdio.h>
    #include <csl.h>
    #include <csl_uart.h>

    //---------Global constants---------
    /* String length to be received and transmitted */
    #define STR_LEN 83

    //---------Global data definition---------
    /* Buffer to be copied to clip board and sent to UART
    using terminal emulator program
    */

    //char clipboardBuf[] = {0x11,0x22,0x33};


    char clipboardBuf[] = {
    " <BEGIN>The quick brown fox jumped over lazy dog. This is simple UART test<END>"
    };

    /* User buffer that receives data */
    char myBuf[STR_LEN];

    /* UART setup structure */
    UART_Setup mySetup = {
    75, /* input clock freq */
    UART_BAUD_38400, /* baud rate */
    UART_WORD8, /* word length */
    UART_STOP1, /* stop bits */
    UART_DISABLE_PARITY, /* parity */
    UART_FIFO_DISABLE, /*DISABLE */
    UART_NO_LOOPBACK, /* Loop Back enable */
    };

    //---------main routine---------
    void main()
    {
    /* Loop counter and error flag */
    Int16 i, error = 0;

    /* Initialize CSL library */
    CSL_init();

    /* Configure UART registers using setup structure */
    UART_setup(&mySetup);
    // PLL_setFreq(1, 0x3, 0, 1, 3, 3, 0);

    /* UART receiver reads data from PC COM port */
    if (UART_read(myBuf, STR_LEN, 0) == FALSE) {
    error = 1;
    }
    else {

    /* UART transmitter write data to PC COM port */
    if ((UART_write(myBuf, STR_LEN, 0)) == FALSE)
    error = 1;
    }

    /* Verify the recevied data for correctness */
    for (i = 0; i < STR_LEN-1; i++) {
    if (myBuf[i] != clipboardBuf[i]) {
    error = 1;
    break;
    }
    }

    /* Display PASS/FAIL status based on error flag */
    if (error)
    printf("\nTEST FAILED\n");
    else
    printf("\nTEST PASSED\n");
    }

  • 这个用csl例程跟左边的lib有关吗?

  • 如果例程不能跑通的话,应该和你的硬件和串口工具有关。

    你先量一下时序,看第一个数据有没有发出来,先排除硬件的问题。

  • 你是指什么lib? csl lib?