Author Topic: UART assembly routine  (Read 7317 times)

0 Members and 1 Guest are viewing this topic.

Offline ChristofferBTopic starter

  • Frequent Contributor
  • **
  • Posts: 929
  • Country: dk
  • Chemistry phd student!
    • My channel:
UART assembly routine
« on: November 29, 2016, 10:49:02 pm »
Hey guys, I'm at it again. I'm trying to get an i8251 USART running with an 8085 microprocessor, in this rack based system I'm building.
I just can't get my head around it, interfacing the chip is easy enough, with it being designed to be compatible, but getting it to, at first, actually spewing serial at me is another matter.

It has this register thing, where just after reset, first command word it gets sets baudrate division, parity, etc, and afterwards, the same register is just commands, like toggle handshaking lines, enable/disable rx/tx so forth.

I've migrated from the motorola 6850 , since it had horrible compatibility with the 8085 , and I've been trying to modify the serial routines meant for that, originally adapted from an old altair bootloader.

Here's my code:
Code: [Select]
0001   0000             ;SIMPLE TEST ROUTINE TO PUNCH OUT CHARACTERS TO A SERIAL PORT
0002   0000             ;BASED LOOSELY ON THE ALTAIR 8800 TURNKEY MONITOR CODE, ADAPTED FOR THE INTEL 8251
0003   0000             ;VERSION 1
0004   0000             
0005   0000             
0006   0000             UARTDR .EQU 10H ; 8251 UART DATA REGISTER
0007   0000             UARTCR .EQU UARTDR+1 ; 8251 UART STATUS AND COMMAND REGISTER
0008   0000             ;UARTRST .EQU 03H ; UART MASTER RESET  (DUNNO HOW YET, IT RESETS WITH CPU, MIGHT NOT BE NEEDED.)
0009   0000             UARTINIT .EQU 01001101B ;[S2][S1][EP][PEN][L2][L1][B2][B1] /1 STOP, NO PARITY, 8 BIT, X1 CLOCK
0010   0000             
0011   0000             LEADCH .EQU 0DH ; PUNCH LEADER CHAR
0012   0000             LEADCNT .EQU 3CH ; PUNCH LEADER COUNT
0013   0000             SOFB .EQU 3CH ; PUNCH "START OF BLOCK" CHAR
0014   0000             
0015   0000             PROMPT .EQU '.' ; COMMAND PROMPT
0016   0000             
0017   0000             ;STACK EQU 0FC00H
0018   0000             STACK .EQU 02FFFH ;START OF STACK IS THE TOP!!  - 4K OF RAM ENDING AT 2FFFH
0019   0000             
0020   0000             .ORG 00H ;START OF MONITOR ( BOTTOM OF ROM)
0021   0000             
0022   0000             MON:
0023   0000 3E 4D        MVI A,UARTINIT   
0024   0002 D3 11        OUT UARTCR      ;SET UART /1, 8 BITS, NO PARITY, 1 STOP, NO INTS
0025   0004              ;MVI A,UARTRST ; RESET 2SIO  /PUT SIORST IN A
0026   0004              ;OUT UARTCR ; AND INITIALIZE /ENABLE INT.
0027   0004             
0028   0004             
0029   0004             ENTER:
0030   0004 31 FF 2F    LXI SP,STACK ; LOAD STACK
0031   0007              ;CALL CRLF ; FORMAT OUTPUT
0032   0007 3E 20        MVI A, ' '
0033   0009 CD 4C 00    CALL OUTCHK
0034   000C 3E 20        MVI A, ' '
0035   000E CD 4C 00    CALL OUTCHK
0036   0011 3E 38        MVI A, '8'
0037   0013 CD 4C 00    CALL OUTCHK
0038   0016 3E 32        MVI A, '2'
0039   0018 CD 4C 00    CALL OUTCHK
0040   001B 3E 35        MVI A, '5'
0041   001D CD 4C 00    CALL OUTCHK
0042   0020 3E 31        MVI A, '1'
0043   0022 CD 4C 00    CALL OUTCHK
0044   0025 3E 20        MVI A, ' '
0045   0027 CD 4C 00    CALL OUTCHK
0046   002A 3E 4F        MVI A, 'O'
0047   002C CD 4C 00    CALL OUTCHK
0048   002F 3E 4B        MVI A, 'K'
0049   0031 CD 4C 00    CALL OUTCHK
0050   0034 CD 42 00    CALL CRLF ; FORMAT OUTPUT
0051   0037 3E 2E        MVI A, PROMPT ; HELLO MONITOR
0052   0039 CD 4C 00    CALL OUTCHK
0053   003C 00          STOP: NOP
0054   003D 00          NOP
0055   003E 00          NOP
0056   003F C3 3C 00    JMP STOP ; JUST LOOPING FOREVER
0057   0042             
0058   0042             
0059   0042 3E 0D       CRLF: MVI A,0DH ; DO A CRLF AND RETURN TO MONITOR
0060   0044             
0061   0044 CD 4C 00    CALL OUTCHK
0062   0047             
0063   0047 3E 0A        MVI A,0AH
0064   0049             
0065   0049 C3 4C 00    JMP OUTCHK
0066   004C             
0067   004C F5          OUTCHK: PUSH PSW ; SAVE CHARACTER
0068   004D 81          ADD C ; ADD IN CHECKSUM
0069   004E 4F          MOV C,A ; UPDATE CHECKSUM
0070   004F             
0071   004F             LOOP: ;IN UARTCR ; READ STATUS
0072   004F              ;CPI ' ' OMMIT ERROR
0073   004F              ;JNC LOOP ; READY ?
0074   004F             
0075   004F F1          POP PSW ; YES, GET CHAR
0076   0050 D3 10        OUT UARTDR ; PRINT CHARACTER
0077   0052             
0078   0052 C9          RET ; FROM WHENCE YE CAME
0079   0053             
0080   0053              .ENDtasm: Number of errors = 0

