打印

[求助]关于串口相关寄存器的问题

[复制链接]
1706|8
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
zhaoyanggolden|  楼主 | 2013-3-25 16:11 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
我是新手,最近刚接触DSP,使用的是ICETEK的f2812板子调程序。最近在研究串口通信的时候遇到问题了。
使用DSP板子自带的例程编译后运行,但是串口调试助手中无法收到板子发送的数据,单步调试了一下,发现是
while(SciaRegs.SCIFFTX.bit.TXFFST !=0) { }
这一句中TXFFST这个值,一旦发送缓冲区读入第一个值后就无法归零,导致程序一直锁死,请问这个值的作用是什么,应该怎样使用才能让串口正常工作,谢谢各位了

相关帖子

沙发
zhaoyanggolden|  楼主 | 2013-3-25 16:12 | 只看该作者
下面是程序的源代码
/* 2812A板:
        使用直连的串口通信电缆;
        启动串口调试助手.exe;
        PC机发送一个"."为结束标志
*/
#include "DSP281x_Device.h"
#include "DSP281x_Examples.h"

// Prototype statements for functions found within this file.
void scia_loopback_init(void);
void scia_fifo_init(void);       
void scia_xmit(int a);
void error(int);
void wait(int nWait);
interrupt void scia_rx_isr(void);
interrupt void scia_tx_isr(void);

// Global counts used in this example
Uint16 LoopCount;
Uint16 ErrorCount;
char cString[17]={"Hello PC!,Over|"},cReceive,cBuffer[17],cAnswer[16]={"Oh,you say"};
void main(void)
{   
    char ReceivedChar;   
    int i,k=0,nLen,bReceive=0;
// Step 1. Initialize System Control registers, PLL, WatchDog, Clocks to default state:
        // This function is found in the DSP281x_SysCtrl.c file.
        InitSysCtrl();

// Step 2. Select GPIO for the device or for the specific application:
       // This function is found in the DSP281x_Gpio.c file.
       // InitGpio(); skip this as this is example selects the I/O for SCI in this file itself
    EALLOW;
    GpioMuxRegs.GPFMUX.all=0x0030;        // Select GPIOs to be Sci pins         
                                    // Port F MUX - x000 0000 0011 0000
    EDIS;

// Step 3. Initialize PIE vector table:
      // The PIE vector table is initialized with pointers to shell Interrupt
      // Service Routines (ISR).  The shell routines are found in DSP281x_DefaultIsr.c.
      // Insert user specific ISR code in the appropriate shell ISR routine in
      // the DSP28_DefaultIsr.c file.

      // Disable and clear all CPU interrupts:
        DINT;
        IER = 0x0000;
        IFR = 0x0000;

      // Initialize Pie Control Registers To Default State:
      // This function is found in the DSP281x_PieCtrl.c file.
          // InitPieCtrl();  PIE is not used for this example

      // Initialize the PIE Vector Table To a Known State:
      // This function is found in DSP281x_PieVect.c.
      // This function populates the PIE vector table with pointers
      // to the shell ISR functions found in DSP281x_DefaultIsr.c.
          InitPieVectTable();  

      // Enable CPU and PIE interrupts
      // This example function is found in the DSP281x_PieCtrl.c file.   
      EnableInterrupts();
       
// Step 4. Initialize all the Device Peripherals to a known state:
      // This function is found in DSP281x_InitPeripherals.c
      // InitPeripherals(); skip this for SCI tests
       
// Step 5. User specific functions, Reassign vectors (optional), Enable Interrupts:

    LoopCount = 0;
    ErrorCount = 0;
   
    scia_fifo_init();           // Initialize the SCI FIFO
    scia_loopback_init();  // Initalize SCI for digital loop back

    // Note: Autobaud lock is not required for this example
   
    // Send a character starting with 0
                                               

// Step 6. Send Characters forever starting with 0x00 and going through
// 0xFF.  After sending each, check the recieve buffer for the correct value
    for ( i=0;i<16;i++ )
                        {
                            scia_xmit(cString[i]);
                                while(SciaRegs.SCIFFTX.bit.TXFFST !=0) { }
                                //wait(1024);               
                        }
        for(;;)
    {        
       if ( bReceive==1 )
       {for ( i=0;i<10;i++ )
                        {                       
                                scia_xmit(cAnswer[i]);
                             while(SciaRegs.SCIFFTX.bit.TXFFST !=0) { }
                        }
                       
                        scia_xmit('\"');
                        for ( i=0;i<nLen;i++ )
                        {
                       
                                scia_xmit(cBuffer[i]);
                            while(SciaRegs.SCIFFTX.bit.TXFFST !=0) { }
                        }
                       
                        scia_xmit('\"');
                        wait(1024);               
                        for ( i=9;i<16;i++ )
                        {                               
                                scia_xmit(cString[i]);
                            while(SciaRegs.SCIFFTX.bit.TXFFST !=0) { }
                        }
                }
                k=0; bReceive=0;
        while(1)
         {
            while(SciaRegs.SCIFFRX.bit.RXFIFST ==0) { } // 如果接受寄存器不为0则跳出
            ReceivedChar = SciaRegs.SCIRXBUF.all;
            cBuffer[k]=ReceivedChar;
            
                if ( ReceivedChar=='.')
                        {
                                cBuffer[k+1]='\0';
                                nLen=k+1;
                                bReceive=1;
                                break;
                        }
                    k++; k%=16;
              }       
      
    }

}        


// Step 7. Insert all local Interrupt Service Routines (ISRs) and functions here:       

