Go Down

Topic: SPI interface with other board_AVR_ESK1100 or among Arduino itself (Read 10 times) previous topic - next topic

ranjeetray


According to the datasheet you just posted:

Quote
Although the ADIS16400/ADIS16405 produce data independently, these operate as SPI slave devices that communicate with system (master) processors using the 16-bit segments displayed in Figure 11.


The device operates as a slave, and thus there is no requirement to jump between master/slave for each communication. Have you read my page?

http://www.gammon.com.au/spi

A simple yes/no will suffice.

Have you read the datasheet?




Hi...!!!

For testing purpose I will directly connect to OBC(On Board Computer) of satellite which will be master and my Arduino Board will be slave(IMU).

ranjeetray


[/quote]


Hi...!!!

Can anybody share the working code on SPI.

ranjeetray


Nick Gammon


Have you read my page?

http://www.gammon.com.au/spi

A simple yes/no will suffice.

Have you read the datasheet?


I think I'll close this thread if you don't answer my question. It's no use ignoring the questions and keep posting about wanting people to share code.

ranjeetray



Have you read my page?

http://www.gammon.com.au/spi

A simple yes/no will suffice.

Have you read the datasheet?


I think I'll close this thread if you don't answer my question. It's no use ignoring the questions and keep posting about wanting people to share code.


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
Code: [Select]

//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
Code: [Select]

//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



Go Up