The datasheet for the 8251: http://map.grauw.nl/resources/midi/intel_8251.pdf

and my schematic, just in case you spot a giant blunder I haven't.

What am I not getting? I've never worked with the 8251 before, and I originally chose the 6850 mainly because I had some good example code to work from.

Thanks in advance.
« Last Edit: November 29, 2016, 10:51:13 pm by ChristofferB »
--Christoffer //IG:Chromatogiraffery
Check out my scientific instruments diy (GC, HPLC, NMR, etc) Channel: https://www.youtube.com/channel/UCZ8l6SdZuRuoSdze1dIpzAQ
 

Online Andy Watson

  • Super Contributor
  • ***
  • Posts: 2074
Re: UART assembly routine
« Reply #1 on: November 29, 2016, 11:22:35 pm »
From an Intel data book:
Quote
The 8251A cannot be transmission until the Tx Enable (Transmitter Enable) bit is set in the Command instruction and it has received a CTS (Clear to Send) input.
Does it have a valid CTS signal? Do you have means of checking that it has both baud and system clocks?
 
The following users thanked this post: ChristofferB

Offline ChristofferBTopic starter

  • Frequent Contributor
  • **
  • Posts: 929
  • Country: dk
  • Chemistry phd student!
    • My channel:
Re: UART assembly routine
« Reply #2 on: November 29, 2016, 11:46:56 pm »
...Wow, completely missed that. I'll try that, as a first.

I haven't actually checked the clocks in circuit, but I should sic the scope on them, you're right.
It does have CTS from the terminal, but the other flow control is probably the culprit.

Thanks!
--Christoffer //IG:Chromatogiraffery
Check out my scientific instruments diy (GC, HPLC, NMR, etc) Channel: https://www.youtube.com/channel/UCZ8l6SdZuRuoSdze1dIpzAQ
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4196
  • Country: us
Re: UART assembly routine
« Reply #3 on: November 30, 2016, 07:31:16 am »
the way I read the datasheet, you should initialize by sending the sequence 0, 0, 0, 0x40, <mode>, <command to enable stuff>
This allows for the 'initial state' of the 8251 to be unknown.  If it was already in command state, the three zeros are essentially no-op (or 'disable everything') commands, and the 0x40 puts the chip into "reset" status (ready for the "mode" byte.)  If the chip was expecting <mode>, the zeros configure a relatively benign mode that doesn't last very long, since the RESET instruction follows immediately.
 
The following users thanked this post: ChristofferB

Online coppice

  • Super Contributor
  • ***
  • Posts: 8605
  • Country: gb
Re: UART assembly routine
« Reply #4 on: November 30, 2016, 09:11:07 am »
Do you actually have an 8251 or an 8251A? Its 36 years since I used these, and I can't remember the exact details, but the 8251 was badly botched, and couldn't really be used for interrupt serviced I/O. The 8251A fixed that, but was incompatible with the 8251.
 
The following users thanked this post: ChristofferB

