Graynomad:
That wasn't a stand-alone program, what happened to all your setup() code (most or which you don't need anyway I think).
Rob
Hi..!!
This code give following results, which have been attached here.
#include "pins_arduino.h"
#include <SPI.h>
#define MAX_BYTES 4 // is there 4 bytes? if not change this and the arrays.
byte cmd_04_data[MAX_BYTES] = {1,2,3,4}; // you fill in the numbers
byte cmd_06_data[MAX_BYTES] = {5,6,7,8};
byte * data_ptr;
int byte_count = 0;
void setup (void)
{
// have to send on master in, *slave out*
pinMode(MISO, OUTPUT);
SPI.setBitOrder(MSBFIRST);
SPI.setDataMode (SPI_MODE2);
SPI.setClockDivider(SPI_CLOCK_DIV64) ;
// turn on SPI in slave mode
SPCR |= _BV(SPE);
// turn on interrupts
SPCR |= _BV(SPIE);
// disable timer interrupts
TIMSK0 = 0;
// interrupt for SS falling edge
//attachInterrupt (0, ss_falling, FALLING);
// disable timer interrupts
TIMSK0 = 0;
}
ISR (SPI_STC_vect) {
byte c = SPDR;
if (byte_count == 0) {
// set a pointer to one or other array based on the byte just received
data_ptr = (c == 0x04) ? cmd_04_data : cmd_06_data;
}
SPDR = *(data_ptr + byte_count);
byte_count++;
if (byte_count = MAX_BYTES) byte_count = 0;
}
void loop (void)
{
} // end of loop
TEK0000.BMP (76.1 KB)
TEK0001.BMP (76.1 KB)