We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi, I have a 24 byte tx buffer. When i send the buffer from a uM to pc in a polled manner, timer 2 works fine with the following setting: mov SCON, #01010000b mov RCAP2L, #0DCh mov RCAP2H, #0FFh mov T2CON, #00110100b but if i try to use serial interrupt (to receive some chars and do some other calculations) then the send is hanged after the 1st char.... my send codes are (with 30h as the beginning of the tx buffer): Send: mov R0, #30h Main: clr TI mov SBUF, @R0 Wait: jnb TI, Wait inc R0 cjne R0,#48h, Main However, if the baudrate was set by using timer 1 then the code will work fine....timer 1 setting: mov TMOD,#20h mov PCON,#80h mov TH1,#250 mov TCON,#40h mov SCON,#50h what was wrong?? pls help, thanks!! I use a 11.0592 xtal set to generate a baud of 9600. My code which works with timer1 is (but not when timer2 was used): .equ TxNow, 01h .equ StackBase,50h .ORG 0 ajmp Init .ORG 23h ajmp SerInt ;[]------------------------[] ;| Interrupt Routines | ;[]------------------------[] SerInt: push PSW push ACC push 00h jbc TI,SerOut jbc RI,SerRx SerRx: mov P0,SBUF SerOut: pop 00h pop ACC pop PSW reti CheckRdy: mov A,P0 cjne A,#'U',cTxNow setb TxNow mov P0,#0h ret cTxNow: clr TxNow ret ;[]------------------------[] ;| Setup | ;[]------------------------[] Init: mov TMOD,#20h mov PCON,#80h mov TH1,#250 mov TCON,#40h mov SCON,#50h setb ES setb EA ;[]------------------------[] ;| Main Program | ;[]------------------------[] mov 30h, #'H' mov 31h, #'e' mov 32h, #'l' mov 33h, #'l' mov 34h, #'o' mov 35h, #'!' mov 36h, #' ' mov 37h, #'T' mov 38h, #'x' mov 39h, #'R' mov 3Ah, #'x' mov 3Bh, #' ' mov 3Ch, #'s' mov 3Dh, #'u' mov 3Eh, #'c' mov 3Fh, #'c' mov 40h, #'e' mov 41h, #'s' mov 42h, #'s' mov 43h, #'!' mov 44h, #' ' mov 45h, #':' mov 46h, #')' mov 47h, #' ' Main1: lcall CheckRdy jnb TxNow, Main1 jbc TxNow, Send Send: mov R0, #30h Main: clr TI mov SBUF, @R0 Wait: jnb TI, Wait inc R0 cjne R0,#48h, Main clr TxNow ajmp Main1 .END When timer2 was used, it would just hang after sending 'H'.....
You seem to be clearing TI in your serial ISR and also waiting for it to become set in your main loop. I think this is why your program gets stuck. Why it might work using a different timer to generate the baudrate I have no idea. Stefan