Offline ChristofferBTopic starter

  • Frequent Contributor
  • **
  • Posts: 929
  • Country: dk
  • Chemistry phd student!
    • My channel:
Re: UART assembly routine
« Reply #5 on: November 30, 2016, 08:37:35 pm »
the way I read the datasheet, you should initialize by sending the sequence 0, 0, 0, 0x40, <mode>, <command to enable stuff>
This allows for the 'initial state' of the 8251 to be unknown.  If it was already in command state, the three zeros are essentially no-op (or 'disable everything') commands, and the 0x40 puts the chip into "reset" status (ready for the "mode" byte.)  If the chip was expecting <mode>, the zeros configure a relatively benign mode that doesn't last very long, since the RESET instruction follows immediately.

You may be right, but since the chip master reset is tied to the processor reset (out), and it has power on reset, I don't think It'll start in an undefined state. In any case, it's only a few cycles, so it might be worth to have just for belt-and-braces.

Do you actually have an 8251 or an 8251A? Its 36 years since I used these, and I can't remember the exact details, but the 8251 was badly botched, and couldn't really be used for interrupt serviced I/O. The 8251A fixed that, but was incompatible with the 8251.

One is a NEC D8251C, the other is a NEC D71051C. I can't find datasheet on the former, and the latter doesn't say whether it's the 8251 or A version.
I think I'm going to use them polled more than anything so both would hopefully do the trick.
 
--Christoffer //IG:Chromatogiraffery
Check out my scientific instruments diy (GC, HPLC, NMR, etc) Channel: https://www.youtube.com/channel/UCZ8l6SdZuRuoSdze1dIpzAQ
 

Offline ChristofferBTopic starter

  • Frequent Contributor
  • **
  • Posts: 929
  • Country: dk
  • Chemistry phd student!
    • My channel:
Re: UART assembly routine
« Reply #6 on: November 30, 2016, 10:54:21 pm »
Okay, updated the code with the recommendations, still doesn't do anything:
Code: [Select]
0001   0000             ;SIMPLE TEST ROUTINE TO PUNCH OUT CHARACTERS TO A SERIAL PORT
0002   0000             ;BASED LOOSELY ON THE ALTAIR 8800 TURNKEY MONITOR CODE, ADAPTED FOR THE INTEL 8251
0003   0000             ;VERSION 1.1
0004   0000             
0005   0000             
0006   0000             UARTDR .EQU 10H ; 8251 UART DATA REGISTER
0007   0000             UARTCR .EQU UARTDR+1 ; 8251 UART STATUS AND COMMAND REGISTER
0008   0000             UARTRST .EQU 40H ; UART RESET 
0009   0000             UARTINIT .EQU 01001101B ;[S2][S1][EP][PEN][L2][L1][B2][B1] /1 STOP, NO PARITY, 8 BIT, X1 CLOCK
0010   0000             
0011   0000             
0012   0000             LEADCH .EQU 0DH ; PUNCH LEADER CHAR
0013   0000             LEADCNT .EQU 3CH ; PUNCH LEADER COUNT
0014   0000             SOFB .EQU 3CH ; PUNCH "START OF BLOCK" CHAR
0015   0000             
0016   0000             TXEN .EQU 00100001B ;[EH][RST][RTS][ER][SBRK][RXE][DTR][TXEN]
0017   0000             
0018   0000             PROMPT .EQU '.' ; COMMAND PROMPT
0019   0000             
0020   0000             ;STACK EQU 0FC00H
0021   0000             STACK .EQU 02FFFH ;START OF STACK IS THE TOP!!  - 4K OF RAM ENDING AT 2FFFH
0022   0000             
0023   0000             .ORG 00H ;START OF MONITOR ( BOTTOM OF ROM)
0024   0000             
0025   0000 3E 00       MON: MVI A, 00H ;NOP
0026   0002 D3 11        OUT UARTCR
0027   0004 3E 00        MVI A, 00H
0028   0006 D3 11        OUT UARTCR
0029   0008 3E 00        MVI A, 00H
0030   000A D3 11        OUT UARTCR
0031   000C 3E 40        MVI A, UARTRST ;RESET UART
0032   000E D3 11        OUT UARTCR
0033   0010 3E 4D        MVI A,UARTINIT   
0034   0012 D3 11        OUT UARTCR      ;SET UART /1, 8 BITS, NO PARITY, 1 STOP, NO INTS
0035   0014             
0036   0014             
0037   0014             
0038   0014             ENTER:
0039   0014 31 FF 2F    LXI SP,STACK ; LOAD STACK
0040   0017              ;CALL CRLF ; FORMAT OUTPUT
0041   0017 3E 20        MVI A, ' '
0042   0019 CD 5C 00    CALL OUTCHK
0043   001C 3E 20        MVI A, ' '
0044   001E CD 5C 00    CALL OUTCHK
0045   0021 3E 38        MVI A, '8'
0046   0023 CD 5C 00    CALL OUTCHK
0047   0026 3E 32        MVI A, '2'
0048   0028 CD 5C 00    CALL OUTCHK
0049   002B 3E 35        MVI A, '5'
0050   002D CD 5C 00    CALL OUTCHK
0051   0030 3E 31        MVI A, '1'
0052   0032 CD 5C 00    CALL OUTCHK
0053   0035 3E 20        MVI A, ' '
0054   0037 CD 5C 00    CALL OUTCHK
0055   003A 3E 4F        MVI A, 'O'
0056   003C CD 5C 00    CALL OUTCHK
0057   003F 3E 4B        MVI A, 'K'
0058   0041 CD 5C 00    CALL OUTCHK
0059   0044 CD 52 00    CALL CRLF ; FORMAT OUTPUT
0060   0047 3E 2E        MVI A, PROMPT ; HELLO MONITOR
0061   0049 CD 5C 00    CALL OUTCHK
0062   004C 00          LOP: NOP
0063   004D 00          NOP
0064   004E 00          NOP
0065   004F C2 4C 00    JNZ LOP ; JUST LOOPING FOREVER
0066   0052             
0067   0052             
0068   0052 3E 0D       CRLF: MVI A,0DH ; DO A CRLF AND RETURN TO MONITOR
0069   0054             
0070   0054 CD 5C 00    CALL OUTCHK
0071   0057             
0072   0057 3E 0A        MVI A,0AH
0073   0059             
0074   0059 C3 5C 00    JMP OUTCHK
0075   005C             
0076   005C F5          OUTCHK: PUSH PSW ; SAVE CHARACTER
0077   005D 81          ADD C ; ADD IN CHECKSUM
0078   005E 4F          MOV C,A ; UPDATE CHECKSUM
0079   005F             
0080   005F 3E 21       LOOP: MVI A, TXEN ;ENABLE TX
0081   0061             
0082   0061              ;IN UARTCR ; READ STATUS
0083   0061              ;CPI ' ' OMMIT ERROR
0084   0061              ;JNC LOOP ; READY ?
0085   0061             
0086   0061 F1          POP PSW ; YES, GET CHAR
0087   0062 D3 10        OUT UARTDR ; PRINT CHARACTER
0088   0064             
0089   0064 C9          RET ; FROM WHENCE YE CAME
0090   0065             
0091   0065              .ENDtasm: Number of errors = 0

Does this look like it'd at least 'sorta' work? If that's the case I'll get to hardware debugging.
 
--Christoffer //IG:Chromatogiraffery
Check out my scientific instruments diy (GC, HPLC, NMR, etc) Channel: https://www.youtube.com/channel/UCZ8l6SdZuRuoSdze1dIpzAQ
 

Offline Bruce Abbott

  • Frequent Contributor
  • **
  • Posts: 627
  • Country: nz
    • Bruce Abbott's R/C Models and Electronics
Re: UART assembly routine
« Reply #7 on: December 01, 2016, 06:54:51 am »
This line
Code: [Select]
LOOP: MVI A, TXEN ;ENABLE TX doesn't do what the comment says. I think to actually enable the transmitter you need to follow it with
Code: [Select]
OUT UARTCR
 

Offline ChristofferBTopic starter

  • Frequent Contributor
  • **
  • Posts: 929
  • Country: dk
  • Chemistry phd student!
    • My channel:
Re: UART assembly routine
« Reply #8 on: December 01, 2016, 11:45:23 am »
You're absolutely right. Jeez, my assistant must have been drunk that day! He's also made some really dumb wiring errors, resulting in no baud-clock and floating reset, both now fixed.

Thankfully, vero-wire is pretty easy to correct.


--Christoffer //IG:Chromatogiraffery
Check out my scientific instruments diy (GC, HPLC, NMR, etc) Channel: https://www.youtube.com/channel/UCZ8l6SdZuRuoSdze1dIpzAQ
 

Offline ChristofferBTopic starter

  • Frequent Contributor
  • **
  • Posts: 929
  • Country: dk
  • Chemistry phd student!
    • My channel:
Re: UART assembly routine
« Reply #9 on: December 01, 2016, 02:48:27 pm »
Okay, been through the hardware issues, uart clock works, main clock works, reset works, it's executing the code, and it's doing something right, since the correct chip's /CS is triggered every loop cycle, rs232 drivers works, and can drive both low and hi, but I still don't get any data out.

I'm suspecting my very vintage uarts may be duds. Either that or a software thing.
--Christoffer //IG:Chromatogiraffery
Check out my scientific instruments diy (GC, HPLC, NMR, etc) Channel: https://www.youtube.com/channel/UCZ8l6SdZuRuoSdze1dIpzAQ
 

Offline stfsux

  • Contributor
  • Posts: 23
  • Country: 00
Re: UART assembly routine
« Reply #10 on: December 01, 2016, 05:19:05 pm »
Don't you have to check the TxRDY signal before sending an other byte?
 

Offline Bruce Abbott

  • Frequent Contributor
  • **
  • Posts: 627
  • Country: nz
    • Bruce Abbott's R/C Models and Electronics
Re: UART assembly routine
« Reply #11 on: December 01, 2016, 05:54:19 pm »
/CS is triggered every loop cycle, rs232 drivers works, and can drive both low and hi, but I still don't get any data out.
Can you toggle RTS and DTR? If so then the chip is working.

Your OUTCHK routine needs to be tidied up:-

1. Move tx enable code to initialization.

2. Wait until the transmitter is ready (UARTCR bit 0 = 1) before sending the next character.

Note: As well as setting TXEN, CTS (pin 17) must be low to enable the transmitter. 
 

Offline ChristofferBTopic starter

  • Frequent Contributor
  • **
  • Posts: 929
  • Country: dk
  • Chemistry phd student!
    • My channel:
Re: UART assembly routine
« Reply #12 on: December 01, 2016, 06:36:20 pm »
/CS is triggered every loop cycle, rs232 drivers works, and can drive both low and hi, but I still don't get any data out.
Can you toggle RTS and DTR? If so then the chip is working.

Your OUTCHK routine needs to be tidied up:-

1. Move tx enable code to initialization.

2. Wait until the transmitter is ready (UARTCR bit 0 = 1) before sending the next character.

Note: As well as setting TXEN, CTS (pin 17) must be low to enable the transmitter.

I'll do some tests on RTS and DTR.

The reason TxEN is in the actual routine, is that there's also an RxEN, and I don't assume you could just tick them both at initialization - wouldn't they have to be toggled between Rx and Tx routines?

I absolutely should wait for tx to be ready, but for simplicity, I just wanted it to spew data, less controlled, integrity less important, until I knew the hardware was solid.

thanks again.
--Christoffer //IG:Chromatogiraffery
Check out my scientific instruments diy (GC, HPLC, NMR, etc) Channel: https://www.youtube.com/channel/UCZ8l6SdZuRuoSdze1dIpzAQ
 

Offline ChristofferBTopic starter

  • Frequent Contributor
  • **
  • Posts: 929
  • Country: dk
  • Chemistry phd student!
    • My channel:
Re: UART assembly routine
« Reply #13 on: December 02, 2016, 06:24:55 pm »
Okay, now hardware IS sorted out, made a small loop to toggle RTS, and it does that splendidly, so the chip works and is initialized correctly.

Here's my cleaned assembly routine, I still can't get it to behave. Does anyone have an idea what I might have missed?

Code: [Select]
;SIMPLE TEST ROUTINE TO PUNCH OUT CHARACTERS TO A SERIAL PORT
;BASED LOOSELY ON THE ALTAIR 8800 TURNKEY MONITOR CODE, ADAPTED FOR THE INTEL 8251
;VERSION 1.1


UARTDR .EQU 10H ; 8251 UART DATA REGISTER
UARTCR .EQU UARTDR+1 ; 8251 UART STATUS AND COMMAND REGISTER
UARTRST .EQU 40H ; UART RESET 
UARTINIT .EQU 01001101B ;[S2][S1][EP][PEN][L2][L1][B2][B1] /1 STOP, NO PARITY, 8 BIT, X1 CLOCK
TXEN .EQU 00100011B ;[EH][RST][RTS][ER][SBRK][RXE][DTR][TXEN]

