Pages: 1 ... 6 7 [8]   Go Down
Author Topic: SPI interface with other board_AVR_ESK1100 or among Arduino itself  (Read 9841 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

Quote
Master code on Arduino
...
Master code on Arduino Again
...
Other Slave codes are:

What?

Hi..!!

I mean to say that I have tried both the way on Arduino in Master , with delay and without delay also, but still does not respond properly.
I tried all the combination of master and slave but slave is not able to send back data for multiple if conditions or multiple SPDR = data.


And AVR EVK1100 master is reading FFFFFFFFFFFFF from slave Arduino board.
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 484
Posts: 18768
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You are going to have to post code for a master, and a slave, and describe what is going wrong. Not lots of codes for each. And not "does not respond properly".

We are up to page 8 and your posts are as vague as a violet.
Logged


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

You are going to have to post code for a master, and a slave, and describe what is going wrong. Not lots of codes for each. And not "does not respond properly".

We are up to page 8 and your posts are as vague as a violet.
Ok. I apologize for this.


//Master sending data
Code:
#include <SPI.h>// include the SPI library:
#define SS_PIN   10

int command_array[] = {0x04, 0x06, 0x08, 0x0A};
int returned_data[4];

void setup() {
 
  pinMode (SS_PIN, OUTPUT);// set the spi_data_pin as an output:

  Serial.begin(115200);
 
  SPI.begin();
  SPI.setDataMode(SPI_MODE2);
  SPI.setClockDivider(SPI_CLOCK_DIV64) ;
  SPI.setBitOrder(LSBFIRST);
 
}

void loop() {
   
    digitalWrite(SS_PIN,LOW);
    SPI.transfer(command_array[0]);       // send command
    //delay(1);                             // give the slave some time
    returned_data[0] = SPI.transfer(0);   // get response
    digitalWrite(SS_PIN,HIGH);

    digitalWrite(SS_PIN,LOW);
    //delay(1);
    SPI.transfer(command_array[1]);
    returned_data[1] = SPI.transfer(0);
    digitalWrite(SS_PIN,HIGH);

    digitalWrite(SS_PIN,LOW);
    //delay(1);
    SPI.transfer(command_array[2]);
    returned_data[2] = SPI.transfer(0);
    digitalWrite(SS_PIN,HIGH);

    digitalWrite(SS_PIN,LOW);
    //delay(1);
    SPI.transfer(command_array[3]);
    returned_data[3] = SPI.transfer(0);
    digitalWrite(SS_PIN,HIGH);

    Serial.print (returned_data[0]);
    Serial.print (',');
    Serial.print (returned_data[1]);
    Serial.print (',');
    Serial.print (returned_data[2]);
    Serial.print (',');
    Serial.println (returned_data[3]);
 
}

Slave code for sending back data:
Code:
//Slave Code
#include "pins_arduino.h"
#include <SPI.h>
#define SS 10

byte c;
int m, n ;
void setup (void)
{
  // 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);
 
 // disable timer interrupts
  TIMSK0 = 0;
 
}  // end of setup
 
 
// SPI interrupt routine
ISR (SPI_STC_vect)
{
  c = SPDR;
  if(c == 0x04)
 {
  SPDR = 0x01;
}
  else if(c == 0x06)
 {
 
  SPDR = 0x02;
 }
  else if(c == 0x08)
 {
 
  SPDR = 0x03;
 }
   else if(c == 0x0A)
 {
 
  SPDR = 0x07;
 }
 
else
 SPDR = 0;    // what to return to the master
 
}  // end of interrupt service routine (ISR) SPI_STC_vect
 
void loop (void)
{
 
}  // end of loop

This combination of Master and Slave code I have tried but Slave is not able to send back data to Master, I have observed in Oscilloscope MISO is not having data. What could be the reason.
« Last Edit: November 19, 2012, 05:00:46 am by ranjeetray » Logged

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