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


[<<] [<] Page 1 of 1 [>] [>>]
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
Subject: Re: TXIF flag not set after TXEN - bug in gpsim?
From: Scott Dattalo ####@####.####
Date: 1 Aug 2001 06:31:41 -0000
Message-Id: <Pine.LNX.4.33.0108010056570.6313-100000@tempest.blackhat.net>


On Tue, 31 Jul 2001, Wojciech Zabolotny wrote:

> 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)

<snip>

>
> 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?

What? A bug in gpsim?

Yep

Fixed in gpsim-0.20.10

http://www.dattalo.com/gnupic/gpsim-0.20.10.tar.gz
http://www.dattalo.com/gnupic/gpsim-0.20.10-1.i386.rpm

Scott

Subject: Re: TXIF flag not set after TXEN - bug in gpsim?
From: Wojciech Zabolotny ####@####.####
Date: 1 Aug 2001 10:47:06 -0000
Message-Id: <20010801123909.A27834@ipebio15.ise.pw.edu.pl>

On Wed, Aug 01, 2001 at 01:39:35AM -0500, Scott Dattalo wrote:
> 
> Fixed in gpsim-0.20.10
> 

Sorry for beeing boring, but TXIF still (gpsim-0.20.10) works in
a strange way.
After the initialization the TXIF gets set, but if the TXIE
is cleared, when the transmission finishes, TXIF remains clear
"forever" (in fact until someone sends the character with TXIE set).

Additionally the TXIF does not get cleared when TXREG is written:
Quoted from 33023a.pdf (page 130)
"...
bit TXIF: USART Transmit Interrupt Flag bit
   1 = The USART transmit buffer, TXREG, is empty (cleared when TXREG is written)
   0 = The USART transmit buffer is full
..."
In gpsim the TXIF must be cleared with software.
In the description of some interrupt flags (eg. ADIF) there is a note "must
be cleared in software", but not in dexription of TXIF.

-- 
				TIA & Regards,
	                      Wojciech M. Zabolotny
	http://www.ise.pw.edu.pl/~wzab  <--> ####@####.####

http://www.ise.pw.edu.pl/~wzab/codmpasm  If you want to use MPASM with GPSIM
[<<] [<] Page 1 of 1 [>] [>>]


Powered by ezmlm-browse 0.20.