LEADCH .EQU 0DH ; PUNCH LEADER CHAR
LEADCNT .EQU 3CH ; PUNCH LEADER COUNT
SOFB .EQU 3CH ; PUNCH "START OF BLOCK" CHAR



PROMPT .EQU '.' ; COMMAND PROMPT

;STACK EQU 0FC00H
STACK .EQU 02FFFH ;START OF STACK IS THE TOP!!  - 4K OF RAM ENDING AT 2FFFH

.ORG 00H ;START OF MONITOR ( BOTTOM OF ROM)

MON:
MVI A, UARTRST ;RESET UART
OUT UARTCR
MVI A,UARTINIT   
OUT UARTCR      ;SET UART /1, 8 BITS, NO PARITY, 1 STOP, NO INTS
MVI A, TXEN ;SET MODE /RTS LO, /DTR LO, TX ENABLE
OUT UARTCR ;ENABLE TX


ENTER:
LXI SP,STACK ; LOAD STACK
;CALL CRLF ; FORMAT OUTPUT
MVI A, ' '
CALL OUTCHK
MVI A, ' '
CALL OUTCHK
MVI A, '8'
CALL OUTCHK
MVI A, '2'
CALL OUTCHK
MVI A, '5'
CALL OUTCHK
MVI A, '1'
CALL OUTCHK
MVI A, ' '
CALL OUTCHK
MVI A, 'O'
CALL OUTCHK
MVI A, 'K'
CALL OUTCHK
CALL CRLF ; FORMAT OUTPUT
MVI A, PROMPT ; HELLO MONITOR
CALL OUTCHK
LOP: NOP
NOP
NOP
JNZ ENTER ; JUST LOOPING SERIAL FOREVER


CRLF: MVI A,0DH ; DO A CRLF AND RETURN TO MONITOR

CALL OUTCHK

MVI A,0AH

JMP OUTCHK

OUTCHK: PUSH PSW ; SAVE CHARACTER
ADD C ; ADD IN CHECKSUM
MOV C,A ; UPDATE CHECKSUM

LOOP:

IN UARTCR ; READ STATUS
RRC ; ROTATE TxREADY TO CARRY
JNC LOOP ; READY ?

POP PSW ; YES, GET CHAR
OUT UARTDR ; PRINT CHARACTER

RET ; FROM WHENCE YE CAME

.END
--Christoffer //IG:Chromatogiraffery
Check out my scientific instruments diy (GC, HPLC, NMR, etc) Channel: https://www.youtube.com/channel/UCZ8l6SdZuRuoSdze1dIpzAQ
 

Online Andy Watson

  • Super Contributor
  • ***
  • Posts: 2074
Re: UART assembly routine
« Reply #14 on: December 02, 2016, 07:27:40 pm »
It's been three decades since I dabbled with these chips - so what I say with respect to the 8251 may not be appropriate, or even correct! But here are some thoughts:
Have a good look at the timing. There is a note at the top of page 14 (of the 8215A datasheet) that says that the status flags may be delayed by 28 clock periods from the event that caused them. I assume this means the system clock. With short sections of assembly code it is quite possible that your processor can change a uart flag and perform a complete loop of code before the flag is actually set.
Another thing to consider is that the processes within the uart are often clocked by the baud-rate clock. For example, the transmitter status flags may get updated only when TxClock happens - you have to make allowances in your code for the fact that your CPU is operating asynchronously with respect to the uart.
 

Offline Bruce Abbott

  • Frequent Contributor
  • **
  • Posts: 627
  • Country: nz
    • Bruce Abbott's R/C Models and Electronics
Re: UART assembly routine
« Reply #15 on: December 03, 2016, 02:08:21 am »
I still can't get it to behave.
Does the CPU get past testing TXRDY, and if so does TXD output anything? If it is then check the baud rate. If not then what is happening on pins 15, 17, and 18?
 

Offline ChristofferBTopic starter

  • Frequent Contributor
  • **
  • Posts: 929
  • Country: dk
  • Chemistry phd student!
    • My channel:
Re: UART assembly routine
« Reply #16 on: December 03, 2016, 11:58:52 am »
I still can't get it to behave.
Does the CPU get past testing TXRDY, and if so does TXD output anything? If it is then check the baud rate. If not then what is happening on pins 15, 17, and 18?


I don't know. I don't have any output devices that could be used to tell where it was in the code. Maybe that's the next project for it.
TXD outputs nothing at all, it just sits at -12V.

Here's the observations so far:
 - voltages are good
 - rom's being read correctly
 - uart reset line's good
 - uart clocks are good, both baud and system.
 - I can write to the uart, get it to wag its RTS pin.

