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

Back to Subject List

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


 
#41248 - RE: Serial ISR problems
Responding to: ???'s previous message
Jeffery:

I have a number of comments regarding your serial I/O code.

First of all you have the serial interrupt vector performing an LJMP to the Ser_ISR routine followed by the RETI. This RETI will never be executed. Either change the LJMP to an LCALL or instead replace the RET at the end of the Ser_ISR with the RETI. I recomment the latter because it saves a level on the stack.

Secondly you have the code inside Ser_ISR that handles the receive function usint R0 and R7 registers which are nowhere initialized. You should have set these up someplace. Now it is my opinion that it is bad practice to use registers inside the ISR that are expected to be setup outside the scope of the interrupt service routine. Therefore you should keep the buffer for the receive pointer in a internal memory variable instead and then load R0 from this variable. After the MOV @R0 it seems to me that you would need to increment R0 to the next buffer location and store the updated buffer pointer back to the variable. You should also be pushing the R0 register value that you came into this routine with so that if that register was in use in the mainline program it does not get destroyed. Alternatively you could allocate an alternate register bank exclusively to the serial interrupt context.

At the end of the receive section of Ser_ISR you are branching to the exit point of the routine. It seems to me that it would be efficient to immediately drop through to the TX handler section and check the TI flag before exiting. Both the RI and TI flags could be set and at higher baud rates it is a very good idea to service both pending interrupts is they are set while already inside the interrupt routine.

At the start of the TX portion of the Ser_ISR routine you are blindling assuming that the TI flag was set and you are clearing it. It is way better to first check if TI is set and then clear it.

In your piece of main line "test code" you are using the flag SENT in a manner that I find curious. It seems very strange to me that you would go to the work of handling the TI bit in the interrupt routine and then mimicing the state of that bit to the SENT bit. If you intend to literally poll the send function from then mainline code it is more efficient to remove the TI bit handling in the Ser_ISR routine and simply have the mainline code operate on the TI bit instead of the SENT bit.

Normally one sets up interrupts on the serial port to support a kind of disconnect between the main line code and the serial RX and TX functions. As such a conventional scheme is to implement queues on the serial port. I have some sample UART handling code that demonstrates the use of queues which you could Download From Here. This code is in C and is for a Cygnal derivative so sone of the SFR addresses are a bit different and the baud rates are set slightly different. I will have my C compiler convert this code to assembly language source for you as well. I will post a link to that in a second post to this thread.

Michael Karas


List of 5 messages in thread
TopicAuthorDate
Serial ISR problems            01/01/70 00:00      
   RE: Serial ISR problems            01/01/70 00:00      
   RE: Serial ISR problems            01/01/70 00:00      
   RE: Serial ISR problems            01/01/70 00:00      
      RE: Serial ISR problems            01/01/70 00:00      

Back to Subject List