mirror of
https://github.com/hak5darren/wifipineapple-wiki.git
synced 2025-10-29 16:59:29 +00:00
Merge pull request #10 from phpsystems/gh-pages
Fix of the getting started page for the HDK - Source code
This commit is contained in:
commit
6ec7d5943c
@ -49,71 +49,7 @@ The program will need to be uploaded to the HDK. Once complete, run the command:
|
|||||||
|
|
||||||
On the serial console of the HDK, the words "Testing 1 2 3" should appear.
|
On the serial console of the HDK, the words "Testing 1 2 3" should appear.
|
||||||
|
|
||||||
```C
|
[Code for the HDK](spi.ino)
|
||||||
// Written by Nick Gammon
|
|
||||||
// February 2011
|
|
||||||
/**
|
|
||||||
* Send arbitrary number of bits at whatever clock rate (tested at 500 KHZ and 500 HZ).
|
|
||||||
* This script will capture the SPI bytes, when a '\n' is recieved it will then output
|
|
||||||
* the captured byte stream via the serial.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <SPI.h>
|
|
||||||
|
|
||||||
char buf [100];
|
|
||||||
volatile byte pos;
|
|
||||||
volatile boolean process_it;
|
|
||||||
|
|
||||||
void setup (void)
|
|
||||||
{
|
|
||||||
Serial.begin (115200); // debugging
|
|
||||||
|
|
||||||
// have to send on master in, *slave out*
|
|
||||||
pinMode(MISO, 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
|
|
||||||
|
|
||||||
// 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;
|
|
||||||
Serial.println (buf);
|
|
||||||
pos = 0;
|
|
||||||
process_it = false;
|
|
||||||
} // end of flag set
|
|
||||||
|
|
||||||
} // end of loop
|
|
||||||
```
|
|
||||||
|
|
||||||
## Additional Information + Useful Links
|
## Additional Information + Useful Links
|
||||||
|
|
||||||
|
|||||||
63
spi.ino
Normal file
63
spi.ino
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
// Written by Nick Gammon
|
||||||
|
// February 2011
|
||||||
|
/**
|
||||||
|
* Send arbitrary number of bits at whatever clock rate (tested at 500 KHZ and 500 HZ).
|
||||||
|
* This script will capture the SPI bytes, when a '\n' is recieved it will then output
|
||||||
|
* the captured byte stream via the serial.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <SPI.h>
|
||||||
|
|
||||||
|
char buf [100];
|
||||||
|
volatile byte pos;
|
||||||
|
volatile boolean process_it;
|
||||||
|
|
||||||
|
void setup (void)
|
||||||
|
{
|
||||||
|
Serial.begin (115200); // debugging
|
||||||
|
|
||||||
|
// have to send on master in, *slave out*
|
||||||
|
pinMode(MISO, 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
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
Serial.println (buf);
|
||||||
|
pos = 0;
|
||||||
|
process_it = false;
|
||||||
|
} // end of flag set
|
||||||
|
|
||||||
|
} // end of loop
|
||||||
Loading…
x
Reference in New Issue
Block a user