The test setup is just looping RTS to CTS on the db9 connector, and putting a oscilloscope probe in TX.
and I get nothing.
--Christoffer //IG:Chromatogiraffery
Check out my scientific instruments diy (GC, HPLC, NMR, etc) Channel: https://www.youtube.com/channel/UCZ8l6SdZuRuoSdze1dIpzAQ
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4196
  • Country: us
Re: UART assembly routine
« Reply #17 on: December 03, 2016, 06:09:56 pm »
Quote
made a small loop to toggle RTS
Quote
I don't have any output devices that could be used to tell where it was in the code.
Put an LED on RTS and use that...
 

Offline Bruce Abbott

  • Frequent Contributor
  • **
  • Posts: 627
  • Country: nz
    • Bruce Abbott's R/C Models and Electronics
Re: UART assembly routine
« Reply #18 on: December 03, 2016, 06:40:20 pm »
I don't have any output devices that could be used to tell where it was in the code.
You can 'waggle' RTS at certain points in your code. If you feed that signal into your scope's external trigger then you can see what other pins are doing at the time.

TXRDY (pin 15) should go high when the transmitter is enabled, and pulse low as each character is sent. If it stays low then either the transmitter is not enabled or CTS (pin 17) is high. TXEMPTY should start out high but go low while characters are being transmitted.

In case there is something wrong with the rs232 driver, disconnect it from TXD (pin 19) and look directly at the pin.

Quote
The reason TxEN is in the actual routine, is that there's also an RxEN, and I don't assume you could just tick them both at initialization - wouldn't they have to be toggled between Rx and Tx routines?
No. The UART can send and receive simultaneously.

 

Offline ChristofferBTopic starter

  • Frequent Contributor
  • **
  • Posts: 929
  • Country: dk
  • Chemistry phd student!
    • My channel:
Re: UART assembly routine
« Reply #19 on: December 03, 2016, 07:52:17 pm »
Removing the driver chips might actually be a good idea. the MC1488/1489 likely takes a fair bit more abuse than the components later in the chain, being both higher voltage and 'front end'.

Adding some status LEDs might be a good idea, but I've actually made some progress:

I've added the dummy control words [00H] to the start of the MON routine, and that did something:
Code: [Select]
0026   0000 3E 00        MVI A, 00H
0027   0002 D3 11        OUT UARTCR
0028   0004 D3 11        OUT UARTCR
0029   0006 D3 11        OUT UARTCR

Still have no idea what this does.


A good visualization is the A8-15 led panel I have on the thing, since the 8085 also duplicates its IO ports to the upper addresses:
Now, when no RS232 connector is plugged in, it stabilizes in a loop of an IO request at 00010001B, the control reg. That must be the  waiting loop:
Code: [Select]
LOOP:
 
 IN UARTCR  ; READ STATUS
 RRC    ; ROTATE TxREADY TO CARRY
 JNC LOOP  ; READY ?

When a DB9 with RTS and CTS shorted is inserted, it breaks from the loop, doing things too fast for the naked eye, presumably sending the characters to the UART.
Removing the plug plunges it back into aforementioned state.

With one of my two UART chips (swapping between them), it sends something. too slow and few pulses to be data, but it is something. The other doesn't.

It looks like the handshaking portion of the UART (1 of them) is at least working.

Maybe it'd be worth it to buy a set of new 8251A's, so they can be ruled out.

Another thing - I'm only using RTS/CTS for handshaking - should something be done to DSR/DTR?

Thanks again, slowwly getting there.
--Christoffer //IG:Chromatogiraffery
Check out my scientific instruments diy (GC, HPLC, NMR, etc) Channel: https://www.youtube.com/channel/UCZ8l6SdZuRuoSdze1dIpzAQ
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4196
  • Country: us
Re: UART assembly routine
« Reply #20 on: December 03, 2016, 09:20:53 pm »
Quote
an 8085 microprocessor
Do you have anything connected to the SOD pin yet?  that's another place you can stick an LED.  Or a scope if you want to bit twiddle it.  Or a serial device, if you want to implement bit-banged serial before you get the USART working...
 

Offline ChristofferBTopic starter

  • Frequent Contributor
  • **
  • Posts: 929
  • Country: dk
  • Chemistry phd student!
    • My channel:
