Go Down

Topic: interfacing a bus to the arduino (Read 521 times) previous topic - next topic

phoenixcomm


ok I have a group of four(4) rotary switches each switch is position is pulled up and then connected to a 74LS125 a tri-state bus. then they are tied together to form a bus. In this way I can control the data getting on the bus. The bus is connected to a 74LS147 priority encoder which is connected to the arduino.

In the world I come from 68k If you have a bus you need  a r/w line and a data valid line
so basically I set the r/w to w(low) output the switch address on the  bus (high nibble) and then put a data_valid which tells the
thing that data  is ok.
Then set the r/w to read(high) and then put a data_valid which tells that you just read the output (low nibble).
KiCad File:www.flite-tronics.com/temp/proto_CP-1252.switches.sch
SVG File: www.flite-tronics.com/temp/proto_CP-1252.switches.svg

but there are no Data_Valid or R/W lines on the arduino.. Please Help...
oh BTW there is also a ps2 keyboard and I am sending the data up the virtual serial bus (USB)
Thanks I really need the help.. :smiley-eek-blue:

phoenixcomm@gmail.com

johnwasser

The ATmega processor is generally used for simple devices that only need a few bits of I/O so it doesn't have an external data bus.

It looks like you are trying to read 16 bits from four hex (or decimal) rotary switches.  The typical Arduino way would be to use 16 input pins if you can spare them.  If you can't spare 16 inout pins you can daisy-chain two 8-bit parallel-in/serial-out shift registers.  These can connect to three I/O pins (Latch/Clock/Data).  The shiftIn() function does most of the work.

If you want to read shift registers VERY quickly you can use the SPI hardware.
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

phoenixcomm

:smiley-roll-sweat: Yes I have 4 switches.. 2 are bcd and 2 go trough priority encoders  via the tri-state bus. that way I only read 1 switch at a time and all I need input is 4 bits on input but I need the other 4 bits for controlling the tri-state bus enables and that is 3 bits 

:smiley-mr-green:so the logic would be as follows this is only an outline...   

for( count =0; count < 4; count ++ ){     // valid values for count are 0, 1, 2, or 3
for( odd = 0; odd < 2; odd ++){             // valid values for odd are 0 or 1
  write low order 3 bits of count on high order data lines      // address
  write data_valid                                //delay for data settling time
  read  data low order nibble
  buffer[odd]  = put data 8 bits
  if ( buffer[0] != buffer[1]){
    serial.write (buffer[odd]) // send the data to the host.
}}

johnwasser

This is sort of how that might look on an Arduino:

Code: [Select]

  for(int count = 0; count < 4; count ++ ) {     // valid values for count are 0, 1, 2, or 3
    for(int odd = 0; odd < 2; odd ++) {             // valid values for odd are 0 or 1

      // Set data bus to output and default all output bits to LOW
      digitalWrite(readWritePin, LOW);  // Write Mode
      for (int bit = 0; bit < 8; bit++) {
        pinMode(dataBusPins[bit], OUTPUT);
        digitalWrite(dataBusPins[bit], LOW);
      }

      // write low order 3 bits of count on high order data lines      // address
      for (int bit = 0; bit < 4; bit++) {
        digitalWrite(dataBusPins[bit + 5], count & (1 << bit));
      }

      // write data_valid                                //delay for data settling time
      digitalWrite(dataValidPin, HIGH);  // Write
      digitalWrite(dataValidPin, LOW);
     
     // read  data low order nibble
     // Set data bus to input
      digitalWrite(readWritePin, HIGH);  // Read Mode
      for (int bit = 0; bit < 8; bit++) {
        pinMode(dataBusPins[bit], INPUT);
      }

      int value = 0;
      for (int bit = 0; bit < 4; bit ++) {
        value |= (digitalRead(dataBusPins[bit]) << bit);
      }

      // buffer[odd]  = put data 8 bits
      buffer[odd] = value;

      if ( buffer[0] != buffer[1]) {
        serial.write (buffer[odd]); // send the data to the host.
      }
  }
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Go Up