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.

[参考译文] CCS/TMS570LC4357:UART 缓冲器问题

Guru**** 2481465 points


请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/arm-based-microcontrollers-group/arm-based-microcontrollers/f/arm-based-microcontrollers-forum/655736/ccs-tms570lc4357-uart-buffer-problem

器件型号:TMS570LC4357

工具/软件:Code Composer Studio

您好!

我使用 Hercules 的 UART、但我有问题。 我使用一个数组来存储从 MCU 接收到 UART  端口的字节、但我看到程序丢失了接收到的第一个字节。

例如、当发送安全 1234时、MCU 仅发送 其他 UART 234、如果我再次发送安全 1234、则 MCU 显示2341。

我共享 在 ISR 和主代码中使用的基本代码。  

int main (空)


/*用户代码开始(3)*/
int i=0;
MCU_Init();

//sci_Restart();
while (1)

RX_NEXT = 0;
RX_READ=0;
RxB_NEX=0;
RxB_READ=0;

延迟(10);

if (flag_bluy=1){//读取缓冲区  
sciSend (蓝色、11、(无符号字符*)"\r\n 缓冲区!\r\n");

while (flag_Blue=1){
sciSendByte (蓝色、Rx_buffer_blue[RxB_Read]);
RxB_READ++;
RxB_NEX--;
if (RxB_NEX=1){
Flag_Blue = 0;
RxB_READ=0;
RxB_NEX=0;
for (i=0;i<100;i++){
RX_buffer_blue[i]=0;}


 }

void sciNotification (sciBASE-t * sci、无符号标志)

if (sci=blue){
sciReceive (sci、1、(unsigned char *)&rx_buffer_blue[RxB_NEX]);
sciSendByte (蓝色、Rx_buffer_blue[RxB_NEX]);
RxB_NEX++;

if (sciIsRxReady (sci)=0){
Flag_Blue = 1;

如果您有任何建议或问题,请告诉我

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
    我更新代码、因为我在 sci notificacion 内的指令 scisendbyte 时不使用。 此部分代码为:

    void sciNotification (sciBASE-t * sci、无符号标志)


    if (sci=blue){
    sciReceive (sci、1、(unsigned char *)&rx_buffer_blue[RxB_NEX]);
    RxB_NEX++;

    if (sciIsRxReady (sci)=0){
    Flag_Blue = 1;


  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
    您好、Sanchez、

    遗憾的是、我无法深入研究这一点以确定确切的根本原因、但在前面的问题中、我发现中断的初始化存在问题、第一个字节丢失、因为中断不会到达第二个字节。

    在代码启动期间、您在代码中的哪个位置初始化/启用中断?
  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    你好、Chuck、

    在中断的初始化之上、我共享一部分代码:

    //@文件 hL_sys_main.c

    #include "hL_sci.h"
    #include "hL_het.h"
    #include "HL_Gio.h"
    #include "stdlib.h"
    #include "hL_sci.h"

    /*用户代码结束*/
    /*包含文件*/

    #include "hL_sys_common.h"

    /*用户代码开始(1)*/
    //======================================================== 变量 Iridium 和 debug
    unsigned char 命令;
    unsigned char rx_buffer_blue[100];
    int rx_next = 0;
    int rx_read=0;
    int RxB_NEXT = 0;
    int RxB_read=0;

    uint8_t flag_bluy=0;

    void Plot_Debug ();

    void sci_Restart()


    sciInit();
    _enable_IRQ ();

    sciEnableNotification (蓝色、SCI_RX_INT);
    sciReceive (蓝色、1、(无符号字符*)&rx_buffer_blue);

    void MCU_Init()


    //int i=0;
    sciInit();
    adcInit();
    //adcInit();
    //sciSend (debug、11、(unsigned char*)"MCU init!\r\n");
    gioSetDirection (hetPORT1、0x2040240A);
    gioSetPort (hetPORT1、0x00000000);
    gioSetDirection (hetPORT2、0xFFFFFFFF);
    gioSetPort (hetPORT2、0x00000000);

    _enable_IRQ ();
    sciEnableNotification (蓝色、SCI_RX_INT);

    //输入

    //gioSetBit (hetPORT1,12,0);//CTS
    //gioSetBit (hetPORT1,16,0);//DCD
    //gioSetBit (hetPORT1、14、0);//DSR

    //输出

    gioSetBit (hetPORT2、13、1);//rts  
    gioSetBit (hetPORT1,29.1);//DTR  

    sciReceive (蓝色、1、(无符号字符*)&rx_buffer_blue[99]);

    RX_buffer_blue[99]=0;
    sciSend (蓝色、11、(无符号字符*)"MCU Init!\r\n");

    /*用户代码结束*/

    /**@fn void main (void)
    *@应用程序主函数简介
    *@请注意、默认情况下、此函数为空。
    *
    *此函数在启动后调用。
    *用户可以使用此函数来实现应用程序。
    *

    /*用户代码开始(2)*/

    /*用户代码结束*/

    int main (空)


    /*用户代码开始(3)*/
    int i=0;
    MCU_Init();

    //sci_Restart();
    while (1)

    RX_NEXT = 0;
    RX_READ=0;
    RxB_NEX=0;
    RxB_READ=0;

    延迟(10);

    if (flag_bluy=1){//读取缓冲区  
    sciSend (蓝色、11、(无符号字符*)"\r\n 缓冲区!\r\n");

    while (flag_Blue=1){
    sciSendByte (蓝色、Rx_buffer_blue[RxB_Read]);
    RxB_READ++;
    RxB_NEX--;
    if (RxB_NEX=1){
    Flag_Blue = 0;
    RxB_READ=0;
    RxB_NEX=0;
    for (i=0;i<100;i++){
    RX_buffer_blue[i]=0;}


     }

    void sciNotification (sciBASE-t * sci、无符号标志)

    if (sci=blue){
    sciReceive (sci、1、(unsigned char *)&rx_buffer_blue[RxB_NEX]);
    sciSendByte (蓝色、Rx_buffer_blue[RxB_NEX]);
    RxB_NEX++;




    我按照您的示例操作、唯一的区别是缓冲区、该缓冲区 存储在端口中接收到的字节(蓝色)

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
    你好、Sanchez
    您是否能够解决此问题?
    此致
    Mukul