Re: UART assembly routine
« Reply #21 on: December 03, 2016, 11:53:17 pm »
I don't have anything connected to the SOD pin, might use that. I reaally don't want to do bit-bang serial, as much done in hardware as possible!

I have another potential explaination for the very very slow shifting serial output I see. In the setup, the baud prescaler has to be set, /1, /16 or /64.

If I feed it a low baudrate like 1200 hz, and it's not initializing properly, thus dividing that by either 16 or 64, that could account for some very slow data transmission..

edit: that seemed to be wishful thinking, unless a registry bit is stuck in the chip (can they do that?)
editedit: There aren't any strict requirements for the cpu clock, is there? I think mine's 4.1 MHz, within the spec of my 8085.
« Last Edit: December 04, 2016, 12:18:59 am by ChristofferB »
--Christoffer //IG:Chromatogiraffery
Check out my scientific instruments diy (GC, HPLC, NMR, etc) Channel: https://www.youtube.com/channel/UCZ8l6SdZuRuoSdze1dIpzAQ
 

Offline ChristofferBTopic starter

  • Frequent Contributor
  • **
  • Posts: 929
  • Country: dk
  • Chemistry phd student!
    • My channel:
Re: UART assembly routine
« Reply #22 on: December 04, 2016, 02:44:32 am »
I only just realized there's something seriously wrong with my clock.

I went from measuring the baudrate gen to the system clock with my scope, and only then relized I had to turn the timebase knob the 'wrong' way!

Measuring the system clock (buffered, from 'CLK' on the 8085), the period's about 0,3 ms! that'd be a 3.2 kHz system clock! What's going on??


Trying another xtal, about 3 mhz, from another scrap 8085 board didn't change that outcome notably.

Tomorrow I'm gonna try to replace the entire crystal circuitry with a 9MHz can-oscillator, that's a known good, can't really go wrong.

The super-slow-system-clock would explain alot of the issues I've been having. First, I can see the IO/M pin flicker - that should probably be too fast @3mhz,

secondly, my previous UART board worked, but had the strange bug that it sent the characters very. very. slowly. like one every second.

--Christoffer //IG:Chromatogiraffery
Check out my scientific instruments diy (GC, HPLC, NMR, etc) Channel: https://www.youtube.com/channel/UCZ8l6SdZuRuoSdze1dIpzAQ
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4196
  • Country: us
Re: UART assembly routine
« Reply #23 on: December 04, 2016, 04:44:52 am »
Quote
I reaally don't want to do bit-bang serial
"Just for debugging" (you've probably heard THAT before!)(and only because you're using "difficult" hardware for peripherals.)
 

Offline ChristofferBTopic starter

  • Frequent Contributor
  • **
  • Posts: 929
  • Country: dk
  • Chemistry phd student!
    • My channel:
Re: UART assembly routine
« Reply #24 on: December 04, 2016, 01:21:47 pm »
Yeah, you're right. might be worth it. Anyway, I think the clock is a bigger issue now. I shifted to the can oscillator (seemed to be dead), removed it, and the machine still runs exactly the same when powered up with no clock! I removed power from the BAUDrate crystal to be sure it didn't catch crosstalk from that.
It still runs, no clocks, exactly the same behavior as before. Am I running a computer off of mains hum?

Anyway, I'll try to find a crystal that works and fits and throw in there. Perhaps my main clock crystal has been damaged all along.
--Christoffer //IG:Chromatogiraffery
Check out my scientific instruments diy (GC, HPLC, NMR, etc) Channel: https://www.youtube.com/channel/UCZ8l6SdZuRuoSdze1dIpzAQ
 

Offline ChristofferBTopic starter

  • Frequent Contributor
  • **
  • Posts: 929
  • Country: dk
  • Chemistry phd student!
    • My channel:
Re: UART assembly routine
« Reply #25 on: December 04, 2016, 02:17:27 pm »
Aand now we're done. Got it working at last! It was the clock, it must've run off of noise all this time. Putting in a 9MHz can oscillator and removing the xtal capacitors and now it just runs. Here's proof and a portrait.

This fault obviously accounts for most of the larger issues I've had with this the last year, maybe actually measuring frequencies with a scope instead of just going 'yep, there's a signal' is a wise idea..

Thanks for all the assistance!

--Christoffer //IG:Chromatogiraffery
Check out my scientific instruments diy (GC, HPLC, NMR, etc) Channel: https://www.youtube.com/channel/UCZ8l6SdZuRuoSdze1dIpzAQ
 
The following users thanked this post: SeanB


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf