Pages: [1]   Go Down
Author Topic: Soft SPI slave  (Read 364 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 1
Posts: 14
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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;
  }
}
Logged

Forum Moderator
BZ (I)
Offline Offline
Brattain Member
*****
Karma: 271
Posts: 21881
+39 349 2158303
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Rätselraten imJänner  smiley-wink smiley-wink
Quote
Meine gewünschte 85 bekomme ich nicht.
Was bekommst Du dann?
Bitte gesamten Sketch.
Grüße Uwe
Logged

Offline Offline
Newbie
*
Karma: 1
Posts: 14
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ich bekomme "C0"
Wenn ich "FF" sende bekomme ich "FFFFFFFF"

Code:
#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;
  }
}
« Last Edit: January 13, 2013, 07:57:15 am by ka_ru » Logged

Pages: [1]   Go Up
Jump to: