Shop OBEX P1 Docs P2 Docs Learn Events
SPI communication from propeller (master) to arduino (slave) — Parallax Forums

SPI communication from propeller (master) to arduino (slave)

SneakyeanSneakyean Posts: 6
edited 2012-03-07 16:28 in Propeller 1
Howdy,
I am trying to establish communication between an arduino and my propeller board. I have tried the object BS2 Functions with the shiftin and shiftout commands to no avail.
Has anyone ever established SPI communications between these two boards successfully. If so, any help would be appreciated.
I using the usual connections,
chip select
master out, slave in MOSI
master in, slave out MISO
clock
power
ground
Thanks
sneakyean

Comments

  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-03-05 15:21
    Is there a reason you don't want to just use an asynchronous serial connection?

    If you want to use SPI, I assume you want the Prop to be the slave? I tried something like this recently. I was surprised at how much harder writing a slave SPI driver was then writing a master driver.

    I don't know off the top of my head of any SPI slave driver object (that wasn't supposed to sound as bad as it did).

    On the other hand, an asynchronous serial connection would be pretty easy.

    BTW, I really don't think BS2 Functions' shiftin and shiftout would work for this application. They both assume the Prop's the SPI master.
  • Mike GreenMike Green Posts: 23,101
    edited 2012-03-05 15:23
    With SPI communications, one device is considered a master and the other is considered a slave. The master furnishes the chip select and the clock pulses. The BS2 Functions object (and all of the other SPI objects in the Object Exchange) is written assuming that the Propeller acts as the master. Probably the Arduino code assumes the same thing which is why you can't get this to work. You could modify or rewrite the BS2 Functions code to act like an SPI slave or do the same thing with the Arduino code. It should be straightforward for either. I'm not aware of any posted sample code or previous projects that do this sort of thing. There was someone who got a Propeller to act as an I2C slave, but I don't have any link to relevant posts. Someone else may.
  • SneakyeanSneakyean Posts: 6
    edited 2012-03-06 03:54
    Howdy again. The Prop is supposed to be the master and the arduino the slave. The arduino has a program on it that is supposed to read an angle from a rotating beacon. It is then set up to send that info to the master board on a robot. My students are using a propeller board as their main robot board. They used a BS2 for last year's robot and we used the shiftin command to get the angle from the beacon and all was well.
    We have migrated to propeller and we are trying to do the same thing. We, unfortunately, have to use this arduino since it has the program on it that communicates with this beacon. It is set up to use SPI communication so we didn't have a choice in this matter. The arduino code is written assuming it is the slave and the other board is master. The prop board does set the clock.

    So given that, I was confused why the BS2 Functions code wasn't working since my prop board is the master.
  • blittledblittled Posts: 681
    edited 2012-03-06 05:55
    Are the clock and polarity of the master and slave the same? If not they won't communicate. See http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus for a description on clock and polarity.
  • pgbpsupgbpsu Posts: 460
    edited 2012-03-06 07:40
    You might find another implementation of the SPI protocol useful. There's a very easy to follow version by Andrew LaMothe in the attached file. It would take a bit of editing, but I believe everything you need is there for the Prop to run as master. Some of the methods could be removed or ignored. I think you'd need the Init and the SPI_Write_Read. As a protocol, I find SPI to be more straight forward than most, no timing to get just right. If you can deal with the speed (or slowness depending on your point of view) this Spin implementation should allow you to easily see what's going on.

    pb
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-03-06 07:40
    It might help if you post the BS2 code you had previously used. Maybe someone here could translate it to spin.

    Could you provide more information about the rotating beacon? Do you have the Arduino code you use?
  • SneakyeanSneakyean Posts: 6
    edited 2012-03-07 07:59
    I doubt the clock and polarity are the same but neither is that true for the BS2 and arduino and that does work. I have slowed the prop to 20mHz so it matches the basic stamp times - the arduino runs at 16.
    The code for the Basic stamp is at the bottom.
    The beacon is rotating, finds the robot, figures out the angle to that robot (based on a compass heading of north), then sends that angle to the arduino who is supposed to communicate with the attached program to the master.
    The arduino receiving program is attached as is my spin program that is supposed to do the same thing.
    Here is the website for info about the beacon if that is helpful
    http://spacegrant.colorado.edu/index.php/rcbeaconinfo
    Thanks for your help!!!



    CS PIN 8 ' Chip Select
    DATAfromBS PIN 9 ' Data from BS to Arduino
    DATAtoBS PIN 10 ' Data from Arduino to BS
    Clock PIN 11 ' Clock


    '
    [ Init Setup ]

    results VAR Byte ' Results

    '
    [ Program Code ]



    DO

    LOW CS
    SHIFTIN DATAtoBS, Clock, MSBPRE, [results] 'request the BR value
    SHIFTOUT DATAfromBS, Clock, MSBFIRST, [ 202] 'write 202 to the Arduino as a staleness indicator
    HIGH CS

    DEBUG "Shifted In Value = ", DEC results, CR
    PAUSE 3000


    LOOP
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-03-07 09:26
    There are two SPI objects in the Propeller Tool's library. There is a demo for each object in the "_Demos" folder.

    That's were I'd start.

    This looks like a very interesting project.
  • RickInTexasRickInTexas Posts: 124
    edited 2012-03-07 16:28
    Sneakyean wrote: »
    Howdy,
    I am trying to establish communication between an arduino and my propeller board. I have tried the object BS2 Functions with the shiftin and shiftout commands to no avail.
    Has anyone ever established SPI communications between these two boards successfully. If so, any help would be appreciated.
    I using the usual connections, ...

    XGamestation sells a Propeller/AVR board that does exactly that, AVR (Arduino compatible) that has the Prop configured as a SPI Master. http://www.xgamestation.com/view_product.php?id=51.

    The idea is to leverage the Propeller for it's graphics, keyboard, etc. Very slick idea as GUI on microcontrollers is a pain, but the Propeller really shines here. They offer a 16-bit Pic 24Hxx version also. Complete s/w h/w info including source code for both can be found here: http://www.chameleon-dev.com/pmwiki.php
Sign In or Register to comment.