Implementation of dual IO SPI

Hi,

I need to communicate with dual IO SPI device. I want to implement it or to use the SPI library.

Currently I can't find any support for dual IO SPI.

This is very urgent project, Is arduino able to wirte using dual IO SPI???

Thank you, Nir

(deleted)

I don't need to control 2 devices. In dual-SPI mode the hardware configuration is similar to the one in single mode, but here two lines are used for data.

It is called SDI.

The next level is SQI.

Hi,

I would like to implement SPI with 2 lines of MOSI and 2 lines of MISO. How can I do that?

Thank you

Please do not cross-post. Threads merged.

https://www.google.com/search?q=bit+bang+spi

...should get you started.

Thank you very much.

Still, All examples are for standard SPI.
My issue is that I have 2 Data Bits (MOSI[1:0]) and the data is splitting between both. for example:

Data=1101010101

MOSI[1]=10000
MOSI[0]=11111

And than I should transfer them both together and not cascade.

How can I deal with that??

Thank you in advance.

Nir

nirtzi:
How can I deal with that??

Find a bit-bang implementation you can understand. Extend it to two data bits. Enjoy.

If you run into problems, ask for help. Post your code. Use
</mark> <mark>[code]</mark> <mark>

</mark> <mark>[/code]</mark> <mark>
tags. Include a schematic.

Hi,

I implemented a simple code and I notice that my clock cycle is decreasing during my 8 bit writing (Picture included - CLK==Green).
I can’t explain it.

Do you have any Idea???

Thanx

%Code begin%

const int SS_pin = 12;
const int SCK_pin = 13;
const int MISO_pin = 11;
const int MOSI_pin = 10;

byte sendValue = 74;   // Value we are going to send
byte returnValue = 0;  // Where we will store the value sent by the slave

void setup()
{
  digitalWrite(SS_pin, HIGH);  // Start with SS high
  PORTB &= ~_BV(PORTB5); // SCK low
  
  pinMode(SS_pin, OUTPUT);
  pinMode(SCK_pin, OUTPUT);
  pinMode(MISO_pin, INPUT);
  pinMode(MOSI_pin, OUTPUT);
}

void loop()
{
  digitalWrite(SS_pin, LOW);        // SS low
  returnValue = bitBang(sendValue); // Transmit data
  digitalWrite(SS_pin, HIGH);       // SS high again 
}


//byte bitBang(byte _send)  // This function is what bitbangs the data
//{
//  byte _receive = 0;
//  
//  for(int i=0; i<8; i++)  // There are 8 bits in a byte
//  {
//    digitalWrite(MOSI_pin, bitRead(_send, i));    // Set MOSI
//    digitalWrite(SCK_pin, HIGH);                  // SCK high
//    bitWrite(_receive, i, digitalRead(MISO_pin)); // Capture MISO
//    digitalWrite(SCK_pin, LOW);                   // SCK low
//  }
//  
//  return _receive;        // Return the received data
//}

byte bitBang(byte _send)   // This function is what bitbangs the data
{
  byte _receive = 0;
  
  for(int i=0; i<8; i++)   // There are 8 bits in a byte
  {
    if(_send & _BV(7-i))     // Set MOSI
      PORTB |= _BV(PORTB2);
    else
      PORTB &= ~_BV(PORTB2);
    
    PORTB |= _BV(PORTB5);  // SCK high
    delay(1);
    
    if(PINB & _BV(PORTB3)) // Capture MISO
      _receive |= _BV(7-i);
    else
      _receive &= ~_BV(7-i);
      
    PORTB &= ~_BV(PORTB5); // SCK low
    delay(1);
  }
  
  return _receive;         // Return the received data
}

%Code end

Moderator edit:
</mark> <mark>[code]</mark> <mark>

</mark> <mark>[/code]</mark> <mark>
tags added.

"Dual IO SPI" ... you mean connecting an ADC like this?

Some different connection schemes are shown here.

A datasheet or link to your device would be helpful and appreciated.

Actually, I attached the code for standard SPI but it is easy to modify for 6 wire SPI ( 2x MOSI, 2x MISO, clk, ss).

Now I encounter new issue of reducing clock cycle like you can see on the picture attached above (previous post). I can't understand why it happens.

Can you help with that?

Can you help with that?

If you want a consistent squarewave for SCK, controlling it should not be done within an "else" condition.

So which way do you suggest?

Thank you.

So which way do you suggest?

Just calling your bitBang() function should start changing SCK from HIGH to LOW eight times. There are no conditions where this shouldn't be the case, unless you don't want to send/receive 8 bits of data.

Hi,

Now I use that following code and the CLK is stable.
The clk rate is 40KHz.

How can I increase the rate to > 1MHz?
Is it possible using bit-bang???

Thank you.

% code %

const int SS_pin = 12;
const int SCK_pin = 13;
const int MISO_pin = 11;
const int MOSI_pin = 10;

byte sendValue = 74;   // Value we are going to send
byte returnValue = 0;  // Where we will store the value sent by the slave

void setup()
{
 digitalWrite(SS_pin, HIGH);  // Start with SS high
 PORTB &= ~_BV(PORTB5); // SCK low
 
 pinMode(SS_pin, OUTPUT);
 pinMode(SCK_pin, OUTPUT);
 pinMode(MISO_pin, INPUT);
 pinMode(MOSI_pin, OUTPUT);
}

void loop()
{
 digitalWrite(SS_pin, LOW);        // SS low
 returnValue = bitBang(sendValue); // Transmit data
 digitalWrite(SS_pin, HIGH);       // SS high again 
}


byte bitBang(byte _send)  // This function is what bitbangs the data
{
 byte _receive = 0;
 
 for(int i=0; i<8; i++)  // There are 8 bits in a byte
 {
   digitalWrite(MOSI_pin, bitRead(_send, i));    // Set MOSI
   digitalWrite(SCK_pin, HIGH);                  // SCK high
   bitWrite(_receive, i, digitalRead(MISO_pin)); // Capture MISO
   digitalWrite(SCK_pin, LOW);                   // SCK low
 }
 
 return _receive;        // Return the received data
}

% code end %

Moderator edit:
</mark> <mark>[code]</mark> <mark>

</mark> <mark>[/code]</mark> <mark>
tags added.

On a 16MHz Arduino, it will be very difficult to get to 1MHz speed. You probably need more than 16 instructions to do that loop, even if you write in assembler.

digitalWrite() is a little slow. You could speed it up significantly with digitalWriteFast() and then a further small improvement is possible with direct port manipulation.