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.

关于SCI直接查询标志位发送数据的问题,一直差两个发不出。



我使用的是28027,用查询TXRDY为1时发送数据的方法发数据。但是一直差两个字节,就像被FIFO扣住两个字节一样,但是没开FIFO并且试过加上明确关FIFO的语句也没成功。要发送完整的数据就必须加发两个字节。程序是修改例程的。请问有可能是什么原因造成的。

  • 楼主,请把你的SCI初始化代码贴出以便大家进行错误分析,谢谢!

  • 贴出了部分程序,发3个字节只能收到第一个,发4个只能收到前两个,发2个及以下都收不到。

    void main( void )

    {

         myAdc = ADC_init((void *)ADC_BASE_ADDR, sizeof(ADC_Obj));

            myClk = CLK_init((void *)CLK_BASE_ADDR, sizeof(CLK_Obj));

            myCpu = CPU_init((void *)NULL, sizeof(CPU_Obj));

            myFlash = FLASH_init((void *)FLASH_BASE_ADDR, sizeof(FLASH_Obj));

            myGpio = GPIO_init((void *)GPIO_BASE_ADDR, sizeof(GPIO_Obj));

            myPie = PIE_init((void *)PIE_BASE_ADDR, sizeof(PIE_Obj));

            myPll = PLL_init((void *)PLL_BASE_ADDR, sizeof(PLL_Obj));

            mySci = SCI_init((void *)SCIA_BASE_ADDR, sizeof(SCI_Obj));

            myWDog = WDOG_init((void *)WDOG_BASE_ADDR, sizeof(WDOG_Obj));

            myTimer = TIMER_init((void *)TIMER0_BASE_ADDR, sizeof(TIMER_Obj));

            // Perform basic system initialization

            WDOG_disable(myWDog);

            CLK_enableAdcClock(myClk);

            (*Device_cal)();

            CLK_enableCpuTimerClock(myClk,CLK_CpuTimerNumber_0);

            //Select the internal oscillator 1 as the clock source

            CLK_setOscSrc(myClk, CLK_OscSrc_Internal);

            // Setup the PLL for x12 /2 which will yield 60Mhz = 10Mhz * 12 / 2

            PLL_setup(myPll, PLL_Multiplier_12, PLL_DivideSelect_ClkIn_by_2);

            // Disable the PIE and all interrupts

            PIE_disable(myPie);

            PIE_disableAllInts(myPie);

            CPU_disableGlobalInts(myCpu);

            CPU_clearIntFlags(myCpu);

            // If running from flash copy RAM only functions to RAM

        #ifdef _FLASH

            memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (size_t)&RamfuncsLoadSize);

        #endif

            // This example is a basic pinout

            //Gpio_setup2();

            Gpio_setup1();

            // Initalize GPIO

            GPIO_setPullUp(myGpio, GPIO_Number_28, GPIO_PullUp_Enable);

            GPIO_setPullUp(myGpio, GPIO_Number_29, GPIO_PullUp_Enable);

            GPIO_setQualification(myGpio, GPIO_Number_28, GPIO_Qual_ASync);

            GPIO_setMode(myGpio, GPIO_Number_28, GPIO_28_Mode_SCIRXDA);

            GPIO_setMode(myGpio, GPIO_Number_29, GPIO_29_Mode_SCITXDA);

            // Setup a debug vector table and enable the PIE

            PIE_setDebugIntVectorTable(myPie);

            PIE_enable(myPie);

            PIE_registerPieIntHandler(myPie, PIE_GroupNumber_1, PIE_SubGroupNumber_7, (intVec_t)&cpu_timer0_isr);//-----------------------------

            PIE_enableTimer0Int(myPie);

            // Configure CPU-Timer 0 to interrupt every 500 milliseconds:

            // 60MHz CPU Freq, 50 millisecond Period (in uSeconds)

            //    ConfigCpuTimer(&CpuTimer0, 60, 500000);

            TIMER_stop(myTimer);

            TIMER_setPeriod(myTimer, (uint32_t)(240625));//240625

            TIMER_setPreScaler(myTimer, 0);

            CpuTimer0Regs.TCR.bit.TRB = 1;

    //        TIMER_reload(myTimer);

            TIMER_setEmulationMode(myTimer, TIMER_EmulationMode_StopAfterNextDecrement);

    //        TIMER_enableInt(myTimer);

    //        TIMER_start(myTimer);

            vMBPortSerialEnable( 1, 0 );

            // Register interrupt handlers in the PIE vector table

            PIE_registerPieIntHandler(myPie, PIE_GroupNumber_9, PIE_SubGroupNumber_1, (intVec_t)&sciaRxFifoIsr);

               // Enable interrupts required for this example

            PIE_enableInt(myPie, PIE_GroupNumber_9, PIE_InterruptSource_SCIARX);

            CPU_enableInt(myCpu, CPU_IntNumber_9);

            CPU_enableInt(myCpu, CPU_IntNumber_1);

            CPU_enableGlobalInts(myCpu);

            CPU_enableDebugInt(myCpu);

            scia_echoback_init();

            SCI_putDataBlocking(mySci, 0x01);

    while( j < 50)

    {

    usRegHoldingBuf[ j ] = j;

    j++;

    }

            usRegHoldingBuf[ LCD_WIFI_485_IO + 1] = RS485;

           vMBPortSerialEnable( 0, 1 );         //开启发送关闭接收

            scia_xmit((unsigned char *)"abcde", 3);

            vMBPortSerialEnable( 1, 0 );         //开启接收关闭发送

    while(1)

    if( Recieved )

    {

    Transport_Protocols( &usRegHoldingBuf[ LCD_WIFI_485_IO ] );

    Recieved = 0;

    }

    }

    void Gpio_setup1(void)

    {

        // Example 1:

        // Basic Pinout.

        // These can be combined into single statements for improved

        // code efficiency.

    GPIO_setHigh(myGpio, GPIO_Number_0);

    GPIO_setHigh(myGpio, GPIO_Number_1);

    GPIO_setHigh(myGpio, GPIO_Number_2);

    GPIO_setHigh(myGpio, GPIO_Number_3);

    GPIO_setMode(myGpio, GPIO_Number_0, GPIO_12_Mode_GeneralPurpose);

    GPIO_setMode(myGpio, GPIO_Number_1, GPIO_12_Mode_GeneralPurpose);

    GPIO_setMode(myGpio, GPIO_Number_2, GPIO_12_Mode_GeneralPurpose);

    GPIO_setMode(myGpio, GPIO_Number_3, GPIO_12_Mode_GeneralPurpose);

    GPIO_setDirection(myGpio, GPIO_Number_0, GPIO_Direction_Output);

    GPIO_setDirection(myGpio, GPIO_Number_1, GPIO_Direction_Output);

    GPIO_setDirection(myGpio, GPIO_Number_2, GPIO_Direction_Output);

    GPIO_setDirection(myGpio, GPIO_Number_3, GPIO_Direction_Output);

        // Enable an GPIO output on GPIO6&7, set it high

        GPIO_setHigh(myGpio, GPIO_Number_12);

        GPIO_setMode(myGpio, GPIO_Number_12, GPIO_12_Mode_GeneralPurpose);

        GPIO_setDirection(myGpio, GPIO_Number_12, GPIO_Direction_Output);

    }

    void scia_echoback_init()

    {

        CLK_enableSciaClock(myClk);

        // 1 stop bit,  No loopback

        // No parity,8 char bits,

        // async mode, idle-line protocol

        SCI_disableParity(mySci);

        SCI_setNumStopBits(mySci, SCI_NumStopBits_One);

        SCI_setCharLength(mySci, SCI_CharLength_8_Bits);

        SCI_enableTx(mySci);

        SCI_enableRx(mySci);

        SCI_enableTxInt(mySci);

        SCI_enableRxInt(mySci);

        SCI_setTxFifoIntLevel(mySci, SCI_FifoLevel_Empty);   //关闭FIFO

        SCI_disableFifoEnh(mySci);

        SCI_disableTxFifoInt(mySci);

        // SCI BRR = LSPCLK/(SCI BAUDx8) - 1

    #if (CPU_FRQ_60MHZ)

        SCI_setBaudRate(mySci, SCI_BaudRate_9_6_kBaud);

    #elif (CPU_FRQ_50MHZ)

        SCI_setBaudRate(mySci, (SCI_BaudRate_e)162);

    #elif (CPU_FRQ_40MHZ)

        SCI_setBaudRate(mySci, (SCI_BaudRate_e)129);

    #endif

        SCI_enable(mySci);

        return;

    }

    void scia_xmit(unsigned char * Cbuffer, unsigned char n)

    {

        int i = 0;

        while( i < n )

        {

            SCI_putDataBlocking(mySci, Cbuffer[ i++ ]);

        }

    }

    /***********************************************************

     *

     *

     *

     ***********************************************************/

    unsigned char vMBPortSerialEnable( unsigned char xRxEnable, unsigned char xTxEnable )

    {

        EnterCriticalSection(  );

        unsigned char Error = 0;

        if( xRxEnable && (!xTxEnable))

        {

         GPIO_setLow(myGpio, GPIO_Number_12);

         SCI_disableTx(mySci);

         SCI_disableTxInt(mySci);

         SCI_enableRx(mySci);

         SCI_enableRxInt(mySci);

        }

        else if( xTxEnable && (!xRxEnable))

        {

         GPIO_setHigh(myGpio, GPIO_Number_12);

     

         SCI_disableRx(mySci);

         SCI_disableRxInt(mySci);

         SCI_enableTx(mySci);

         SCI_enableTxInt(mySci);

        }

        else

        {

         Error = 1;

        }

        ExitCriticalSection(  );

        return Error;

    }