Hello everyone,
I want to make device reacting to some SPI communication cases between some CPU and periphery. Just like reading some EEPROM memory address or writing to some address. No need to send any data back.
My board is NUCLEO-F429ZI. I’m trying to use SPISlave, and I’m just reading communication to decode command, address and data. Main part of my testing code is:
SPISlave SPIdevice(PA_7, NC, PA_5, PA_4); //MOSI, MISO, SCLK, CS
char array[100][10];
...
SPIdevice.frequency( 4000000) ;
//lcd.cls();
int max=9;
int i=0;
while (!btn && i<100) {
if(SPIdevice.receive()) {
for (int ii=0;ii<max;ii++){
array[i][ii]=SPIdevice.read();
}
i++;
}
}
So this code work a bit, array data for testing is written to SD card later, not when reading SPI.
For now first 6 columns of my array is filled with data like this:
3 1 96 0 0 3
0 3 1 9A 0 3
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 3 e 40
But real data from analyzer is:
Packet ID,MOSI
0,0x03,
0,0x01,
0,0x96,
0,0x00,
0,0x00,
1,0x03,
1,0x01,
1,0x98,
1,0x00,
1,0x00,
2,0x03,
2,0x01,
2,0x9A,
2,0x00,
3,0x03,
3,0x0E,
3,0x5E,
3,0x00,
…
4,0x03,
4,0x0E,
4,0x40,
My problem is every communication is unknown in data length. So how to know when to stop do read()? Or if to be more precise - how to correctly read only first 6-8 bytes of every communication? Even if some communications is shorter. Maybe there is some other methods to read and decode command, address and some first data?