We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
hi i am a student tryin to read the data between two spi devices by tapping the lines in the middle please help me if anyone hav a code to read the ss,mosi,miso,sclk signals using GPIO they vl jst act lyk input port n read
Still using child language.
You obviously have to sample fast enough to see every change of the SPI clock signal, so you know when it is time to sample the MISO and MISO signals. And since the SS signal represents a start-of-frame indicator, you must sample that one fast enough so that you will reset your bit counter in time for incoming data.
The code is trivial - with your shorthand, you should be able to write it in 10 minutes. If it will be fast enough - and if your processor will have enough memory for storing the received data - is another question.
You have two choices. Interrupt-driven or polling. The choice is up to you. But before you decide, you have to look at the clock signal and figure out how fast the SPI interface is running.
thank you for the reply i am basically designing a protocol analyzer which must read spi data ...i will be placing my analyzer in between spi master and slave and read the data...my analyzer has 8051 microcontroller in it...m using 4 bits on port 3 to act as input port.....i have to implement it within two days so i am in a hurry n searchin if anyone can help me with the code while(1); { for(i=0;i<18;i++) { P1=seq[i]; if(ss==0) { if(clock==1) { bit_count++; if(miso==1) { reg1 =reg1+1; if(count1!=1) { reg1 = reg1<<1; count1--; } } else { if(count1!=1) { reg1 = reg1<<1; count1--; } } if(mosi==1) { reg2 =reg2+1; if(count2!=1) { reg2 = reg2<<1; count2--; } } else { if(count2!=1) { reg2 = reg2<<1; count2--; } } }
}
if(bit_count==8) break; }
this is my code at present
this is rather spaghetti at present! use the proper tags please!
I think this is the 'translation' (note the 'extra' white-space to make it more 'readable'....
{ And you might want to use 'comments' to explain what you *think* you are doing }
while( 1 ); seems like an error with this 'added' semicolon { for( i=0; i<18; i++ ) // never use hard-coded numbers: use #defines or const instead { P1 = seq[ i ]; if( ss==0 ) { if( clock==1 ) { bit_count++; if( miso==1 ) { reg1 = reg1 + 1; if( count1 != 1 ) { reg1 = reg1 << 1; count1--; } } else { if( count1 != 1 ) { reg1 = reg1 << 1; count1--; } } if( mosi == 1 ) { reg2 = reg2 + 1; if( count2 != 1 ) { reg2 = reg2 << 1; count2--; } } else { if( count2 != 1 ) { reg2 = reg2 << 1; count2--; } } } } if( bit_count == 8 ) { break; } } // for } // While
--Cpt. Vince Foster 2nd Cannon Place Fort Marcy Park, VA
... or enum
Up here in space I'm looking down on you My lasers trace Everything you do You think you've private lives Think nothing of the kind There is no true escape I'm watching all the time I'm made of metal My circuits gleam I am perpetual I keep the country clean I'm elected electric spy I'm protected electric eye Always in focus You can't feel my stare I zoom into you You don't know I'm there I take a pride in probing all your secret moves My tearless retina takes pictures that can prove I'm made of metal My circuits gleam I am perpetual I keep the country clean I'm elected electric spy I'm protected electric eye Electric eye, in the sky Feel my stare, always there There's nothing you can do about it Develop and expose I feed upon your every thought And so my power grows I'm made of metal My circuits gleam I am perpetual I keep the country clean I'm elected electric spy I'm protected electric eye I'm elected electric spy I'm elected protective, detective, Electric Eye!
Clearly I'm bored to death.
you are clearly not in favor of big brother, unless, of course, it makes the bad guys turn into a spray of goo :-)
You totally forget that SPI is a synchronous transfer. Your code does not tick forward in sync with the clock signal. And should you step time (increment i) even when no slave select?
And you have a bit of duplicated code in there.
By the way - what is the meaning of the magic number 18? Does it in any way relate to the data you are sniffing?