Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
03/06/03 10:50
Read: times


 
#40886 - First x bits missing from serial string
Hi all

I have a problem with my serial routine, basically the first byte that I send out the port loses either one or 2 of the MSBits of the 1st byte, the rest of the string is OK. The correct string pops out about every third message. I am sending a message out every 500mSec. (actually I am replying to a poll message that occurs every 500mSecs)

I thought that it may have been the RS485 chip not enabling quickly enough but a delay to allow the chip to enable did not work either.

The only other thing that I have in the application is a 10mSec interrupt (occurs every 10mSecs) as I sync with the mains but I would assume that it should go and do its thing and then come back and finish sending the string if it was interrupted during the sending of the message, and then you would still expect the framing error to occur anywhere within the message not always the same byte.

Here is an example of the reply strings from the µController

Should be -> EE 11 17 01 00 00 22 BF
Actually -> B8 11 17 01 .........
and -> DC 11 17 01 .........

Here is the code I am using to send the message, (I know the formatting will come out all mucked up when I post it but you may get the idea)

Thanks for any tips

Regards
Marshall Brown

//------------------------------------------------------------------------------------------------------------------------------------ //
// //
// Sends a byte to the transmit buffer and then resets the TI interrupt //
// this also handles the TX enable on the RS485 Chip and implements a delay //
// after the byte has been sent before diabling the TX enable on the RS485 //
// this is because I found that I was disabling the RS485 chip before the entire //
// byte had been sent //
// //
//------------------------------------------------------------------------------------------------------------------------------------ //

void SendByte(byte datatosend)
{
while( !TI ); // Wait until TI is set
TI = 0; // Now clear it
SBUF = datatosend; // And send byte
}




//------------------------------------------------------------------------------------------------------------------------------------ //
// //
// Sends the entire frame to the serial port, It is also hangs around until //
// the serial port does not have any data on it (see notes below on how this is achieved) //
// //
//------------------------------------------------------------------------------------------------------------------------------------ //
void SendFrame()
{

char i;
//OK B4 we just jump in and send our data onto the bus it would be a good idea to
//ensure that no one else is actually using it, to do this I have implemented a 555 timer
//that is Logic 1 when it is receiving data (ie when we are not allowed to send) this also
//has a 2mSec safety margin built in (more or less) so we don't have to daly any further
//when the line flicks back to 0
//so what we can do is then is wait until the input (OKtoSend) is Low then spit out our data

//This line is not reqd on a poll & respond system as these device are only ever responding
//so bus contention should ever occur




while (OKtoSend == BusBusy) //stays in this loop until the bus is cleared
{
VariableDelay(TL0); //just grab whatever the value of the timer currently is
//to generate a psudo random number for a delay
}

ModuleStatus = ACTIVE;
TI=1;
RS485State = TX; //Enable the RS485 Driver


//VariableDelay(10); //Hang around a bit before sending data as I was losing the 1st 2 odd bits because the 485
//chip wasn't turned on i suspect (400 = 4.697mSec)

SendByte(frame.SystemAddress);
SendByte(frame.DestinationAddress);
SendByte(frame.SourceAddress);
SendByte(frame.FunctionCode);
SendByte(frame.Length);

for (i =0; i< frame.Length+1; i++)
SendByte(frame.FrameData[i]);


//now that the CRC is a real 16 bit CRC we have to split the
//CRC into 2bytes as the sendbyte function will only send a byte at a time
//we can do this by bit shifting

//Loads the temp variable with the Most Significant Byte (to send it out Last)
SendByte (frame.Crc >> 8);

// shifts the last byte to the function
SendByte (frame.Crc);


TI=0;
VariableDelay(200); //Hang around a bit before turning driver off (400 = 4.697mSec)
RS485State = RX; //Turn the driver into Receive mode
ModuleStatus = INACTIVE;

}



void SerialInterrupt (void) interrupt 4
{
if (RI)
{
RxByte = SBUF;
RI = 0; //Clear the Interrupt Flag
DataInBuffer =1;
}

}


List of 9 messages in thread
TopicAuthorDate
First x bits missing from serial string            01/01/70 00:00      
   RE: First x bits missing from serial string            01/01/70 00:00      
      RE: First x bits missing from serial str            01/01/70 00:00      
   RE: First x bits missing from serial str            01/01/70 00:00      
   RE: First x bits missing from serial string            01/01/70 00:00      
   RE: First x bits missing from serial string            01/01/70 00:00      
   RE: First x bits missing from serial string            01/01/70 00:00      
   Fixed it            01/01/70 00:00      
   RE: First x bits missing from serial string            01/01/70 00:00      

Back to Subject List