Forum Menu




 


Log in Problems?
New User? Sign Up!
AVR Freaks Forum Index

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
SwarfEye
PostPosted: Jul 19, 2012 - 08:46 PM
Hangaround


Joined: Jan 08, 2006
Posts: 201
Location: San Francisco, CA

So, I've got my usart speaking modbus decently well thanks to the help of you all on the board.

But periodically the usart seems to hang. Here is my code...

Code:

void modbusSendOutputFrame ( cBuffer *buffer )
{   
      PORTB |= (1 << PB0);  // Send RTS high
         
      while (outBuffer.datalength > 0 )
      {
         //Wait for an empty transmit buffer
         while ( !(UCSR0A & (1 << UDRE0 )) );
         
         UDR0 = bufferGetFromFront( &outBuffer );
      }
      
       //Spin for a bit until the USART is done transmitting
      while ( ! (UCSR0A & ( 1 << TXC0 ) ) );
      
      UCSR0A |= ( 1 << TXC0 );  // clear TXCO

      PORTB &= ~(1 << PB0);  // Transmission complete.  Send RTS low
}


For some reason the program gets stuck on this line...

Code:
      //Spin for a bit until the USART is done transmitting
      while ( ! (UCSR0A & ( 1 << TXC0 ) ) );



The way I know this is that I run the program in debug mode with the jtag. It runs fine for a while, but then begins to hang completely. Once it is hung, I pause the program execution with the debugger, and we always end up on that line.

It appears that TXCO is not going high.

After I pause the program, I add a breakpoint to the next line, and start execution again, but we seem to stay forever stuck waiting on TXC0.

What am I doing wrong?

Thanks,

Bill
 
 View user's profile Send private message  
Reply with quote Back to top
Koshchi
PostPosted: Jul 19, 2012 - 10:28 PM
10k+ Postman


Joined: Nov 17, 2004
Posts: 13815
Location: Vancouver, BC

Can the function ever be called when outBuffer.datalength is 0? If so, then you will be waiting for the UART to finish transmitting when you never transmitted anything to begin with.

_________________
Regards,
Steve A.

The Board helps those that help themselves.
 
 View user's profile Send private message  
Reply with quote Back to top
SwarfEye
PostPosted: Jul 20, 2012 - 04:14 PM
Hangaround


Joined: Jan 08, 2006
Posts: 201
Location: San Francisco, CA

Right on. Thank you.

I'm really never supposed to be calling that function when the buffer.datalength == 0, but I put in a little catch for that, and my hanging problem went away!

Now I've got to figure out why my function is getting called when I've got buffer.datalength == 0!

Thanks again.

Bill
 
 View user's profile Send private message  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT + 1 Hour
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2006 The PNphpBB Group
Credits