Graynomad:
I know I'm going to regret this but here's my quick version of one way to do the slave#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;
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;
}
It compiles but I can't test it. _____ Rob
Hi..!!
This code gives following result, which is attached here, blue line is MISO yellow MOSi and Pink line is SCK.
#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)
{
}
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)