Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Routing data from the Serial port to ICs

  1. Aug 21, 2007 #1
    Hello All,

    I am currently trying to figure out how to program the AD9959 IC using a serial connection to my PC.

    From reading through the datasheet for this chip, I learned that it uses the serial SPI interface to send and recieve instructions and data. This chip has four channels of DDS and allows you to program the frequency (32-bit), phase-shift (14-bit), and amplitude (10-bit). The chip has a lot of other, more advanced features (like modulation and frequency sweeps) that I don't care to make use of.

    My circuit board will also have some other digital inputs to control separate chips on the board that control the pulse width of the output signal (the DDS outputs sine waves but I will be using logic chips to convert them to short adjustable duty cycle square waves).

    I'm just wondering how to use the serial port to select which chips I send data and instructions to. I *think* that I want to use the MAX3110E IC which can convert the RS232 level signals into the SPI compatible ones. The problem is that everything coming out of that chip is now serial and I'm not sure how to control where the bits go.

    I was trying to come up with some kind of scheme where I could input the serial data into a shift register to control the lines of a multiplexer or something to route further bits to either the AD9959 or the chip that would control the pulse width.

    As for the pulse width chip, I'm still looking into different ways to do it but I know I will want some kind of digital input to control it. To keep the complexity of the circuit down, I have decided to control all four channels with a single data input. I'm thinking I'll use either four or eight-bit input to control the duty cycle. Is there any simple method for routing the bits without using a microcontroller?

    Thanks,
    Jason O
     
  2. jcsd
  3. Aug 21, 2007 #2

    chroot

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    The RS-232 standard defines a lot of signals that you're not actually going to use to send data to the SPI interface. The signals like CTS/RTS, for example, are going to be unused. These signals can be easily set with software on the PC, and thus can be used to select which device you want to talk to.

    The SPI interface includes an enable signal; use one of those control lines to enable each chip on the bus. If you have a ton of chips, use a 3-to-8 decoder or something to expand the number of selection lines available.

    - Warren
     
  4. Aug 21, 2007 #3
    Hi Warren,

    Thanks for that. That (once again) simplifies things tremendously. Now all I have to do is figure out how to program the individual pins directly. Also, would you happen to know of any good websites with an in-depth discussion on working with the RS232/SPI interface?

    Thanks,
    Jason O
     
  5. Aug 21, 2007 #4

    berkeman

    User Avatar

    Staff: Mentor

    RS-232 is called the SCI interface, and is different from the SPI serial communication standard. SCI has no clock, just the data. The sender and receiver must have accurate time bases, and use a baud rate that both the sender and receiver agree upon. SPI uses a separate clock line, and the data rate can vary. The master generates the clock, and transmits data on the MOSI (master out, slave in) line. The slave drives data back to the master on the MISO line.

    I don't think you will be able to easily drive an SPI interface from your RS-232 port. You would need to bit bang both a clock and a data line, and the RS-232 serial SCI UART is not going to be able to receive data on its RX line from the MISO line, since the UART is assuming some baud rate.
     
  6. Aug 21, 2007 #5

    mgb_phys

    User Avatar
    Science Advisor
    Homework Helper

    You can't drive an SPI from a rs232 port.
    You can with either a realtime os or a very low baud rate bit-bang an spi interface from the parralel port ( bit-bang = change the state of a single wire at the right pattern to simulate a serial interface)


    Some dev kits include an SPI-serial converter, otherwise they are quite expensive. The easiest way to do SPI-serial is with a PIC.
    If you are in the UK give these people a call they are very helpful http://www.milinst.com/
     
  7. Aug 21, 2007 #6

    berkeman

    User Avatar

    Staff: Mentor

    I think mgb_phys is on the right track with the PIC suggestion. If you can find a cheap PIC with an SCI serial port (maybe somebody makes a small module like that?), the PIC may have an SPI serial port as well. Then you could program the PIC to receive your commands over the SCI serial port from the PC (you can just send them using hyperterminal), and write the appropriate config register data to the AD9959 via SPI.
     
  8. Aug 21, 2007 #7
    Hi Guys,

    Thanks for the suggestions. I guess that I ultimitely could just use a PIC but I was trying to find a way to do this without needing to program one. As for the RS232 to SPI interface, I thought that this chip, MAX3110E, was supposed to handle the conversion?

    - Jason O
     
  9. Aug 21, 2007 #8

    berkeman

    User Avatar

    Staff: Mentor

    No, the MAX3110E is an SPI slave, it cannot function as an SPI master. Look at the block diagram at its info page:

    http://www.maxim-ic.com/quick_view2.cfm/qv_pk/2052

    The part can be an SPI slave for a uC to use as a serial SCI UART. It is not intended to be used to convert SCI to an SPI master.
     
  10. Aug 21, 2007 #9
    Ohhhh ok I see now.

    Well, I guess I'll have to use the uC then. I was able to find an interesting article online where this guy used a BASIC Stamp to interface with the Maxim chip:

    http://www.wd5gnr.com/suart.htm

    The code looks like goo gaa to me though. I do know Visual Basic very well but I have 0 experience with basic stamps (or any microcontroller for that matter). Would you happen to have any recommendations for a tutorial or something I could read to learn how to program one? What kind of basic stamp should I use?

    Thanks,
    Jason O
     
  11. Aug 21, 2007 #10

    mgb_phys

    User Avatar
    Science Advisor
    Homework Helper

    You can use a Stamp and manually set one pin high/low to simulate the SPI port ( see bit-banging) the Stamps have a serial port included.

    Basic Stamps are a cheap and easy way into uC programming if you don't know C or don't want to buy a development kit, milinst in the link above list some books.
    But they are expensive if you want to use them in production and are very slow compared to even a PIC.
     
  12. Aug 21, 2007 #11

    chroot

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    I think bit banging would be perfectly sufficient for this application. I see no reason to include a microcontroller.

    - Warren
     
  13. Aug 21, 2007 #12

    berkeman

    User Avatar

    Staff: Mentor

    I can see maybe bit banging the SCLK and MOSI downlink signals, but how do you read the uplink MISO signal? I guess if you go slowly enough, it might work. I guess you would just use all SCI control lines for the bit banging, and avoid the TX and RX SCI signals altogether?
     
  14. Aug 21, 2007 #13

    chroot

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    This is a write-only application; he does not need to read back from his devices at all.

    You all bring up some good points, though. It might even be easier to just use the parallel port to bit-bang SPI signals.

    - Warren
     
  15. Aug 21, 2007 #14
    Could you guys elaborate more on this "bit-banging" idea? What is it and how does it work? If I wouldn't need a microcontroller to do it, how would I do the communications?

    Thanks,
    Jason O
     
  16. Aug 21, 2007 #15

    chroot

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    They're basically saying the clocking mechanism in RS-232 is not directly compatible with the clocking mechanism for SPI.

    To communicate with an SPI device, you have to produce your own clock. They're talking about driving a control line high and low over and over to "simulate" a clock. That's "bit banging:" drive 1, drive 0, drive 1, drive 0...

    In retrospect, I suppose using a parallel port would be significantly easier. I believe the voltages on the parallel port are already compatible with CMOS.

    - Warren
     
  17. Aug 21, 2007 #16

    berkeman

    User Avatar

    Staff: Mentor

    Ah, good point about the write-only aspect. I guess there are no registers that he needs to read for anything after all.

    I went back and skimmed through the datasheet -- not all SPI slaves have a fully static SPI interface. Some will time out the transaction if the clock stays static for too long (around 100us is a common number, IIRC). But I didn't see anything about a timeout on SCLK (I could have missed it), so even if the bit banging gets wobbled around by Windows scheduler jitter, it looks like bit banging could work.
     
  18. Aug 21, 2007 #17
    Ok, so if I use the the parallel port to do this, but I want to use a serial connector on the board (to save space) could I just use a parallel to serial converter jack to still wire the pins in and only use the pins from the parallel port that I need? Also, what chip should i use to interface the port with the port?

    I am still considering using a BASIC Stamp to do this just for the learning experience. I was looking at Parallax's website at this basic Stamp II OEM board which has a serial port built into it already:

    http://www.parallax.com/detail.asp?product_id=27290

    I call the tech support people and they said that you could also communicate through the serial connection as well as program the chip. The only thing I don't know is how to do SPI to the AD9959 with it...

    But I am interested in knowing how I would pull this off without one using the bit-banging method :smile:

    Thanks,
    Jason O
     
  19. Aug 21, 2007 #18

    berkeman

    User Avatar

    Staff: Mentor

    You will probably get the most useful learning experience with the Basic Stamp and serial port thing. Does the Basic Stamp also have an SPI port on some of it's other IO pins? If not, you can still bit-bang the SPI interface to the AD9959. Just look at the SPI waveforms shown in the AD9959 datasheet, and think about how you would do writes to a byte-wide output register to generate the SCLK and MOSI (and CS) signals to the slave AD9959. Does that make sense?


    EDIT -- One reason I say this is that the current trend in operating systems like WinXP, etc., is to give you less programmatic access to hardware resources like the serial and parallel ports. It has gotten harder to bit-bang those IO ports over the years, and is very difficult now. The trend is to use USB or other standard interface out of the PC/laptop, and have some intelligence (usually uC based) out at the end of the cable that serves as the interface to whatever is external that you want to communicate with.


    EDIT2 -- Not too many years ago at my work, we based an important internal R&D Lab test IO interface to a new chip on bit-banging the parallel port of PCs. Well, the timing varied based on the PC brand and model, and the interface was only reliable on a few select machines. Doh! So we learned our lesson and based the 2nd generation of those chip test devices on a National Instruments DIO card family, which had reliable timing (independent of Windows XP/whatever OS scheduling jitter, and with reliable IO timing specifications).
     
    Last edited: Aug 22, 2007
  20. Aug 22, 2007 #19

    chroot

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    He doesn't need reliable timing for an extremely slow DC serial bus! If it's normally-implemented SPI, it's STATIC LOGIC anyway -- the clock needn't have any specific period or timing relationship at all, and there's no minimum clock period.

    Again, there's no need for any kind of uC.

    - Warren
     
  21. Aug 22, 2007 #20
    @berkeman,

    Hmmmm thats very interesting :smile:. You know, thats the one thing I was worried about with the bit-banging idea. the output data would then be subject to the speed of the computer and what it is doing at the time.

    I'm not sure if the basic stamp has a dedicated SPI output but I heard from reading that you use the BASIC SHIFTIN/SHIFTOUT commands to do SPI communications. So it doesn't look too horrible once I figure out how to do it :smile:

    @all,

    So at this point, its looking very doable to use the basic stamp. Now the big problem I'm facing is how to setup the AD9959......

    I've been staring at the datasheet for several days now and I'm still confused about what settings and pins to set to make it do what I want.... There's just so many features and options in it, I'm not sure where to start. How would you approach this?

    - Jason O
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?



Similar Discussions: Routing data from the Serial port to ICs
  1. VHDL Serial Port (Replies: 0)

  2. Serial Port (Replies: 3)

Loading...