Spidev is not working properly

96boards

#1

i m using Db410c as a master and arduino mega as a slave here is my screenshot
actually master sends some random values with actual data

arduino mega as a slave

#include <SPI.h>
#include <stdlib.h>

char buf [100];
volatile byte pos;
volatile boolean process_it;

void setup (void)
{
//Start the Serial for the debugging
Serial.begin (115200);

// have to send on master in, slave out
pinMode(MISO, OUTPUT);
pinMode(53,INPUT);

//Setting up the LED pin as OUTPUT
pinMode(7,OUTPUT);
pinMode(6,OUTPUT);

// turn on SPI in slave mode
SPCR |= _BV(SPE);

// get ready for an interrupt
pos = 0; // buffer empty
process_it = false;

// now turn on interrupts
SPI.attachInterrupt();

} // end of setup

// SPI interrupt routine
ISR (SPI_STC_vect)
{
byte c = SPDR; // grab byte from SPI Data Register
SPDR=0;
if(digitalRead(53)==0){
// add to buffer if room
if (pos < sizeof buf)
{
buf [pos++] = c;

// example: newline means time to process buffer
if (c == '\n')
  process_it = true;
  
}  // end of room available

}
} // end of interrupt routine SPI_STC_vect

// main loop - wait for flag set in interrupt routine
void loop (void)
{
if (process_it)
{
buf [pos] = 0;
int buff = atoi(buf);
Serial.println (buff);
switch(buff){
case 10:
digitalWrite(6,HIGH);
digitalWrite(7,LOW);
break;
case 11:
digitalWrite(6,LOW);
digitalWrite(7,HIGH);
break;
}
pos = 0;
process_it = false;
} // end of flag set

}


#2

@alokm014,

Have you tested SPIDEV on Dragonboard410c in loopback mode first?

Thanks,
Mani


#3

i already enable spi that is why my code is working but the problem is it transfer some random values check it in screenshots for more details i don’t hav any idea about it


#4

@alokm014 My question was whether you have tested SPIDEV in Loopback mode? Were you able to receive all bytes successfully without any random values?


#5

ok…when i run this sudo ./spidev_test -CHO -D /dev/spidev0.0 0xaa,0xbb,0xcc,0,0,0,0,0 --loop
the output is something like this…
OUTPUT:
spi mode: 0x27
bits per word:8
max speed: 500000 hx

this is the output instead of :
AA BB CC 00 00 00 00 00
AA BB CC 00 00 00 00 00


#6

problem solved…Here is my tutorial link on spidev https://github.com/alokm014/DB-410C-spidev
and thanks for your support … :slight_smile: