CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

#int_tbe problem

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
ritchie



Joined: 13 Sep 2003
Posts: 87

View user's profile Send private message

#int_tbe problem
PostPosted: Wed Mar 10, 2004 7:57 am     Reply with quote

Hello,

I have an RS485 system wherein PIN_A1 controls the transmit enable of the MAX485 chip. My concern is that when I check the waveform of my transmit signal it lost one character.. this simply means that PIN_A1 control pin goes low earlier.

How can I resolve this? I use interrupt for transmission and I don't want to use delay on the system. I need your help, suggestions of what algorithm should fit.

Thanx
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

PostPosted: Wed Mar 10, 2004 8:32 am     Reply with quote

I have been using a timer to detect when reception is complete because the pause between bytes has a maximum. I load a timer after each incomming byte. If the timer expires the packet is finished. For transmition I do almost the same thing but instead of setting a flag to decode the packet I turn off the transmit hardware. You can look at the serial file in my home folder that shows this for recieving. It was written for 232 so it is not exactly what you seek but should help you find inspiration.
Ttelmah
Guest







Re: #int_tbe problem
PostPosted: Wed Mar 10, 2004 8:38 am     Reply with quote

ritchie wrote:
Hello,

I have an RS485 system wherein PIN_A1 controls the transmit enable of the MAX485 chip. My concern is that when I check the waveform of my transmit signal it lost one character.. this simply means that PIN_A1 control pin goes low earlier.

How can I resolve this? I use interrupt for transmission and I don't want to use delay on the system. I need your help, suggestions of what algorithm should fit.

Thanx

If I read you correctly, you are setting the TXE, when you first have data available, and then clearing it when the last byte is transferred to TXREG. At this point the problem is that the transmit shift register still contains this byte 'in transit'. You have to consider three possible solutions:
1) External timer - a retriggerable monostable on the TXE line can hold it for a period after you release it in software.
2) Internal delay/timer. Remember you can use an interrupt driven hardware timer. Program this for the character time, when you have no more data to send, and then reset the TXE when this triggers. This removes the need to wait in code.
3) Have the main loop check the transmit shift register status, at intervals, and if it is empty, drop the TXE line.

Best Wishes
Gerrit



Joined: 15 Sep 2003
Posts: 58

View user's profile Send private message

PostPosted: Wed Mar 10, 2004 8:52 am     Reply with quote

Richie,

Send a copy of your TBE interupt handler this would be easy to answer
your question.

possible :

Depending on the receiver side you can just send a dummy character at the end, or check in your main loop if the TX buffer is empty (TRMT bit).



Gerrit
ritchie



Joined: 13 Sep 2003
Posts: 87

View user's profile Send private message

PostPosted: Wed Mar 10, 2004 5:20 pm     Reply with quote

Gerrit wrote:
Richie,

Send a copy of your TBE interupt handler this would be easy to answer
your question.

possible :

Depending on the receiver side you can just send a dummy character at the end, or check in your main loop if the TX buffer is empty (TRMT bit).



Gerrit


Code:

#int_tbe
void RS485_TXisr() // RS485 transmission interrupt routine
{
   // put RFid & keypress data to TX buffer then send?
   //fputc(*(TXbuffer+TXout),RS485Com);
   TXREG = *(TXbuffer+TXout);
   TXout++;                           // increment TX OUT index
   TXout = (TXout) % TX_SIZE;         // limit to max buffer size

   if (TXin == TXout)                 // if last in data, stop RS485 TX?
   {
      disable_interrupts(int_tbe);    // stop TX interrupt
      RS485_RCV();  // received mode enabled
      TXin  = 0;    // reset TX data IN index
      TXout = 0;    // reset TX data OUT index
      glTXpnd = 0;  // reset TX pending flag
   }
}

Gerrit



Joined: 15 Sep 2003
Posts: 58

View user's profile Send private message

PostPosted: Wed Mar 10, 2004 6:03 pm     Reply with quote

Hi ritchie,

If you also read the answer of Ttelmah you see the same solution.

If you read specs of usart you find that when the TXREG register gets
empty you get an interrupt, but when TXREG get empty the data is
transfered to the TSR register. Now the compleet character has to be transmitted so you have to start an timer for the time of one character,
or you have to check in your main loop for the TRMT bit. when this bit is
set the real TX buffer is empty.

Good luck

Regards,


Gerrit
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group