Pages: 1 ... 3 4 [5] 6 7 8   Go Down
Author Topic: SPI interface with other board_AVR_ESK1100 or among Arduino itself  (Read 10559 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
***
Karma: 0
Posts: 108
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I suspect that your 0x3E is still in the SPDR register although it should be overwritten by SPI.transfer(array[ii]) I would think.

Quote
So I want to remove this 0x3E while sending back data from Slave.Is it possible by clearing any buffer.
If 0x12 is written into the SPDR register that's the value that will go out, I don't know why SPI.transfer() would not do that.

Have I got this right...

Arduino sends 0x3E to IMU.
Line turns around.
IMU sends data to Arduino.

Does this IMU really expect the SPI line to be turned around? Have you got a data sheet?

Quote
so before testing the actual IMU, I want to create a dummy IMU which will be Arduino board or EVK1100(which will act as Master and will send command for data) and other slave board will be Arduino board which will receive command from IMU master board(Arduino or EVK1100)
BTW, All this talk of IMU/Arduino/EVK1100 is really confusing the issue IMO, can we just say Arduino and IMU and assume that they are both SPI-capable devices.

______
Rob



Respected Sir

Thanks a lot for your kind reply.
Yes , I want to communicate between IMU and Arduino board. IMU will act as a Master and Arduino will be a slave.
Once slave(Arduino) receives 0x3E(as a command) from IMU it will send back 12bytes of required data to IMU.

Thanks & Regards...:-)

* ADIS16400_16405.pdf (496.69 KB - downloaded 16 times.)
Logged

Global Moderator
Melbourne, Australia
Online Online
Brattain Member
*****
Karma: 511
Posts: 19314
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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?

Logged

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

Please post technical questions on the forum - not to me by personal message. Thanks a lot.

Offline Offline
Full Member
***
Karma: 0
Posts: 108
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

For the benefit of people who don't have MS Word, your connection diagram is:



Can you explain why you want to send data from one to the other, and then back again? Why not leave it where it started in the first place?

And assuming you have a good reason, on my page here:

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

I describe how to send data between two Arduinos using SPI. Scroll down to "How to get a response from a slave".

I don't understand this sort of talk, to be honest:

Quote
Because received one byte data is going back on to SPI bus again when I send back data from slave.
Respected Sir

How did you copy image here. I am trying to paste image here but it is not happening.

Thanks & Regards....  :-)
Logged

Global Moderator
Melbourne, Australia
Online Online
Brattain Member
*****
Karma: 511
Posts: 19314
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I put the image on my own web site and included a link to it.
Logged

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

Please post technical questions on the forum - not to me by personal message. Thanks a lot.

Offline Offline
Full Member
***
Karma: 0
Posts: 108
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I put the image on my own web site and included a link to it.
OK Sir



Thanks & Regards...   :-)
Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 108
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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).
Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 108
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


[/quote]


Hi...!!!

Can anybody share the working code on SPI.
Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 108
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset




Hi...!!!

Can anybody share the working code on SPI.
[/quote]

Any Luck....!!!
Logged

Global Moderator
Melbourne, Australia
Online Online
Brattain Member
*****
Karma: 511
Posts: 19314
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

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

Please post technical questions on the forum - not to me by personal message. Thanks a lot.

Offline Offline
Full Member
***
Karma: 0
Posts: 108
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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


Logged

Global Moderator
Melbourne, Australia
Online Online
Brattain Member
*****
Karma: 511
Posts: 19314
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

If you aren't sending any data back, what do you expect? It will happen to return what is in SPDR at the time. You have to change it in the ISR. Also you can't do Serial.print in an ISR, it takes too long.

Modified sketch, returns 0x42:


Code:
//Slave receiving data
#include <SPI.h>

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;  // what we received from the master
  SPDR = 0x42;    // what to return to the master
}  // end of ISR SPI_STC_vect


void loop (void)
{
 
}  // end of loop

Logic analyzer confirms we got the 0x42 returned each time:


« Last Edit: November 15, 2012, 11:33:52 pm by Nick Gammon » Logged

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

Please post technical questions on the forum - not to me by personal message. Thanks a lot.

Offline Offline
Full Member
***
Karma: 0
Posts: 108
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you aren't sending any data back, what do you expect? It will happen to return what is in SPDR at the time. You have to change it in the ISR. Also you can't do Serial.print in an ISR, it takes too long.

Modified sketch, returns 0x42:


Code:
//Slave receiving data
#include <SPI.h>

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;  // what we received from the master
  SPDR = 0x42;    // what to return to the master
}  // end of ISR SPI_STC_vect


void loop (void)
{
 
}  // end of loop

Logic analyzer confirms we got the 0x42 returned each time:




Thanks a lot Sir.
Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 108
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you aren't sending any data back, what do you expect? It will happen to return what is in SPDR at the time. You have to change it in the ISR. Also you can't do Serial.print in an ISR, it takes too long.

Modified sketch, returns 0x42:


Code:
//Slave receiving data
#include <SPI.h>

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;  // what we received from the master
  SPDR = 0x42;    // what to return to the master
}  // end of ISR SPI_STC_vect


void loop (void)
{
 
}  // end of loop

Logic analyzer confirms we got the 0x42 returned each time:




Thank you Sir.

Can we do like this, after receiving data can we check(if condition) data and then send back data to master like this.
Code:

#include <SPI.h>

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;  // what we received from the master
  //delay(15);
 if(c == 0x04)
 {
   digitalWrite(SS, LOW);
    SPDR = 0x45;
  SPI.transfer(0xFF);
digitalWrite(SS, HIGH);
 }
  else
 SPDR = 0x00;    // what to return to the master
}  // end of ISR SPI_STC_vect


void loop (void)
{
 
}  // end of loop
It is not working, I tried.
Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 108
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you aren't sending any data back, what do you expect? It will happen to return what is in SPDR at the time. You have to change it in the ISR. Also you can't do Serial.print in an ISR, it takes too long.

Modified sketch, returns 0x42:


Code:
//Slave receiving data
#include <SPI.h>

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;  // what we received from the master
  SPDR = 0x42;    // what to return to the master
}  // end of ISR SPI_STC_vect


void loop (void)
{
 
}  // end of loop

Logic analyzer confirms we got the 0x42 returned each time:




Hi...!!

This code works fine with making SPDR = 0x00; at ISR but I have observed on Oscilloscope that sometime few data goes back to MISO, Slave is not able to clear SPDR perfectly, what could be the reason.

Code:
//Slave receiving data
#include <SPI.h>

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;  // what we received from the master
  SPDR = 0x00;    // what to return to the master
}  // end of ISR SPI_STC_vect


void loop (void)
{
 
}  // end of loop
Just keeping bandwidth of site in mind I am attaching one oscilloscope photo for your reference.


* TEK0000.BMP (76.05 KB, 320x240 - viewed 40 times.)
Logged

Global Moderator
Melbourne, Australia
Online Online
Brattain Member
*****
Karma: 511
Posts: 19314
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Can we do like this, after receiving data can we check(if condition) data and then send back data to master like this.

I really don't know what you are trying to do. You are doing an SPI.transfer in the middle of the ISR?

You send back data to the master by assigning to SPDR in the interrupt service routine. No other way. What are you thinking?
Logged

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

Please post technical questions on the forum - not to me by personal message. Thanks a lot.

Pages: 1 ... 3 4 [5] 6 7 8   Go Up
Jump to: