2

Is it possible to output integer binary values to GPIO pins at once like a parallel port?

I need that because I am afraid if I toggled pins one by one there will be invalid intermediate states that will cause wrong behavior in the circuit connected to GPIO.

I prefer software solution but any other idea to overcome this is welcomed.

M.Sameer
  • 151
  • 1
  • 6

4 Answers4

2

You can't change the values of multiple GPIO pins simultaneously. Parallel ports don't do this either, they handle it by having an additional control pin (Strobe) to tell the device that the data is ready.

If you use an extra pin (I'll call it the Ready pin) you could use a process like this:

  • Set Ready pin to low
  • Set data pins to the correct values.
  • Set Ready pin to high

Now this has a problem, how do you know if the remote end has read the data and can accept more? 2 possible solutions:

  • Assume the remote end is guaranteed to read the data in some maximum time and keep the Ready pin high for a minimum of that amount of time.
  • Add an additional Acknowledge pin that the remote end will set to high when it has read the data. The Raspberry pi will keep the Ready pin high until the ACK pin goes high.
Craig
  • 3,014
  • 14
  • 15
1

@OP The answers provided are not correct and its apparent that these posters do not understand the GPIO architecture of the device. You can and I've done it. There's C code here - http://elinux.org/RPi_Low-level_peripherals#C_2. You just need to modify a couple of lines. Then you can set and clear GPIO in parallel.

Wrong
  • 11
  • 2
1

M.Sameer: It sounds like you are on the right track. To test this, you can modify the following lines in the file

// Old                                  
  for (rep=0; rep<10; rep++)            
  {                     
    for (g=7; g<=11; g++)     // Delete    
     {                        // Delete    
       GPIO_SET = 1<<g;       // Delete    
       sleep(1);              // Delete    
     }                        // Delete    
     for (g=7; g<=11; g++)    // Delete    
     {                        // Delete    
       GPIO_CLR = 1<<g;       // Delete    
       sleep(1);              // Delete    
     }                        // Delete    
  }                     

  // New                    
  for (rep=0; rep<10; rep++)            
  {                     
    // Toggle GPIO 7 & 8 concurrently       
    GPIO_SET = 3<<7;       // Added         
    sleep(1);              // Added         
    GPIO_CLR = 3<<7;       // Added         
    sleep(1);              // Added         
  }     

Have a look at the Broadcom 2835 datasheet. There are separate SET and CLEAR registers to control a vector of GPIO. What value you write to these registers will determine which and how many GPIO get set and cleared at the same time. Hope this helps.

RPiAwesomeness
  • 3,021
  • 4
  • 31
  • 52
Right
  • 11
  • 3
0

parallel communication is long gone, most HDD drives today are SATA and you can hardly find any parallel port on the back of your average PC.

considering the lack of GPIO pins, the best idea might be to use serial communication, either the serial port or, if you are adventurous type, the i2c port.

lenik
  • 11,533
  • 2
  • 32
  • 37