Shop OBEX P1 Docs P2 Docs Learn Events
Bus Communications — Parallax Forums

Bus Communications

DiscoveryDiscovery Posts: 606
edited 2015-05-16 09:56 in Propeller 1
I need to send the binary equivalent of a decimal variable over an 8-bit bus.

The bus is formed using Propeller Pins
P0 Bus 0
P1 Bus 1
P2 Bus 2
P3 Bus 3
P4 Bus 4
P5 Bus 5
P6 Bus 6
P7 Bus 7

int i ranges from 0 to 255.

Is there a 'C' library instruction that does this simple task?

Sincerely,

Discovery

Comments

  • David BetzDavid Betz Posts: 14,516
    edited 2015-05-13 15:19
    Any reason you can't just do this?
    #include <propeller.h>
    
    void write_to_bus(int i)
    {
        DIRA |= 0xff;    // make P0-P7 outputs
        OUTA = (OUTA & ~0xff) | (i & 0xff);
    }
    
    and if you're sure that i won't contain a value greater than 255 you can leave out the "& 0xff" part of the second statement.
  • David BetzDavid Betz Posts: 14,516
    edited 2015-05-13 15:45
    This may be a more direct answer to your question. Here is a link to the description of the Simple Libraries function to set a group of pins:

    https://propsideworkspace.googlecode.com/hg/Learn/Simple%20Libraries/Utility/libsimpletools/html/simpletools_8h.html#acbf5fe86eb36a02d4f86df2d3ca8d84d

    You should be able to do what you're asking with this code:
    #include <simpletools.h>
    
        set_outputs(7, 0, i);
    
  • DiscoveryDiscovery Posts: 606
    edited 2015-05-13 16:24
    Hi David,

    I ran the following code on my Propeller Activity board.

    i = 1;
    set_outputs(7, 0, i);

    and could not set any output pins.

    I will try your write_to_bus instruction next.

    Discovery
  • DiscoveryDiscovery Posts: 606
    edited 2015-05-13 16:52
    Hi David,

    The write_to_bus(int i) code compiled correctly but did not set the pins.

    i was set to various values 1, 2, 3...etc. but the pins remained low.

    The pins do work via high(0)...etc.

    Do you have a Propeller Activity Board you can run your code on to verify functionality?

    Discovery
  • DiscoveryDiscovery Posts: 606
    edited 2015-05-13 17:21
    David,

    My fault...the write_to_bus works perfectly well.

    I had to make i a static volatile int and the function works great.

    Thank you.

    Discovery
  • David BetzDavid Betz Posts: 14,516
    edited 2015-05-13 18:52
    Discovery wrote: »
    Hi David,

    I ran the following code on my Propeller Activity board.

    i = 1;
    set_outputs(7, 0, i);

    and could not set any output pins.

    I will try your write_to_bus instruction next.

    Discovery
    I've never used these functions but you might need to call:
        set_directions(7, 0, 0xff);
    

    first to set pins 7:0 to outputs. You only need to do that once though at the beginning of your program, not every time you call set_outputs.
  • DiscoveryDiscovery Posts: 606
    edited 2015-05-13 19:51
    Dave,

    The set_directions instruction did the trick. Both of your suggestions work just fine.

    Sincerely,

    Discovery
  • DavidZemonDavidZemon Posts: 2,973
    edited 2015-05-16 09:56
    Another option is PropWare's Port and SimplePort class. Since your pins are all consecutive, SimplePort would work wonderfully for you. Built for exactly what you're doing (I was working on an HD44780 LCD driver when I made it)
Sign In or Register to comment.