Shop OBEX P1 Docs P2 Docs Learn Events
Question about performing SX comms to A/D thru SPI Microwire — Parallax Forums

Question about performing SX comms to A/D thru SPI Microwire

marktmarkt Posts: 2
edited 2005-07-05 18:50 in General Discussion
Hi there,

Please understand that I am new to programming the SX28, but thankfully I have a programming background in Assembly, Java, C, C++.·

I am in the process of developing an application for a weigh scale that will use a CS5531.· This is an analog to digital convertor that has an SPI/Microwire interface through CS, SDI, SDO, SCLK.· I have a great many questions of course.· Some of the main ones are:

1) Is there free source code for performing this type of SPI communications already available?

2) Will I need to add·additional memory to support this kind of functionality?· If so, is there any guides?· I have been looking at the 24LC128


Also, I need to get up to speed ASAP on implementing support for the SX28.· Does anyone have any suggestions as to the sequence of going through the reading materials, tutorials, etc.?·


Any help/suggestions would be very much appreciated.

Thank you,
Mark.

Comments

  • KenMKenM Posts: 657
    edited 2005-06-13 02:27
    I don't have any source code but if it exists sxlist.com would be a good place to start looking.

    Ken
  • BeanBean Posts: 8,129
    edited 2005-06-13 10:47
    You can use the SX/B compiler. It has SPI (SHIFTOUT) commands built in.
    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "SX-Video·Module" Now available from Parallax for only $28.95

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

    Product web site: www.sxvm.com

    "If you keep doing what you always did, you'll keep getting what you always got."
    ·
  • marktmarkt Posts: 2
    edited 2005-07-05 16:43
    Thank you for your information. Sorry it took a while to reply. I have been using the information you supplied.

    A question regarding the SHIFTOUT SX/B command; I found a Basic Stamp program that communicates with a Cirrus CS5531 which is exactly what I need but for SX28 so I need to convert. The SHIFTOUT command seems to be "expanded" with the Basic Stamp compiler and allows the programmer to concatenate a series of bits plus multiple bytes of data in a very flexible manner, whereas SX/B SHIFTOUT command allows a maximum of 8 bits in a single command statement. My question is, how can I get around this limitation? Do I use an array of bytes together with a loop to call the SHIFTOUT command multiple times, using the loop index counter to pass all the bytes of the array? Or, is this going to get me into trouble? The SPI code support for the SC5531 requires >32 bits of data passed with each SHIFTIN/SHIFOUT. If I use mutliple instances of SHIFTIN/OUT I will burn up all my memory. Other thoughts I was playing with was to look at the assembly created and try modifying to expand number of bits (could be time consuming). Also, maybe a subroutine passing the data to and from a SHIFOUT and SHIFTIN sub. Here is a code sample that I was playing around with:

    idx var byte 'loop counter
    dathi var byte(2) '16 bit high address
    datlo var byte(2) '16 bit low address
    ...

    for idx = 0 to 1
    shiftin SDO,SCLK,0,dathi(idx)
    next

    ...

    Any help would be much appreciated.

    Thanks again,
    Mark T.
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-07-05 17:36
    No, SX/B works a byte at a time. If you always want to send the same number of bytes then you could use PUT to move them to an array, then call a subroutine to sends that array out your SPI connection.

    The key to not "burning up all you memory" is to put SX/B commands into subroutines -- the same way assembly programmers do. If you were coding in pure assembly you wouldn't duplicate code for shifting bits out an SPI port, so don't so it in SX/B. The SX/B help file does have SPI examples that you can learn from. Take your time and build your project slowly -- if you try to rush through it you'll end up creating more problems than solving.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • pjvpjv Posts: 1,903
    edited 2005-07-05 18:23
    Hi Mark;

    About two years ago I did a project making a rather compicated strain gage weighing system using multiple remotely located CS5525, each with its own SX, all communicating RS485 back to one central where the controls and display were loctaed. It was very complicated and a LOT of work (those chips are not all that friendly and several poorly documented traps), but once I got it done, they have been operating reliably in the field. We were able to reliably measure one gram in 30 Kilograms.

    As this relates to industrial measurement and control systems, (the business I'm in), I would only be interested in selling my design and software at commercial rates. I'm POSITIVE I will save you a TON of time, hence presumably a ton of money.

    Cheers,

    Peter (pjv)
  • Paul BakerPaul Baker Posts: 6,351
    edited 2005-07-05 18:50
    Applications Notes (13th and 14th in the list) on this page provide code for both SPI master and slave modes in SX assembly, while I believe the code is designed for 8 bit quanities, you have the ability to modify the code to achieve larger packet sizes, something more difficult to do with SX/B SHIFTOUT.
Sign In or Register to comment.