Go Down

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

Graynomad

Serial.println((data[1] << 8 ) + data[2], HEX);

______
Rob
Rob Gray aka the GRAYnomad www.robgray.com

ranjeetray


Serial.println((data[1] << 8 ) + data[2], HEX);

______
Rob


Respected Sir


Thanks a Ton. it is working. You are mind blowing Sir.


Thanks & Regards...... :)

Graynomad

Rob Gray aka the GRAYnomad www.robgray.com

ranjeetray


Quote
The gap/delay between these two 8 bit data will be considered as 0.


No it won't because the receiving device only clocks in bits on the clock pulses. There is no "clocked" gap.



Respected Sir

Why this following code is not generating 16 clock cycle continuously. Here I am using two continuous SPI.transfre(); but it is not giving 16 clock cycle.

Code: [Select]


#include <SPI.h>


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

unsigned char data;
int array[6] = {0x0A04, 0x0107, 0x0E05, 0x0209, 0x0B08, 0x0507 }, 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();
            //SPI.setDataMode(SPI_MODE2);
            //SPI.setBitOrder(LSBFIRST);
          }

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;
   if(hg == 0x3B)
   {
     Serial.println("Writting Data on SPI bus");
     pinMode(SS_PIN, OUTPUT);
     digitalWrite(SS_PIN, LOW);
     SPI.transfer(0x3b);
     SPI.transfer(0x2b);   
     digitalWrite(SS_PIN, HIGH);
     Serial.println();
     Serial.println("Sending Done");
    delay(10); 
   }

}

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



Nick Gammon


Why this following code is not generating 16 clock cycle continuously. Here I am using two continuous SPI.transfre(); but it is not giving 16 clock cycle.


Prove it. Where is your logic analyzer output?

Go Up