AT89C51ac3 serial data packet problem

Thread Starter

swinch

Joined Jan 24, 2010
5
Hi,
At the moment I have a project involving running 3 motors via a micro controller, the user controls the motors using a 3-axis joystick connected to a computer.
I have the joystick working perfectly, and the program sending the serial data packet to the micro correctly (I used a couple of serial port monitors to check this). The data sent is ASCII characters.

So the problem I'm having is that the micro only understands a section of the data being sent, it understands the automatic address character, the end of packet characters and the first 3 data characters, but not the rest. I'm sending a 15 character array including the address and the end chars.
i.e. if I send a12345678911ff it will reckonise the automatic address character 'a' and the end characters 'ff' and the '123' but not the rest.
The idea with the packet is to use each group of 3 to control each motor and the last 2 characters to choose whether the motors should be on or off.

I've added the serial interrupt method so you can see whats being done, basically I take the data from the serial buffer and put it in an array, I then use another method to convert the ASCII char to an int so that the PWM can be set.

I appreciate the help
Steve

Rich (BB code):
interrupt void Serial(){
    
    if(TI == 1){        //check for the transmit flag
        TI = 0;        //clear the flag
        transmit = 1;    //clear the global flag used for transmitting
    }
    
    if(RI == 1){                //check for the receive flag    
        UART_received = 1;        //set the flag to indicate that the UART byte has been received
            
        if(SM2 == 1){            //check to see if the automatic address is set to high
            SM2 = 0;        //turn off the address recognition and set it to data mode
            RI = 0;            //clear the receive flag
            i = 0;            //reset the global pointer to 0
        }
        else {                //ready for the data transmission
            buffer = SBUF;    //extract the information and store it inside the array
            if((buffer == 0x66 || 0x46) && (flag == 1)){    //check if the termination bit is a f and check the previous character
                SM2 = 1;    //if the last 2 characters have been ff turn back on the address recognition
                flag = 0;    
                complete = 1;    
                i=0;
                RI = 0;        //clear the receive flag
            }
            else if(buffer == 0x66|| 0x46){    //if this is the 1st f wait for another one 
                flag = 1;        //set the 1st f flag high
                i++;            //increment the array position
                RI = 0;            //clear the flag
            }        
            else{            //otherwise it is a normal byte coming in            
                i++;        //increment the array position
                RI = 0;        //clear the flag
            }                
        }            
    }                            
}
 

n9352527

Joined Oct 14, 2005
1,198
Rich (BB code):
  ...
  if((buffer == 0x66 || 0x46) && (flag == 1)){    //check if the termination bit is a f and check the previous character
  ...
  else if(buffer == 0x66|| 0x46){    //if this is the 1st f wait for another one 
  ...


The above statements are wrong. You have to test both conditions separately and then OR the results.

Rich (BB code):
  if ((buffer == 0x66 || buffer == 0x46) && (flag == 1))
 

Thread Starter

swinch

Joined Jan 24, 2010
5
You Rock, :D
I can't believe I made such a stupid mistake, that fixes it all!
I can now get all 3 PWMs to work with the joystick.
Thanks
Steve
:D
 
Top