6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sat Jun 01, 2024 10:37 am

All times are UTC




Post new topic Reply to topic  [ 13 posts ] 
Author Message
PostPosted: Fri Dec 31, 2021 6:04 pm 
Offline

Joined: Sun Sep 19, 2021 11:21 am
Posts: 23
I have my breadboard SBC up and running, but the next big step is to establish communications with my PC and start to transfer programs to RAM rather than the popping out of the ROM and reprogramming.

The *typical* method for doing this seems (seemed) to be using the 65C51. However, given that there are issues with the 65C51 and the lack of RS232 ports on PCs these days, a trawl through the forum indicated that the MAX3100 is a candidate for use in 6502 communications. Furthermore, use of an inexpensive FTDI module (to my limited knowledge) *should* allow SBC/PC communications via USB in the following setup...

65C02 & 65C22 bit banging SPI <==> MAX3100 <==> FTDI module <==> USB on PC.

I have these parts.

I have done a lot of research and there is very little out there for someone at my beginners level. I don't have the expertise/knowledge to extract from the MAX3100 datasheet even how I am to send/receive the data. It talks about the write configuration being 16 bits, but I'm not sure if that just needs to be done once before a transmit/receive session. The 8051 and PIC examples don't throw any additional light on matters for me either.

The MAX3100 is not memory mapped (being SPI and on the *other side* of the 65C22 VIA, I didn't think such a thing was possible so thought no more about it anyway). Consequently, I'm not clear on how to use the Chip Select (active low). Can I tie this to GND so the chip is always active or should I have the 65C22 drive it?

I have found no code in the wild for a 6502 that speaks to a MAX3100 and I am not competent enough to write my own, but if I had sight of working code an accompanying schematic, I would have a sporting chance to reverse engineer it, see how it works and modify it for my use.

I have seen in the forum that some people have used the MAX3100 and even some have done this with an FTDI module, so I know those far more capable than me must have had some success with this approach.

If there is anything anyone can point me to on how to get all this working, I should be most grateful.


Top
 Profile  
Reply with quote  
PostPosted: Fri Dec 31, 2021 7:45 pm 
Offline
User avatar

Joined: Tue Mar 05, 2013 4:31 am
Posts: 1373
Well, using an FTDI USB to UART adapter is pretty trivial... they just work. At most, you'll need to install a driver for the FTDI device one time.

I also configure mine for RTS/CTS handshaking, which works very well... zero issues. However, I've not used the MAX3100 or any SPI devices as of yet. You could look at some of the NXP UARTs (or DUARTs). These can attach directly to the 6502 bus and work flawlessly.

For some hardware/software details, look at my GitHub page for the C02 Pocket SBC. This uses an older NXP SCC2691 UART with a FTDI interface. The BIOS and Monitor will support Xmodem CRC-16 upload and download via the console port.

BTW - Daryl Rictor has created a SPI chip based on a CPLD that takes most of the work out of interfacing SPI devices to a 6502... might be worth a look as well.

_________________
Regards, KM
https://github.com/floobydust


Top
 Profile  
Reply with quote  
PostPosted: Fri Dec 31, 2021 8:36 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8447
Location: Southern California
Do you have the SPI working already?  If you need help writing code for that (ie, the SPI), I have some at http://wilsonminesco.com/6502primer/SPI.ASM .  If you just need the MAX3100-specific stuff, I'll try to translate what I have from Forth to assembly for you.  I should post that on my site too.

Regarding the W65C51, the following is from 40% of the way down the page of my RS-232 primer:

    WDC 65c51 bug report, Oct 2013:  WDC obviously has a bug in that bit 4, "transmit data register empty," is stuck in the on position, such that it always looks like it's ready for another byte, so if you don't have enough delay between giving it new bytes to transmit, you'll get garbage out.  Follow the forum discussion on it in this topic.  They also have a bug in the even parity; but who uses parity?  Elsewhere I mention something I consider a bug in the old NMOS 6551's— either that or an idiotic part of the design; but it got corrected in the CMOS version.  I have never had any trouble with Rockwell's or CMD's (formerly GTE's) 65c51's (ie, CMOS).

    Edit, 2/8/19:  I think 6502.org forum member GaBuZoMeu has the best solution yet: Use the 51's pin 5 (if in DIP), the x16 clock, as an output to drive a VIA's PB6 for its T2 to count pulses and generate an interrupt.  The T2 latch value does not need to change with Φ2 rate nor with baud rate.

I just finished up a project for work to interface a PIC16 with its USART to our bluetooth modules at 115.2kbps.  I did the same thing for in-house programming equipment with my workbench computer with a 65c51 (CMD G65SC51P-4) a couple of years ago, and did not have any trouble at all doing the '51 part.  But although I had working 65c02 and Forth code to start with for the PIC project, getting the PIC's USART going was very, very difficult, very discouraging, and I nearly gave up.  When I tried the MAX3100 years ago, I just wrote code in Forth to use the VIA to bit-bang the SPI, and it all worked on first try.  I have not really put the MAX3100 into service, only exercised it to verify that I understood its operation, and successfully ran a bunch of data through it.

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
PostPosted: Fri Dec 31, 2021 9:42 pm 
Offline

Joined: Sun Sep 19, 2021 11:21 am
Posts: 23
floobydust wrote:
For some hardware/software details, look at my GitHub page for the C02 Pocket SBC.
Thanks, Kevin - will do. What system did you use for your schematics for this?

GARTHWILSON wrote:
If you just need the MAX3100-specific stuff, I'll try to translate what I have from Forth to assembly for you. I should post that on my site too.
Garth, that would be most welcome too.

Thanks, gentlemen, I'll persevere given this additional information.


Top
 Profile  
Reply with quote  
PostPosted: Fri Dec 31, 2021 10:25 pm 
Offline
User avatar

Joined: Tue Mar 05, 2013 4:31 am
Posts: 1373
I started using Express PCB many years ago... and still do.

https://www.expresspcb.com/

I've created many parts (both schematic and PCB) so moving to something else isn't all that likely, time will tell.

_________________
Regards, KM
https://github.com/floobydust


Top
 Profile  
Reply with quote  
PostPosted: Sat Jan 01, 2022 2:00 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8447
Location: Southern California
DRG wrote:
GARTHWILSON wrote:
If you just need the MAX3100-specific stuff, I'll try to translate what I have from Forth to assembly for you.  I should post that on my site too.
Garth, that would be most welcome too.

With all of the many options, there appears to be more to it than I was remembering.  I still plan to do it, but I'll need a little time, and hopefully I'll get it right the first time, while keeping it down to the basics.  Thanks for your patience.

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
PostPosted: Sun Jan 09, 2022 8:43 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8447
Location: Southern California
I've been combing through the data sheet and trying to get the basics boiled down to the simplest terms.  I started with my older working Forth code from 23 years ago (which is obviously plenty of time to forget, and I wasn't careful to write down the goals and reasons) and I tried to translate it into assembly language.  I've changed it substantially though.  The code below uses Sel_SPI_dev and SPI_Xceive near the bottom of http://wilsonminesco.com/6502primer/SPI.ASM .  At the expense of flexibility, you could gain efficiency by simplifying these to only handle the one SPI mode that the MAX3100 UART uses (which is mode 0) and making the select to be as simple as making a particular VIA port pin a 0 or a 1 such that the select routine is only good for the one device.

I'm sure this can be improved.  I'll probably end up editing this based on whatever response you give, and I won't try to post it on my site until I'm more sure it's clear and it works as intended.


Code:
DISABL_FIFO: EQU  $2000   ; (and there are more options in tables 9 through 11
TX_IRQ:      EQU   $800   ;  of the MAX3100 data sheet, where 'M' is for
RX_IRQ:      EQU   $400   ;  "interrupt Mask."  'RA' in the framing-err bit is
FE_IRQ:      EQU   $100   ;  "receiver activity" if you're in shutdown mode.)

_300bps:     EQU     $F
_9600bps:    EQU     $A   ; (...and you can add more rates as desired,
_19.2kbps:   EQU      9   ;  from table 7 of the data sheet.)

CONF:        EQU  $4000   ; Setting bit 14 of the outgoing word tells the UART
DATA:        EQU     $0   ; that what follows is for config info, not data.

                          ; "DFS" ("DeFine Storage) below in C32 is like "BLKB"
 ;     Variables:         ; (dedicate a BLocK of Bytes) in the 2500AD assembler.
                          ; I think ca65 uses ".res" for "reserve."

UART_IO:     DFS      2   ; 2-byte outgoing cell; gets replaced with incoming.
                          ; Can optionally be put in ZP for efficiency.
                          ; Little-endian, as usual for the 6502.  If there's
                          ; data (not just configuration/status info), whether
                          ; input or output, it will aways be in the low byte.

 COMMENT
    The MAX3100 runs in SPI mode 0, meaning the clock must be low when CS\
    falls, and both the master and the device then put out their first data bit,
    which will be accepted by the other end upon the rising edge of the clock.
    Data can change immediately after the falling edge of the clock.  Put the
    MAX3100's device number in A, and 0 (the SPI mode it operates on) in X,
    before calling Sel_SPI_dev ("Select SPI device") above.

    Apparently you have to de-select it after every 16-bit transfer.  :(

    SPI macros and subroutines will be like what's shown in the SPI code at
    http://wilsonminesco.com/6502primer/SPI.ASM .  You might need to change
    them if your ports and bit numbers are different.  Code below remains the
    same.  Structure macros are in the http://wilsonminesco.com/StructureMacros/
    section of my website.  In most cases, they will assemble exactly what you
    would do by hand; but the purpose here is to make the essence of running
    the MAX3100 as clear as possible.
 END_COMMENT


RdWr_UART:                 ; Read/Write MAX3100.  Use 2-byte variable UART_IO
       LDA  UART_IO+1      ; for data.  Select the UART before calling this.
       JSR  SPI_Xceive     ; First do the high byte,
       STA  UART_IO+1

       LDA  UART_IO        ; then the low byte.  (Send/Receive
       JSR  SPI_Xceive     ; actual data is never in the high byte.)
       STA  UART_IO

       JMP   NONE_SELECT   ; (JSR, RTS)
 ;-------------


 COMMENT
    Page 8 of the data sheet says, "To change the RTS pin’s state without
    writing data, set the TE bit. Setting the TE bit high inhibits the write
    command (Table 3)."  So TE, bit 10, is set below.  These disable transmis-
    sion, but you will re-enable it again if you give it a byte to transmit.

    After RTS_TRUE or RTS_FALSE below, you can check various status bits (R,
    T, rcv_activity/frame_err, CTS, & rcv parity), plus rcv data, in the high
    byte of variable UART_IO without needing another SPI operation.
 END_COMMENT


RTS_TRUE:
       LDA  #$86
       BRA  rf1$

RTS_FALSE:
       LDA  #$84
rf1$:  STA  UART_IO + 1    ; high byte
       STZ  UART_IO        ; low  byte
       BRA  RdWr_UART      ; (JSR, RST)
 ;-------------

WrUART_Conf:                    ; Write UART configuration word.
     LDA  UART_IO + 1
     ORA  #$C0
     LDA  UART_IO + 1           ; Set bits 6 & 7 of the high byte of UART_IO.
     BRA  RdWr_UART
 ;-------------

RdUART_Conf:                    ; Read UART configuration word.
     LDA  UART_IO + 1
     ORA  #$40
     STA  UART_IO + 1           ; Set bit 6 of the high byte of UART_IO.
     BRA  RdWr_UART
 ;-------------

WrUART_Data:                    ; Write UART_IO data to UART.  UART_IO + 1
     LDA  UART_IO + 1           ; must already have RTS and parity bits set to
     ORA  #%10000100            ; your choice; then here we enable transmit and
     STA  UART_IO + 1           ; tell it to send data.
     BRA  RdWr_UART
 ;-------------

RdUART_Data:                    ; Read UART data.  Data comes back in UART_IO,
     STZ  UART_IO               ; and you can read the status from UART_IO + 1.
     STZ  UART_IO + 1
     BRA  RdWr_UART
 ;-------------

SET_UP_UART:                    ; (The SPI port itself must already be set up.)
     LDA  #_9600bps
     STA  UART_IO
     LDA  #RX_IRQ + DISABL_FIFO
     STA  UART_IO + 1
                                ; (Set up ring buffer here if desired.)
     BRA  WrUART_Conf
 ;-------------

 COMMENT
    To poll the UART to see if it received data, whether you enabled receive
    interrupts or not (which is the RM\ config bit), put 0000 in UART_IO and
    do RdWr_UART, then branch on the high bit of UART_IO+1.  Bit set means
    data was received, and you can read it at UART_IO + 0 (ie, its low byte).
    I show how to set up a receive ring buffer in one of my earliest-written
    articles, at http://wilsonminesco.com/6502interrupts/index.html#3.1
 END_COMMENT

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
PostPosted: Sun Jan 09, 2022 5:02 pm 
Offline

Joined: Sun Sep 19, 2021 11:21 am
Posts: 23
Thanks for this, Garth.

I am having a break from the project at the moment as the problems I have been having with an intermittent LCD issue and attempting to get comms running have worn me down. I'm going to have a look at some embedded videos and books and attempt to become more informed around electronics generally before I come back for a second bite.

It is disheartening at times when I just can't get something to work despite weeks of research. I haven't got an electronics background so am very much starting from the beginning and so haven't the experience to fall back onto when things don't work they way they are supposed to. I know that's part of the learning process, but I can only take so much! :lol:


Top
 Profile  
Reply with quote  
PostPosted: Mon Jan 17, 2022 7:14 pm 
Offline

Joined: Tue Jan 11, 2022 5:56 pm
Posts: 17
DRG wrote:
I have done a lot of research and there is very little out there for someone at my beginners level. I don't have the expertise/knowledge to extract from the MAX3100 datasheet even how I am to send/receive the data. It talks about the write configuration being 16 bits, but I'm not sure if that just needs to be done once before a transmit/receive session. The 8051 and PIC examples don't throw any additional light on matters for me either.


Hey DRG, I understand how things can be frustrating when the info assumes a certain level of knowledge. Don't worry, you'll get there, and for what it's worth - I am a software dev and have casually been involved in electronics for decades and admit that the MAX3100 data sheet took a bit of deciphering for me. Problem is the information is *there*, but it's not really spelled out well so I had to make some assumptions and then test them out.

My preferred way to learn how to use a new IC like this is to build a prototype using an Arduino. This way I can write and redeploy code quickly, and use the Arduino's serial port as a debugger - then when it all works or I have my questions answered I'll write the 6502 code. Doing the same in 6502 assembly with no debugger would make thing quite a bit more difficult!

Maybe this will help -

Configuration only needs to be sent once after power up. To get a simple test going, nothing much needs to be set but the top two bits of the first byte for the "write config" command and the baud rate divisor for the second byte of the 16 bit config word. If you don't send the config it runs with defaults which is 115k baud I believe.

Then every time you write a byte send the write data command for the first byte and the byte to send for the second byte. The important thing to keep in mind is when you get full functionality going is, if there is any data in the receive buffer you'll receive a byte here in return (since SPI always sends in each direction simultaneously, this saves an extra read command if data is available). So your sending code needs to be aware of this or you'll potentially lose a byte every time you send one.

I haven't started on the 6502 code yet, but I believe the functionality would look something like this (someone correct me if I'm off base here):

Receiving data:
- Interrupt handler reads a byte (until buffer is empty) via SPI and stores it in receive buffer

Sending data:
- Disable interrupts to prevent being stomped by a read in the middle of our SPI transaction
- Send a byte via SPI
- If the "R" bit is set in the response, we also got a byte from the buffer. If so, store it in the receive buffer.
- Enable interrupts

I haven't experimented with what happens when you send too quickly, but there is a "T" flag in the send response to let you know if the transmit buffer is empty, as well as an option for an interrupt when sending is completed. I assumed I'd just set the baud rate fast enough that I couldn't over drive it from the 6502.


Top
 Profile  
Reply with quote  
PostPosted: Mon Jan 17, 2022 8:54 pm 
Offline

Joined: Sun Sep 19, 2021 11:21 am
Posts: 23
Greg816v2 wrote:
Maybe this will help -


Thank you, I will take a look. :)


Top
 Profile  
Reply with quote  
PostPosted: Wed Jan 19, 2022 7:35 am 
Offline

Joined: Tue Jan 11, 2022 5:56 pm
Posts: 17
I'm getting around to implementing my 6502 code and wanted to say thanks for the code examples Garth. I realize now I've read through your site years ago, really good stuff.


Top
 Profile  
Reply with quote  
PostPosted: Wed Jan 19, 2022 7:48 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8447
Location: Southern California
Greg816v2 wrote:
I realize now I've read through your site years ago, really good stuff.

Thanks.  If it was years ago, you'll find several new major features there now.  I'm constantly making little updates to existing pages too.  I'll take advantage of your progress when you're happy with what you have, and add working MAX3100 assembly-language code to the site, to help others.  It seems appropriate, since I have been promoting the 3100 here.  I like its capabilities, and the fact that it's only 16 pins, and that it takes so few lines to interface it.  It's not urgent, so since I've only exercised it but not put it to serious use yet, it makes sense to see how it goes for you and see what you might run into.

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
PostPosted: Thu Jun 16, 2022 8:10 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8447
Location: Southern California
I know from plenty of experience that life gets in the way and sometimes projects get backburnered for long periods of time, or experience long delays; but I'll ask: Is there any more progress on this?

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: