| ??? 02/06/00 07:39 Read: times |
#1396 - Interrupt driven serial 2 on 80C320 |
I need to use both serial ports on the 80c320, to realize a number of industrial controls.
I've a card on which the 320 works ok, but there is a problem. If I enable the interrupt on serial port 0, the interrupt on serial port 1 is not serviced. Note that if I disable the interrupt on serial 0, the serial 1 works ok. It seems that serial 0 interrupt locks the serial 1 interrupt. I need to operate the ports at different baud rate, and it works, because I used timer 2 on serial 0 and timer 1 on serial 1, even if I found that timer 1 runs strange in this case, because I can't make it work well with SMOD=1 to double the baud rate. Why? Back to interrupt problems: I tried also to increase the priority on serial 1 interrupt, but the software seems to lock. Please note that serial 0 works well with or without serial 1 interrupt on, while serial 1 works only with serial 0 interrupt disabled, I believe that the vectoring and related procedures were ok. I include a piece of code, to show how I managed the stuff. What I need, now, is a source code showing both serial ports working simultaneously, at different baud rates, receiving with interrupt and trasmitting when needed. I hope you can help me, because I must deliver the cards in a few days! I red 80c320.pdf, AN75 and related documents you have online, without finding anything useful for my problem. Another question: i tried to speed up the timers turning on the related bit (T0M, T1M, T2M), but it seems to have no effect. Why? HELP ME, PLEASE! Maurizio Dagradi P.S. It's sunday and I'm working on the 320, trying to solve these problems, so have mercy and help me, please! cseg ; Boot ed interrupts. --------------------------------------------------------- boot_org equ 0h org boot_org ; Boot. jmp main org boot_org + 3 ; Interrupt su INT0. jmp gest_int0 org boot_org + 13h ; Interrupt su INT1. jmp gest_int1 org boot_org + 0bh ; Interrupt da timer 0. jmp tmr0 org boot_org + 23h ; Interrupt da porta seriale. jmp int_porta_ser org boot_org + 3bh ; Interrupt da porta seriale 2. jmp int_porta_ser2 ; ----------------------------------------------------------------------------- ; Main. org boot_org + 100h main: init: ; Azzeramento ingressi, uscite, timers ecc. clr sdo clr sck clr cs1 clr cs2 clr cs3 clr en_ser mov r0, #di init1: mov @r0, #0 inc r0 cjne r0, #0ffh, init1 mov pres_0, #vpres0 ; Setup prescalers. mov pres_1, #vpres1 mov scon, #01000000b ; Seriale: modo 1. mov scon1, #01000000b ; Seriale 2: modo 1. setb ren ; Abilitazione ricezione. setb ren1 ; Abilitazione ricezione porta seriale 2. setb ti ; Indicazione di registro di ; trasmissione vuoto. setb ti1 ; Indicazione di registro di ; trasmissione vuoto porta seriale 2. mov pcon, #10000000b ; Seriale: smod = 1. clr sm0fe1 ; Seriale 2: smod1 = 0. mov tcon, #10000000b ; Setup timer 1. mov tmod, #00100010b ; Timer 0 e timer 1 8-bit auto-reload. mov th0, #-201 ; Valore reload per timer 0. mov ie, #10000000b ; Interrupts abilitati individualmente. setb et0 ; Interrupt su overflow timer 0. ; setb int0 ; Settaggio INT0 per gestione interrupt. ; setb it0 ; Interrupt INT0 su falling edge. ; setb ex0 ; Interrupt su INT0. ; setb int1 ; Settaggio INT1 per gestione interrupt. ; setb it1 ; Interrupt INT1 su falling edge. ; setb ex1 ; Interrupt su INT1. ; setb es ; Interrupt su porta seriale. setb es1 ; Interrupt su porta seriale 2. orl ip, #00000000b mov th1, #0fah ; Valore reload per timer 1: 9600 bit/s di default. mov rcap2h, #high(65500) ; Valore reload per timer 2: 9600 bit/s di default. mov rcap2l, #low(65500) ; " " " mov psw, #00000000b ; Banco registri 0. mov sp, #BaseStack ; Stack. setb tr0 ; Partenza timer 0 (tick interrupt). setb tr1 ; Partenza timer 1 (generatore di baud ; rate). setb tr2 ; Partenza timer 2 (generatore di baud ; rate). ; Timer 1 usato per COM2 (seriale 1 = RS485). ; Timer 2 usato per COM1 (seriale 0 = RS232). setb rclk ; Timer 2 usato per ricezione su COM1. setb tclk ; Timer 2 usato per trasmissione su COM1. . . . end ; ----------------------------------------------------------------------------- int_porta_ser: ; Gestione interrupt da porta seriale. jnb ri, ips_reti push psw ; Salvataggio registri. push acc push b push dpl push dph mov psw, #00010000b ; Banco registri 2. clr ri ; Reset interrupt in ricezione. mov b, sbuf ; Acquisizione del carattere. mov carser, b setb car_pronto mov dptr, #rx mov r5, dph mov r4, dpl mov r7, #0 mov r6, irx call addint mov dph, r3 mov dpl, r2 mov a, carser movx @dptr, a inc irx cjne a, #ret_c, ips1 setb rx_pronta jmp ips_fine ips1: mov r1, #timers + Tmr8 ; Si: ricarica del timer di controllo time-out. mov @r1, #TimeOutSer ips_fine: pop dph pop dpl pop b pop acc ; Recupero registri. pop psw ips_reti: reti ; ----------------------------------------------------------------------------- int_porta_ser2: ; Gestione interrupt da seconda porta seriale . jnb ri1, ips2_reti push psw ; Salvataggio registri. push acc push b push dpl push dph mov psw, #00010000b ; Banco registri 2. clr ri1 ; Reset interrupt in ricezione. mov b, sbuf1 ; Acquisizione del carattere. mov carser2, b setb car2_pronto mov dptr, #rx2 mov r5, dph mov r4, dpl mov r7, #0 mov r6, irx2 call addint mov dph, r3 mov dpl, r2 mov a, carser2 movx @dptr, a inc irx2 cjne a, #ret_c, ips21 setb rx2_pronta jmp ips2_fine ips21: mov r1, #timers + Tmr9 ; Si: ricarica del timer di controllo time-out. mov @r1, #TimeOutSer ips2_fine: pop dph pop dpl pop b pop acc ; Recupero registri. pop psw ips2_reti: reti |



