How can I send and receive continuously through the serial port of a wireless network in 8051?

I am trying to get the microcontroller to interact with a program on my desktop. I use serial ports with Xbee radios at both ends.

Communication works great when I send something from the microcontroller to the desktop and the program to the desktop, and then send something back to the microcontroller.

However, when I need the information to be sent from the controller to the desktop program continuously until the desktop program sends a specific response, it does not work.

Here is the code I'm talking about:

    unsigned char ans = 'N';
    unsigned int count = 0;

    void main(void)
    {


        while(1)
        {
            if(count == 0)
            {
                Configure();
                count = 1;
            }

                  //there is some more code here but is irrelevant to the serial communication

         }

    }


void Configure()
{


    //Repeat this until the user accepts the sent string as correct
    while(ans == 'N')
    {

        BuildString();
        Send();
        Receive();
    }
}

void Send()
{
    unsigned int i;

    TMOD = 0x20;
    TH1 = 0xFD;
    SCON = 0x50;
    TR1 = 1;

    for(i=0; i<4; i++)
    {
        SBUF = toSend[i];
        while(TI == 0);
        TI = 0;
    }   

}

void Receive()
{
    unsigned int j;

    TMOD = 0x20;
    TH1 = 0xFD;
    SCON = 0x50;
    TR1 = 1;


    for(j=0; j<2; j++)
    {
        while(RI == 0);
        Received[j] = SBUF;
        RI = 0; 
    }


    if(count == 0)
        ans = Received[1];

    else
    {   
        RunType = Received[0];
        Move = Received[1];
    }


}

BuildString() . , , , , Configure() , .

? .

+5
2

, . , . Dito , ( , , .

, ; , .

, , , , ( tx-empty), / / .

:

  • ( )
  • ( /, , )

( ) ; - , . os (rtos/scheduler), . , , , () .

.

, , . FIFO ( 64 ) , . , , . . , OVERFLOW ; , .

:  * 2 (: init + do_something). msg, - .  * , receive().  * ( , -.

, : . , , . , ( , , , ).

rs232 ( . ( ) , rs232 . , . Google : ; .

+4

, , 4 , 2 ( , , , , , ), 4 ... , , , , - , .

, ( ), ? , . .

  • , ? ?
  • , ?
  • - micro xbee? ?
+1

All Articles