SPI interface with other board_AVR_ESK1100 or among Arduino itself

ranjeetray:

Graynomad:

but it is not giving 16 clock cycle.

How do you know that?


Rob

Respected Sir

I am seeing the output on Oscilloscope, Tektronix TDS2024C, 200MHz 2GS/s.

Thanks & Regards... :slight_smile:

Respected Sir

With the following code Arduino board is not able to generate its own clock it takes another boards when connected with MISO, MOSI, CS and SCK.
I found that once SPI_SlaveReceive(); function is initialized it is not able to generate the clock, if I comment this function or send the data or use SPI.transfer(); before SPI_SlaveReceive(); then it is able to generate the clock.
What would be the reason and how to overcome this problem.

#include <SPI.h>


#define SCK_PIN   13
#define MISO_PIN  12
#define MOSI_PIN  11
#define SS_PIN    10

unsigned char data;
int array[10] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09 }, ii;

void SlaveInit(void) {
  // Set MISO output, all others input
  pinMode(SCK_PIN, INPUT);
  pinMode(MOSI_PIN, INPUT);
  pinMode(MISO_PIN, OUTPUT);
  pinMode(SS_PIN, INPUT);

  // Enable SPI
  SPCR = B00101100;
  SPCR = (1<<SPE);
}

void setup(){ Serial.begin(9600);
            SPI.begin();
          }

void loop()
{
  unsigned char hg = 0;
  Serial.println("Data Received from Master Board");
  SlaveInit();
  data = SPI_SlaveReceive();
   Serial.println(data, HEX);
   hg = data;
   data = 0;
   delay(1000);
  
   if(hg == 0x3D)
   {
     Serial.println("Writting Data on SPI bus");
     pinMode(SS_PIN, OUTPUT);
     digitalWrite(SS_PIN, LOW);
     delay(1000);
     for(ii=0;ii<10;ii++){
     SPI.transfer(array[ii]);
     Serial.println(array[ii], BIN);
       delay(1000);      
     }
     digitalWrite(SS_PIN, HIGH);
     delay(1000);
   Serial.println("Sending Done");
    delay(1000);  
   }

}

unsigned char SPI_SlaveReceive()
{
  while(!(SPSR & (1<<SPIF)));
  return SPDR;
}

Thanks & Regards.... :slight_smile: