hey, I'm trying to write(for a micro-controller) a function that takes in one argument along with an unknown number of arguments. For now I'm testing on an arduino, so there will be some arduino functions. My problem is this: I can't get the individual arguments. The value for all arguments(except the first) is between 0x00 and 0xFF and I want to pass each of them through an spi.transfer function. for instance the arguments are (0, 0x24, 0x63) (the first argument in my case tells me the number of bytes I am expecting to receive, so we can ignore it), so I want 0x24 to be passed via spi.transfer and after pass 0x63.
Code:uint32_t SCOM (int Size, int x, ...){
va_list valist;
va_start(valist, x);
for (int i = 0; i < x; i++){
Serial.println((valist, i), BIN);
SPI.transfer( (valist, i) );
}
if (Size != 0){
for ( int i = 0; i < Size; i++ ){
uint32_t data;
if (i == 0){
data = SPI.transfer(0xff);
if (Size == 1){ return data; }
}
else{
data |= (uint32_t)SPI.transfer(0xff) << (8 * i);
}
return data;
}
}
if (Size == 0){return NULL;}
else {Serial.println("ERROR SCOM format: unsigned int to be received, register");}
}