void error(int ErrorFlag)
{
      ErrorCount++;

}

// Test 1,SCIA  DLB, 8-bit word, baud rate 0x000F, default, 1 STOP bit, no parity
void scia_loopback_init()
{   
    // Note: Clocks were turned on to the SCIA peripheral
    // in the InitSysCtrl() function
   
        SciaRegs.SCICCR.all =0x0007;   // 1 stop bit,  No loopback
                                   // No parity,8 char bits,
                                   // async mode, idle-line protocol
        SciaRegs.SCICTL1.all =0x0003;  // enable TX, RX, internal SCICLK,
                                   // Disable RX ERR, SLEEP, TXWAKE
        SciaRegs.SCICTL2.all =0x0003;
        SciaRegs.SCICTL2.bit.TXINTENA =1;
        SciaRegs.SCICTL2.bit.RXBKINTENA =1;
    SciaRegs.SCIHBAUD    =0x0001;
    SciaRegs.SCILBAUD    =0x00e7;
        SciaRegs.SCICCR.bit.LOOPBKENA =0; // disable loop back  
        SciaRegs.SCICTL1.all =0x0023;     // Relinquish SCI from Reset
}

// Transmit a character from the SCI'
void scia_xmit(int a)
{
    SciaRegs.SCITXBUF=a;
}   

// Initalize the SCI FIFO
void scia_fifo_init()                                                                               
{
    SciaRegs.SCIFFTX.all=0xE040;
    SciaRegs.SCIFFRX.all=0x204f;
    SciaRegs.SCIFFCT.all=0x0;
   
}  

void wait(int nWait)
{
        int i,j,k=0;
        for ( i=0;i<nWait;i++ )
                for ( j=0;j<64;j++ )
                        k++;
}                                                                       

使用特权

评论回复
板凳
zhangmangui| | 2013-3-25 17:46 | 只看该作者
我觉得这句没有问题的  这句的功能:如果缓冲区里面有东西没有发送完的话 这个标志置位表示数据还在发送  等待发送完成   不可能一直到这儿循环啊   一直循环的话  说明有数据一直在发送啊  这样上位机软件是可以收到数据的  还是检查一下你的串口是不是通
下面是我用的发送函数
/*------------------------------------------*/
/*形式参数:char                            */
/*返回值:void                                                */
/*函数描述:发送一个字符                                                */
/*------------------------------------------*/
void Send_Char_SCIA(char temp)
{
        while(SciaRegs.SCIFFTX.bit.TXFFST !=0);
        SciaRegs.SCITXBUF=temp;
}
/*------------------------------------------*/
/*形式参数: char *String                   */
/*返回值:void                                                */
/*函数描述:发送一个字符串                                        */
/*------------------------------------------*/
void Send_String_SCIA(char *String)
{
        while(*String !='\0')
          {
     Send_Char_SCIA(*String++);
          }
}

使用特权

评论回复
地板
zhaoyanggolden|  楼主 | 2013-3-25 19:39 | 只看该作者
感谢回复,串口线没问题、上位机的接口也正常,如果代码没有问题的话,那有可能是板子上串口自身的问题了,我试了两块都是一样的结果真是

使用特权

评论回复
5
zhangmangui| | 2013-3-26 09:41 | 只看该作者
zhaoyanggolden 发表于 2013-3-25 19:39
感谢回复,串口线没问题、上位机的接口也正常,如果代码没有问题的话,那有可能是板子上串口自身的问题了, ...

建议你用硬件中断进行测试   看是否进入相应的处理函数中去

使用特权

评论回复
6
zhaoyanggolden|  楼主 | 2013-3-26 10:24 | 只看该作者
能详细说一下应该怎么做吗?你的意思是不是在相应的处理函数(比如void scia_xmit(int a))中开中断,函数结尾关中断,用板子上某个按钮做中断源,看看按下按钮后它是否能进入处理函数?

使用特权

评论回复
7
蓝草飘香| | 2013-9-28 21:53 | 只看该作者
zhangmangui 发表于 2013-3-25 17:46
我觉得这句没有问题的  这句的功能:如果缓冲区里面有东西没有发送完的话 这个标志置位表示数据还在发送   ...

大侠。  请教一下。。   这一句说如果有数据没有发完,就一直循环等待, 那发完了还需要那个for循环做什么呢?

使用特权

评论回复
8
zhangmangui| | 2013-9-28 22:19 | 只看该作者
蓝草飘香 发表于 2013-9-28 21:53
大侠。  请教一下。。   这一句说如果有数据没有发完,就一直循环等待, 那发完了还需要那个for循环做什 ...

连续发的时候  等待上次发完  发完就会跳出while
继续下面的

使用特权

评论回复
9
蓝草飘香| | 2013-9-29 10:55 | 只看该作者
本帖最后由 蓝草飘香 于 2013-9-29 10:56 编辑

如果我要发31个数据。。。  程序如下:
interrupt void SCITXINTA_ISR(void)     // SCI-A发送中断函数
{
    int i;
        for(i=0;i<31;i++)
        {
            SciaRegs.SCITXBUF=buffer; //发送数据
                 while(SciaRegs.SCIFFTX.bit.TXFFST!=0);
        }

    PieCtrl.PIEACK.all=0x0100;  //使得同组其他中断能够得到响应
    EINT;  //开全局中断
}
那每发一个数据就等待FIFO发完,FIFO里面就相当于进来一个数据就发一个,等FIFO空了再发下一个?  感觉怪怪的~~

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

1

主题

5

帖子

0

粉丝