Go Down

Topic: Soft SPI slave (Read 399 times) previous topic - next topic

ka_ru

Hallo zusammen,

Ich versuche Soft SPI Slave mit Interrupt zu realisieren.
SPI ist in Mode 3. CH1 - CLK, CH2- Daten.
Meine gewünschte 85 bekomme ich nicht.
Kann mir jemand helfen?

Andrew.


http://farm9.staticflickr.com/8195/8376523960_0f764a23be_b.jpg

Code: [Select]

void SPI_slave_in()
{
  if(digitalRead(MOSI_PIN) == 1) SPI_Byte_tmp = (SPI_Byte_tmp << 1) | 0x01; //Set "1"
  else SPI_Byte_tmp = (SPI_Byte_tmp << 1) & 0xFE; //Set "0"
  SPI_Counter --;
 
  if (SPI_Counter == 0) {
   Byte_rdy = HIGH;
   SPI_Byte = SPI_Byte_tmp;   
   SPI_Byte_tmp = 0;
   SPI_Counter = 8;
  }
}


uwefed

Rätselraten imJänner  ;) ;)
Quote
Meine gewünschte 85 bekomme ich nicht.

Was bekommst Du dann?
Bitte gesamten Sketch.
Grüße Uwe

ka_ru

#2
Jan 13, 2013, 01:42 pm Last Edit: Jan 13, 2013, 01:57 pm by ka_ru Reason: 1
ich bekomme "C0"
Wenn ich "FF" sende bekomme ich "FFFFFFFF"

Code: [Select]

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

volatile char SPI_Byte = 0;
volatile char SPI_Byte_tmp = 0;
volatile boolean Byte_rdy = LOW;
volatile char SPI_Counter = 8;

void setup() {
 
 pinMode(SCK_PIN, INPUT);
 pinMode(MOSI_PIN, INPUT);
 pinMode(MISO_PIN, OUTPUT);
 pinMode(SS_PIN, INPUT);
 
 Serial.begin(115200);
 Serial.println("SPI slave mode");
 attachInterrupt(0, SPI_slave_in, RISING); // RISING or FALLING

}

void loop() {
 
 if (Byte_rdy  == HIGH) {
   Byte_rdy = LOW;
   Serial.print(SPI_Byte, HEX);
   Serial.print("\n");
 }

}

void SPI_slave_in()
{
 if(digitalRead(MOSI_PIN) == 1) SPI_Byte_tmp = (SPI_Byte_tmp << 1) | 0x01; //Set "1"
 else SPI_Byte_tmp = (SPI_Byte_tmp << 1) & 0xFE; //Set "0"
 SPI_Counter --;
 
 if (SPI_Counter == 0) {
  Byte_rdy = HIGH;
  SPI_Byte = SPI_Byte_tmp;  
  SPI_Byte_tmp = 0;
  SPI_Counter = 8;
 }
}

Go Up