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.