Hi..!!!
Yes.
I have read this again and again, but still problem is there.
From master I am sending following data (int array[8] = {0x04, 0x00, 0x06, 0x00, 0x08, 0x00, 0x0A, 0x00} and on slave side I am receiving the same data. But same data are available on both MOSI and MISO.
I can see on oscilloscope that even MISO line has the same data which are ( int array[8] = {0x04, 0x00, 0x06, 0x00, 0x08, 0x00, 0x0A, 0x00} on MOSI also.
But from slave side I am not sending any data then why data are available on line(MISO), is there any way to clear buffer or SPDR.
//Master sending data
//Master sending data
#include <SPI.h>// include the SPI library:
#define SCK_PIN 13
#define MISO_PIN 12
#define MOSI_PIN 11
const int spidata = 10;//Pin 11 is data(MOSI) and pin 13 SCK ,set pin 10(SS) as the slave select for the digital pot:
int array[8] = {0x04, 0x00, 0x06, 0x00, 0x08, 0x00, 0x0A, 0x00};
int chr;
void setup() {
pinMode (spidata, OUTPUT);// set the spi_data_pin as an output:
SPI.begin();// initialize SPI:
Serial.begin(115200);
SPI.setDataMode(SPI_MODE2);
SPI.setClockDivider(SPI_CLOCK_DIV64) ;
SPI.setBitOrder(LSBFIRST);
}
void loop() {
int data[10];
char ch;
digitalWrite(spidata,LOW);
SPI.transfer(array[0]);
SPI.transfer(array[1]);
digitalWrite(spidata,HIGH);
digitalWrite(spidata,LOW);
SPI.transfer(array[2]);
SPI.transfer(array[3]);
digitalWrite(spidata,HIGH);
digitalWrite(spidata,LOW);
SPI.transfer(array[4]);
SPI.transfer(array[5]);
digitalWrite(spidata,HIGH);
digitalWrite(spidata,LOW);
SPI.transfer(array[6]);
SPI.transfer(array[7]);
digitalWrite(spidata,HIGH);
}
//Slave receiving data
//Slave receiving data
#include "pins_arduino.h"
#include <SPI.h>
// what to do with incoming data
byte command = 0;
void setup (void)
{
Serial.begin(115200);
// have to send on master in, *slave out*
pinMode(MISO, OUTPUT);
SPI.setBitOrder(MSBFIRST);
SPI.setDataMode (SPI_MODE2);
SPI.setClockDivider(SPI_CLOCK_DIV64) ;
// turn on SPI in slave mode
SPCR |= _BV(SPE);
// turn on interrupts
SPCR |= _BV(SPIE);
} // end of setup
// SPI interrupt routine
ISR (SPI_STC_vect)
{
byte c = SPDR;
Serial.println(c, HEX);
}
void loop (void)
{
// if SPI not active, clear current command
if (digitalRead (SS) == HIGH)
command = 0;
} // end of loop