MC908SAW32 SCI problem

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

MC908SAW32 SCI problem

1,899 Views
gambler
Contributor I
Hi,
 
I'm a beginner to 908saw32. I wish to use interrupt for transmit and receive data through SCI and
I'm using half duplex (2 wire) max485.
 
SCI initialization
 
SCI1BDH = $00
SCI1BDL = $80        
SCI1C2 = $6C (Enable TC,RIE,RE,TE)
 
ISR for the transmit interrupt:
 
SCI1_TX       PSHA
              PSHH
              PSHX
              LDA       SCI1S1          ;clear TC
              LDA       TX_BUF
              BEQ       TX_QUIT
             STA       SCI1D           ;clear TC and send byte
             CLRA
             STA       TX_BUF
             BRA       TX_QUIT
 
TX_QUIT       LDA       #%00101100     ;Disable transmit interrupt
             STA       SCI1C2
             BCLR      MAX485,PORTC   
             PULX
             PULH
             PULA
             RTI

I try to send ascii character a,b,c,d,e,f,g in sequence to hyperterminal, but there is data lost for the transmission. For example, i get a,f,g,b.....

Is there anything wrong with this code??
Plz help....

 
Labels (1)
0 Kudos
4 Replies

433 Views
peg
Senior Contributor IV
Hi gambler,
 
For starters, there is no need to push/pull A and X as this is an ISR it is automatically done.
 
The line BRA TX_QUIT is superfluous as it will fall through to there anyway.
 
Instead of CLRA then STA TX_BUF how about CLR TX_BUF?
 
Instead of LDA #%00101100 then STA SCI1C2 how about BCLR 6,SCI1C2 or for even further improvement in readability BCLR TCIE,SCI1C2 (assuming TCIE is equated to 6).
 
OK, now that it is simplified and tidied up I don't see any actual problem with the code presented.
I think the main problem is the concept. It appears your main loop has to load the next char into your one byte buffer and this is probably where you fallover.
 
The more normal case would be to load an indexed buffer with the whole string to be sent.
Then the ISR can walk through the buffer without any timing issues between the two tasks.
Also more normal would be to use TDRE interrupts to load the characters into the SCID then change to
TC checks when string done just to turn off the TXENA.
 
As you look like you need the practice I will let you have another attempt before I 'give' you the code.
 
 
0 Kudos

433 Views
gambler
Contributor I
Hi Peg,
 
Thanks for your advice. I have change the code and it's working now. I did not use index buffer because this is just a simple test code for me to grab the concept.
 
SCI1_TX        LDA      SCI1S1
              LDA      TX_BUF
              BEQ      TX_ACK
              STA      SCI1D
              CLRA
              STA      TX_BUF
TX_ACK         BCLR     TIE,SCI1C2      
              BRCLR    TC,SCI1S1,*
              BCLR     TXEN,PORTC
              RTI
As for the CLRA,STA TX_BUF, I did not use CLR TX_BUF because TX_BUF has an extended address.
 
Is there anyway to REPLACE the   " BRCLR TC,SCI1S1,* "    in the code? 
I want to run other routines instead of waiting for the end of transmission.
 
 
0 Kudos

433 Views
peg
Senior Contributor IV
Hi gambler,
 
OK, fair enough! As for the loop waiting for TC to drop TX enable:
Just flag that the transmission is finished in the ISR, then in your main loop look for this flag then TC and then cancel TX enable. This doesn't waste time (especially within an ISR) but you have to be careful that the other end does not want to respond very quickly after the tx from here. Buss contention!
 
Also, you have deleted the push/pull of H. Be wary of this that you don't modify H (even unintentionally) within the ISR if you are going to not do this.
 
 

Message Edited by peg on 2007-02-1404:49 PM

0 Kudos

433 Views
gambler
Contributor I
Hi Peg,
 
Thanks a lot. Your advise is very helpful to me. Thanks again. :smileyhappy:
0 Kudos