gnupic: TXIF flag not set after TXEN - bug in gpsim?


Previous by date: 31 Jul 2001 20:02:02 -0000 Re: gpasm-0.9.10 (processor #define case), John Rehwinkel
Next by date: 31 Jul 2001 20:02:02 -0000 Re: TXIF flag not set after TXEN - bug in gpsim?, Scott Dattalo
Previous in thread:
Next in thread: 31 Jul 2001 20:02:02 -0000 Re: TXIF flag not set after TXEN - bug in gpsim?, Scott Dattalo

Subject: TXIF flag not set after TXEN - bug in gpsim?
From: Wojciech Zabolotny ####@####.####
Date: 31 Jul 2001 20:02:02 -0000
Message-Id: <20010731220157.A2940@wzab.nasz.dom>

Hi GPSIM users & developers,

I've faced a problem when using the GPSIM with my USART routines.
It seems, that TXIF is set incorrectly by gpsim.
AFAIK this flag should be set, whenever the TXREG is empty.
Particularly, setting the TXEN to start the transmitter should set
the TXIF flag. 
Below is the text quoted from Microchip's "33023a.pdf" (page 345)

"...
Steps to follow when setting up a Asynchronous Transmission:
1. Initialize the SPBRG register for the appropriate baud rate.
 If a high speed baud rate is desired, set the BRGH bit.
 (Subsection 18.3  USART Baud Rate Generator (BRG)  )
2. Enable the asynchronous serial port by clearing the SYNC bit
   and setting the SPEN bit.
3. If interrupts are desired, then set the TXIE, GIE and PEIE bits.
4. If 9-bit transmission is desired, then set the TX9 bit.
5. Enable the transmission by setting the TXEN bit, which will also
   set the TXIF bit.
6. If 9-bit transmission is selected, the ninth bit should be loaded
   in the TX9D bit.
7. Load data to the TXREG register (starts transmission).
..."

Basing on this description, I tried to implement my own interrupt
driven serial routines, working in that way:
a) The TX interrupt handler checks the serial transmission buffer
  - If there is character to be sent, it takes the character from the
    serial buffer and places it in the TXREG.
  - If the serial buffer is empty, the TX interrupt handler clears
    the TXIE bit
b) The serial_send routine places the character in the buffer and sets
   the TXIE bit

Unfortunately this method doesn't work (at least in GPSIM), because in
GPSIM the TXIF gets set only after the transmission gets finished
(not when TXREG is empty, but when TXREG GETS empty), so after the
initialization of USART TXIF is cleared, until the first character
is transmitted.
Unfortunately at the moment I have no possibility to verify it in the
hardware. But it is either error in 16F877 documentation or bug in GPSIM.

I attach two maximally simplified code samples to illustrate the problem.
They should be compiled with gpasm:
$ gpasm serial.asm
$ gpasm serial2.asm
And then run with 
"gpsim -c serial.stc" or "gpsim -c serial2.stc", and then pressing
the "run" button.
In the serial.asm we never reach the breakpoint - the TXIF is never
set. In serial2.asm, after the transmission is finished, we get to the 
breakpoint set in the interrupt handler.

I'd like to know, if the GPSIM there reflects the behaviour of the
 true 16f877? (so there is bug in Microchip's doc)
Or if there is a bug in GPSIM?
-- 
			TIA & Regards,
			Wojciech Zabolotny
			####@####.####



	list	p=16f877 
	#include <p16f877.inc>
	org	0
	goto	start
	org	4
tx_int	nop	
	goto	$ ;don't do anything, just loop (I'll set the breakpoint above)
start	bcf	STATUS,RP1
	bsf	STATUS,RP0 ; bank 1
	movlw	0xc0
	movwf	TRISC
	bsf	TXSTA,BRGH
	movlw	0x01
	movwf	SPBRG
	bcf	STATUS,RP0 ; bank 0
	movlw	(1<<SPEN)
	movwf	RCSTA	
	bsf	STATUS,RP0
	clrf	PIE1
	clrf	PIE2
	bsf	PIE1,TXIE ; bank 1
	movlw	(1<<GIE)|(1<<PEIE)
	movwf	INTCON	
	bsf	TXSTA,TXEN ; now the TXIF should get set,
			   ; and we should go to tx_int
			   ; but in fact we will loop in the "goto" below :-(
	goto	$
	end

	list	p=16f877 
	#include <p16f877.inc>
	org	0
	goto	start
	org	4
tx_int	nop	
	goto	$ ;don't do anything, just loop (I'll set the breakpoint above)
start	bcf	STATUS,RP1
	bsf	STATUS,RP0 ; bank 1
	movlw	0xc0
	movwf	TRISC
	bsf	TXSTA,BRGH
	movlw	0x01
	movwf	SPBRG
	bcf	STATUS,RP0 ; bank 0
	movlw	(1<<SPEN)
	movwf	RCSTA	
	bsf	STATUS,RP0
	clrf	PIE1
	clrf	PIE2
	bsf	PIE1,TXIE ; bank 1
	movlw	(1<<GIE)|(1<<PEIE)
	movwf	INTCON	
	bsf	TXSTA,TXEN 
	;now we transmit a 0x65 character, so after the transmission
	;is finished, TXIF gets set and the tx_int gets executed.
	bcf	STATUS,RP0 ; bank 0
	movlw	0x65
	movwf	TXREG
	goto	$
	end

# Script for testing modules
#
# The purpose of this script is to load a simple
# program for a PIC, load the gpsim module library,
# and illustrate how modules can be connected to pics.

set verbose 1
load s serial.cod
set verbose 0

break e tx_int

# Script for testing modules
#
# The purpose of this script is to load a simple
# program for a PIC, load the gpsim module library,
# and illustrate how modules can be connected to pics.

set verbose 1
load s serial2.cod
set verbose 0

break e tx_int

Previous by date: 31 Jul 2001 20:02:02 -0000 Re: gpasm-0.9.10 (processor #define case), John Rehwinkel
Next by date: 31 Jul 2001 20:02:02 -0000 Re: TXIF flag not set after TXEN - bug in gpsim?, Scott Dattalo
Previous in thread:
Next in thread: 31 Jul 2001 20:02:02 -0000 Re: TXIF flag not set after TXEN - bug in gpsim?, Scott Dattalo


Powered by ezmlm-browse 0.20.