Editing BoostC Forum Extracts 2007

Jump to navigation Jump to search

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.

Latest revision Your text
Line 641: Line 641:
  
 
As you can see my interrupt routine is heavily loaded. What i need to know is if i use the emulated(software) usart will the transmitted data get corrupted due to extended soft ware delay(due to interrupts), which is used to generate the baud rate ?
 
As you can see my interrupt routine is heavily loaded. What i need to know is if i use the emulated(software) usart will the transmitted data get corrupted due to extended soft ware delay(due to interrupts), which is used to generate the baud rate ?
 +
 +
 +
Not if you intelligently use priority interrupts or alternativly give NOVOS a spin.
 +
 +
 +
--------------------
 +
Good intentions always exist, intelligent thought patterns ... not quite as much
 +
 +
Not if you intelligently use priority interrupts or alternativly give NOVOS a spin.
 +
 +
 +
No priority interrupts, I am using pic16f877. I am talking about software usart and so it does not generate any interrupt ( for that matter i think even the hw uart lib of source boost does not generate interrupt, but does a software polling of the interrupt or status flags( the rx & tx interrupt enable bits are cleared). I don't want to use my own routine. If i use the SB lib i have the advantage of handling strings ,ascii etc with ease( i suppose, i haven't tried).
 +
 +
 +
 
 +
 +
 +
 +
QUOTE (ra68gi @ May 28 2007, 06:19 AM)
 +
QUOTE (emte @ May 28 2007, 10:19 AM)
  
 
Not if you intelligently use priority interrupts or alternativly give NOVOS a spin.
 
Not if you intelligently use priority interrupts or alternativly give NOVOS a spin.
 +
  
 
No priority interrupts, I am using pic16f877. I am talking about software usart and so it does not generate any interrupt ( for that matter i think even the hw uart lib of source boost does not generate interrupt, but does a software polling of the interrupt or status flags( the rx & tx interrupt enable bits are cleared). I don't want to use my own routine. If i use the SB lib i have the advantage of handling strings ,ascii etc with ease( i suppose, i haven't tried).
 
No priority interrupts, I am using pic16f877. I am talking about software usart and so it does not generate any interrupt ( for that matter i think even the hw uart lib of source boost does not generate interrupt, but does a software polling of the interrupt or status flags( the rx & tx interrupt enable bits are cleared). I don't want to use my own routine. If i use the SB lib i have the advantage of handling strings ,ascii etc with ease( i suppose, i haven't tried).
 +
  
 
Use the hardware UART, problem solved.
 
Use the hardware UART, problem solved.
Line 664: Line 686:
 
The rest of the code to handle the actual data at your leisure would be inside your main.
 
The rest of the code to handle the actual data at your leisure would be inside your main.
  
 
+
CODE
void interrupt(void)
+
void interrupt(void)
{
+
{
 
     if(txif)    /* Transmit interrupt flag - triggers when empty */
 
     if(txif)    /* Transmit interrupt flag - triggers when empty */
 
     {
 
     {
Line 682: Line 704:
 
         txif = 0;
 
         txif = 0;
 
     }
 
     }
 
+
 
 
     if(rcif)    /* rx interrupt */
 
     if(rcif)    /* rx interrupt */
 
     {
 
     {
Line 689: Line 711:
 
         rcif=0;
 
         rcif=0;
 
     }
 
     }
}
+
}
 +
 
 +
 
 +
 
 +
 
 +
QUOTE (emte @ May 28 2007, 01:48 PM)
 +
CODE
 +
void interrupt(void)
 +
{
 +
   
 +
    if(rcif)    /* rx interrupt */
 +
    {
 +
        _rxCapture[_rxCount] = rxreg;    /* capture values until we are done */
 +
        _rxCount++;    /* array storage is easier to extract data from - redundancy, CRC. etc */
 +
        rcif=0;
 +
    }
 +
}
  
  
Line 703: Line 741:
  
 
To extract a character from the buffer: new_char = rxCapture(tail++); if (tail >= buffer_size) tail = 0;  
 
To extract a character from the buffer: new_char = rxCapture(tail++); if (tail >= buffer_size) tail = 0;  
 +
  
 
Clearing the RCIF flag is handled automatically when the rxreg is read. Clearing it manually (as shown above) can result in character loss in race conditions (don't do it). The PIC is brain dead with respect to its asynchronous port, in the event of an overrun error (not clearing the RXREG before the next character is received) the PIC disables the asynchronous receive logic - to avoid this problem the receive interrupt handler needs to check the error status and in event of error it needs to disable and immediately reenable the receive logic.
 
Clearing the RCIF flag is handled automatically when the rxreg is read. Clearing it manually (as shown above) can result in character loss in race conditions (don't do it). The PIC is brain dead with respect to its asynchronous port, in the event of an overrun error (not clearing the RXREG before the next character is received) the PIC disables the asynchronous receive logic - to avoid this problem the receive interrupt handler needs to check the error status and in event of error it needs to disable and immediately reenable the receive logic.
 +
  
 
This is true, but also flawed in quite a lot of Microchip's silicon. There is a lot of errata stating that reading does not always clear the flag.  As for the potential race condition, in practice i have yet to see it even when using baudrates in excess of 115.2k.
 
This is true, but also flawed in quite a lot of Microchip's silicon. There is a lot of errata stating that reading does not always clear the flag.  As for the potential race condition, in practice i have yet to see it even when using baudrates in excess of 115.2k.
  
 
Depending on which family of devices your using the USART will disable after the second or third level buffers are full, but the interrupt flag will still be enabled.
 
Depending on which family of devices your using the USART will disable after the second or third level buffers are full, but the interrupt flag will still be enabled.
 +
  
 
Error checking is essential for any protocol, but is a bit advanced for someone trying to figure out the basics of using the USART.
 
Error checking is essential for any protocol, but is a bit advanced for someone trying to figure out the basics of using the USART.
  
I disagree. Lockup of the PIC's USART is a common trap for newbies - they waste a lot of time chasing phantom problems.
+
I disagree. Lockup of the PIC's USART is a common trap for newbies - they waste a lot of time chasing phantom problems.  
 +
 
  
 
== nn3turntable ==  
 
== nn3turntable ==  

Please note that all contributions to OpenCircuits may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see OpenCircuits:Copyrights for details). Do not submit copyrighted work without permission!

Cancel Editing help (opens in new window)