SPI Slave [SOLVED]

Hi, i need to use my arduino as slave spi, master is a st discovery board.
I use this sketch to configure spi:

#include <SPI.h>


#define SCK_PIN   13
#define MISO_PIN  12
#define MOSI_PIN  11
#define SS_PIN    10

void SlaveInit(void) {
  // Set MISO output, all others input
  pinMode(SCK_PIN, INPUT);
  pinMode(MOSI_PIN, INPUT);
  pinMode(MISO_PIN, OUTPUT);
  pinMode(SS_PIN, INPUT);

  // Enable SPI
  SPCR = B00000000;
  SPCR = (1<<SPE);
}

uint8_t ReadByte(void) {
  while(!(SPSR & (1<<SPIF))) ;
  return SPDR;
}

void WriteByte(uint8_t value) {
  SPDR = value;
  while (!(SPSR & (1<<SPIF))) ;
  return;
}




void setup()
{
  Serial.begin(9600);
  SlaveInit();
}

void loop()
{
uint8_t RX_Data;
  RX_Data = ReadByte();
  WriteByte(0x01);
  Serial.println(RX_Data);
//  Serial.println(RX_Data, HEX);
  Serial.println("rx");
}

This is the configuration of master

 SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
  SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
  SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
  SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;
  SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;
  SPI_InitStructure.SPI_NSS = SPI_NSS_Hard;
  SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4;
  SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_LSB;
  SPI_InitStructure.SPI_CRCPolynomial = 7;
  SPI_Init(SPIy, &SPI_InitStructure);

I send this

uint8_t SPIy_Buffer_Tx[BufferSize] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
                                      0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E,
                                      0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15,
                                      0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C,
                                      0x1D, 0x1E, 0x1F, 0x20};

but i recive this

FFFFFFC0
rx
40
rx
FFFFFF88
rx
18
rx
FFFFFFF0
rx
FFFFFFF0
rx
30
rx
10
rx
20
rx
4
rx
FFFFFF88
rx
50
rx
60
rx
40
rx
78
rx
58
rx
68
rx
48
rx
70
rx
50
rx
60
rx
40
rx
FFFFFFF8
rx
4
rx

someone can help me to understand where i do something wrong?
thx.

If I interpret this configuration of the master correctly you chose the wrong mode on the slave side:

  SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;
  SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;

Does this mean SCK is active LOW and the second edge is the time the data is viable? If so I think the mode on the slave side should be 3 and not 0 according to this picture File:SPI timing diagram2.svg - Wikipedia

If the modes are not equal a correct transmission is not possible.

How fast is the master sending data?

I suspect while you are faffing around with Serial.print()s you receive about 20 bytes in the SPI.

I would accumulate ALL the data then print it.

Also because the two events (SPI and serial) are asynchronous you probably read SPDR half way through receiving a byte.

I think there are issues with the way you are returning data as well, but let's get one direction working first.


Rob

pylon:
If I interpret this configuration of the master correctly you chose the wrong mode on the slave side:

  SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;

SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;




Does this mean SCK is active LOW and the second edge is the time the data is viable? If so I think the mode on the slave side should be 3 and not 0 according to this picture http://en.wikipedia.org/wiki/File:SPI_timing_diagram2.svg

If the modes are not equal a correct transmission is not possible.

Thx, i try to change it in this way

SPIE - Enables the SPI interrupt when 1
SPE - Enables the SPI when 1
DORD - Sends data least Significant Bit First when 1, most Significant Bit first when 0
MSTR - Sets the Arduino in master mode when 1, slave mode when 0
CPOL - Sets the data clock to be idle when high if set to 1, idle when low if set to 0
CPHA - Samples data on the falling edge of the data clock when 1, rising edge when 0
SPR1 and SPR0 - Sets the SPI speed, 00 is fastest (4MHz) 11 is slowest (250KHz)

with the master configuration i think i need:
DORD = 1
CPOL = 1
CPHA = 1
Is it now correct?

Graynomad:
How fast is the master sending data?

I suspect while you are faffing around with Serial.print()s you receive about 20 bytes in the SPI.

I would accumulate ALL the data then print it.

Also because the two events (SPI and serial) are asynchronous you probably read SPDR half way through receiving a byte.

I think there are issues with the way you are returning data as well, but let's get one direction working first.


Rob

I don't know the spi clock of stm32vldiscovery, i know internal max clock is 24mhz.
With 2 stm32 code of master work perfectly then problem isn't in master code,
I try to use a new variable to store spi data received and then i print it as u say.
Thx for help.

with the master configuration i think i need:
DORD = 1
CPOL = 1
CPHA = 1
Is it now correct?

I don't know if it's correct as I have no clue about your master's configuration but if my interpretation of the parameters is correct, then I would use these values.

nothing :frowning:
I changed configuration, but receive and send data are different.
I also try to change master-slave, with arduino configuration master and stm32 slave, for being sure that isn't a clock rate problem, but in this situation no data arrive to slave.
Someone can give me a little help?

Post your current code.


Rob

This is new code

#include <SPI.h>


#define SCK_PIN   13
#define MISO_PIN  12
#define MOSI_PIN  11
#define SS_PIN    10

void SlaveInit(void) {
  // Set MISO output, all others input
  pinMode(SCK_PIN, INPUT);
  pinMode(MOSI_PIN, INPUT);
  pinMode(MISO_PIN, OUTPUT);
  pinMode(SS_PIN, INPUT);

  // Enable SPI
  SPCR = B00101100;
  SPCR = (1<<SPE);
}

uint8_t ReadByte(void) {
  while(!(SPSR & (1<<SPIF))) ;
  return SPDR;
}

void WriteByte(uint8_t value) {
  SPDR = value;
  while (!(SPSR & (1<<SPIF))) ;
  return;
}




void setup()
{
  Serial.begin(9600);
  SlaveInit();
}

void loop()
{
uint8_t RX_Data[32];
for (int i = 1;i<=32;i++){
  RX_Data[i] = ReadByte();
  WriteByte(0x01);
}
  
  
for (int i = 1;i<=32;i++){
  Serial.println(RX_Data[i]);
//  Serial.println(RX_Data, HEX);
  Serial.println("rx");
}
}

You are putting data into RX_Data starting at index 1 (normally you start at 0) then you count to 32, so you overrun the end of the array.

But I suspect that this code

  RX_Data[i] = ReadByte();
  WriteByte(0x01);

Takes way to long, you haven't said how fast the SPI link is running but remember that when a byte is received you have one bit time to read it before it starts getting overwritten with the next byte.

With any decent SPI link that's just a few uS, not enough time for function calls and indexing into arrays.

I would propose something like this

uint8_t RX_Data[32];

uint8_t ReadPacket(void) {
	ptr = RX_Data;
	for (int i = 0; i < 32; i++){
		SPDR = 0x01;			// preload the data reg
		while(!(SPSR & (1<<SPIF))) ; // wait for new byte
		*ptr++ = SPDR;			// save byte
	}
}

void loop() {
   ReadPacket ();
   ...
   }

Rob

thx for help this is my new code (following what u have said)

#include <SPI.h>


#define SCK_PIN   13
#define MISO_PIN  12
#define MOSI_PIN  11
#define SS_PIN    10

void SlaveInit(void) {
  // Set MISO output, all others input
  pinMode(SCK_PIN, INPUT);
  pinMode(MOSI_PIN, INPUT);
  pinMode(MISO_PIN, OUTPUT);
  pinMode(SS_PIN, INPUT);

  // Enable SPI
  SPCR = B00101100;
  SPCR = (1<<SPE);
}
uint8_t RX_Data[32];

uint8_t ReadByte(void) {
uint8_t *ptr = RX_Data;
	 for (int i = 0; i < 32; i++){
		 SPDR = 0x01;			 // preload the data reg
  while(!(SPSR & (1<<SPIF))) ;
		*ptr++ = SPDR;			 // save byte
	 }
}

void WriteByte(uint8_t value) {
  SPDR = value;
  while (!(SPSR & (1<<SPIF))) ;
  return;
}




void setup()
{
  Serial.begin(9600);
  SlaveInit();
}

void loop()
{


ReadByte();
  
  
for (int i = 1;i<=32;i++){
  Serial.println(RX_Data[i]);
//  Serial.println(RX_Data, HEX);
  Serial.println("rx");
}
}

and this is the result from board

1
rx
1
rx
1
rx
1
rx
1
rx
1
rx
1
rx
1
rx
1
rx
1
rx
1
rx
1
rx
1
rx
1
rx
1
rx
1
rx
1
rx
1
rx
1
rx
1
rx
1
rx
1
rx
1
rx
1
rx
1
rx
1
rx
1
rx
1
rx
1
rx
1
rx
1
rx
0
rx

i send

uint8_t SPIy_Buffer_Tx[BufferSize] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
                                      0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E,
                                      0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15,
                                      0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C,
                                      0x1D, 0x1E, 0x1F, 0x20};

a little more help?
P.S.
I configured stm32 to 2MHZ spi speed

I would remove this

SPDR = 0x01; // preload the data reg

It's not really helping as you don't have to reply to the master it seems.

Also modify the for() loop to count from 0 to 31, that's not the problem but as I said before you are counting off the end of the array. Check the loop in ReadByte().

But I really can't see what's wrong and without a logic analyser it's very difficult to see because you can't do serial.print debugging in such a real time function.

But then I look at this

for (int i = 1;i<=32;i++){
  Serial.println(RX_Data[i]);
//  Serial.println(RX_Data, HEX);
  Serial.println("rx");
}

All the bytes in the array are non-printable ASCII characters so they won't show. Why you get all 1s I'm not sure but anyway we need to see exactly what is in that array. Try this

for (int i = 0;i<32;i++){  // note loop values
  Serial.print(RX_Data[i], HEX);
  Serial.println(',');
}

Rob

Situation:

#include <SPI.h>

#define SCK_PIN   13
#define MISO_PIN  12
#define MOSI_PIN  11
#define SS_PIN    10

void SlaveInit(void) {
  // Set MISO output, all others input
  pinMode(SCK_PIN, INPUT);
  pinMode(MOSI_PIN, INPUT);
  pinMode(MISO_PIN, OUTPUT);
  pinMode(SS_PIN, INPUT);

  // Enable SPI
  SPCR = B00101100;
  SPCR = (1<<SPE);
}
uint8_t RX_Data[32];

uint8_t ReadByte(void) {
uint8_t *ptr = RX_Data;
	 for (int i = 0; i < 32; i++){
		// SPDR = 0x01;			 // preload the data reg
  while(!(SPSR & (1<<SPIF))) ;
		*ptr++ = SPDR;			 // save byte
	 }
}

void setup()
{
  Serial.begin(9600);
  SlaveInit();
}

void loop()
{

ReadByte();
 
for (int i = 0;i<32;i++){  // note loop values
  Serial.print(RX_Data[i], HEX);
  Serial.println(',');
}
}

Result:

0,
40,
40,
20,
20,
60,
60,
10,
10,
50,
50,
30,
30,
70,
70,
8,
8,
48,
48,
28,
28,
68,
68,
18,
18,
58,
58,
38,
38,
78,
78,
4,

Update:

60,
10,
10,
50,
50,
30,
30,
70,
70,
8,
8,
48,
48,
28,
28,
68,
68,
18,
18,
58,
58,
38,
38,
78,
78,
4,
0,
40,
40,
20,
20,
60,
4,
0,
40,
40,
20,
20,
60,
60,
10,
10,
50,
50,
30,
30,
70,
70,
8,
8,
48,
48,
28,
28,
68,
68,
18,
18,
58,
58,
38,
38,
78,
78,

If i run sketch in another istance i have this.... why if i have a for loop 32 times i receive more than 32 value :astonished: i'm going crazy

i post my hardware configuration for master.... i hope this is useful

void GPIO_Configuration()
{
 // SPIy_Mode == SPI_Mode_Master
  GPIO_InitTypeDef GPIO_InitStructure;
 
 
  /* Configure NSS pin as Output Push Pull */
  GPIO_InitStructure.GPIO_Pin = SPIy_PIN_NSS;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
    GPIO_Init(SPIy_GPIO, &GPIO_InitStructure);
      
  /* Configure SPIy pins: SCK, MISO and MOSI ---------------------------------*/
  /* Configure SCK and MOSI pins as Alternate Function Push Pull */
  GPIO_InitStructure.GPIO_Pin = SPIy_PIN_SCK | SPIy_PIN_MOSI;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
   GPIO_Init(SPIy_GPIO, &GPIO_InitStructure);
  
  /* Configure MISO pin as Input Floating  */
  GPIO_InitStructure.GPIO_Pin = SPIy_PIN_MISO;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  GPIO_Init(SPIy_GPIO, &GPIO_InitStructure);
    
}

And

SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
  // SPI_InitStructure.SPI_Direction = SPI_Direction_1Line_Tx;
  SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
  SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
  SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;
  SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;
  SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
  SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4;
  SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_LSB;
  SPI_InitStructure.SPI_CRCPolynomial = 7;
  SPI_Init(SPIy, &SPI_InitStructure);

why if i have a for loop 32 times i receive more than 32 value

By my count you have 64 values which is 2x32, that's probably not a coincidence. There's obviously a pattern there but I can't see how it relates to the transmitted data.

How often is the master sending? Can you change it to only transmit once?
How are you getting in sync with the master? If the slave starts reading at any old time you will get crap data.
Can you fill the RX_Data array with a known value (say 0xAA) in setup() so we know those values are actually coming from the SPI.

Can you change the print to this

for (int i = 0;i<32;i++){  // note loop values
	  Serial.print(RX_Data[i], HEX);
	  Serial.print(',');
	}
    Serial.println('');

So we don't have to scroll so much and it will make it obvious how many times we get data.


Rob

Graynomad:

How often is the master sending? Can you change it to only transmit once?
How are you getting in sync with the master? If the slave starts reading at any old time you will get crap data.
Can you fill the RX_Data array with a known value (say 0xAA) in setup() so we know those values are actually coming from the SPI.

Can you change the print to this

for (int i = 0;i<32;i++){  // note loop values
  Serial.print(RX_Data[i], HEX);
  Serial.print(',');
}

Serial.println('');




So we don't have to scroll so much and it will make it obvious how many times we get data.

______
Rob

i use this code to master

while (1)

{
   
    while(!STM32vldiscovery_PBGetState(BUTTON_USER));
   
   
    /* Transfer procedure /
    for(TxIdx=0;TxIdx < BufferSize;TxIdx++)
    {
      GPIO_ResetBits(SPIy_GPIO, SPIy_PIN_NSS );
     
      //    /
Wait for SPIy Tx buffer empty /
      while (SPI_I2S_GetFlagStatus(SPIy, SPI_I2S_FLAG_TXE) == RESET);
     
      //    /
Send SPIy data /
      SPI_I2S_SendData(SPIy, SPIy_Buffer_Tx[TxIdx]);
     
      //    /
Wait for SPIy data reception /
      while (SPI_I2S_GetFlagStatus(SPIy, SPI_I2S_FLAG_RXNE) == RESET);
//      ////    /
Read SPIz received data */
      rec=SPI_I2S_ReceiveData(SPIy);
      // 
      GPIO_SetBits(SPIy_GPIO, SPIy_PIN_NSS );
     
    }



i start sending data when i push button, i think only 32 data has sent.
Master speed as i write in configuration is 2MHZ

ok, this is my new code with preconfigured rx_data as 0x00, and your modification.

#include <SPI.h>

#define SCK_PIN   13
#define MISO_PIN  12
#define MOSI_PIN  11
#define SS_PIN    10

void SlaveInit(void) {
  // Set MISO output, all others input
  pinMode(SCK_PIN, INPUT);
  pinMode(MOSI_PIN, INPUT);
  pinMode(MISO_PIN, OUTPUT);
  pinMode(SS_PIN, INPUT);

  // Enable SPI
  SPCR = B00101100;
  SPCR = (1<<SPE);
}
uint8_t RX_Data[32] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                       0x00, 0x00, 0x00, 0x00};

uint8_t ReadByte(void) {
uint8_t *ptr = RX_Data;
	 for (int i = 0; i < 32; i++){
		// SPDR = 0x01;			 // preload the data reg
  while(!(SPSR & (1<<SPIF))) ;
		*ptr++ = SPDR;			 // save byte
	 }
}

void setup()
{
  Serial.begin(9600);
  SlaveInit();
}

void loop()
{

ReadByte();
 
for (int j = 0;j<32;j++){  // note loop values
  Serial.print(RX_Data[j], HEX);
  Serial.print(',');
  }
Serial.println(' ');
}
0,40,40,20,20,60,60,10,10,50,50,30,30,70,70,8,8,48,48,28,28,68,68,18,18,58,58,38,38,78,78,4, 
28,28,68,68,18,18,58,58,38,38,78,78,4,0,40,40,20,20,60,60,10,10,50,50,30,30,70,70,8,8,48,48,

What have you got on the Arduino's SS pin? I see you are controlling it with the master, is it connected properly?

It seems that most bytes are being received twice, if we ignore that and look at the bits in the first few values

40	10000000
20	01000000
60	11000000

10	00010000
50	01010000
30	00110000
70	01110000

8	00000100
48	01001000
28	00101000
68	01101000
18	00011000
58	01011000
38	00111000
78	01111000

We can see there is a progression of sorts from the MSB position. In fact when I did the first 3 values I thought "Yes that's it, it's an MSB/LSB problem".

I still can't get the pattern but I think it's partly to do with transmitting MSB first and receiving LSB first , or vice versa.

Check out which is being used at both ends. I don't know what the Arduino SPI library defaults to but there is a SPI.setBitOrder() function to force it.

Also just thinking about the speed, at 2MBs you have 500nS to read and store a character, that's only 8 instructions on the Arduino, not long enough to do the job I think. Slow down the master (a lot) to prove this one way or another. This does have a quasi-random look to it that might be explained by the two ends being synced but the slave not being able to keep up.


Rob

Graynomad:
What have you got on the Arduino's SS pin? I see you are controlling it with the master, is it connected properly?

It seems that most bytes are being received twice, if we ignore that and look at the bits in the first few values

40	10000000

20 01000000
60 11000000

10 00010000
50 01010000
30 00110000
70 01110000

8 00000100
48 01001000
28 00101000
68 01101000
18 00011000
58 01011000
38 00111000
78 01111000




We can see there is a progression of sorts from the MSB position. In fact when I did the first 3 values I thought "Yes that's it, it's an MSB/LSB problem".

I still can't get the pattern but I think it's partly to do with transmitting MSB first and receiving LSB first , or vice versa.

Check out which is being used at both ends. I don't know what the Arduino SPI library defaults to but there is a SPI.setBitOrder() function to force it. 

Also just thinking about the speed, at 2MBs you have 500nS to read and store a character, that's only 8 instructions on the Arduino, not long enough to do the job I think. Slow down the master (a lot) to prove this one way or another. This does have a quasi-random look to it that might be explained by the two ends being synced but the slave not being able to keep up.


_____
Rob

Thx for great help.
Now i should go to work, this evening when i come back i will do some modify, but i don't understand why if i configured all in lsb i've this this problem (SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_LSB; STM32 DORD = 1 DORD - Sends data least Significant Bit First when 1, most Significant Bit first when 0 ARDUINO
For clock i will downgrade clock speed of stm32 from 24mhz to 8 mhz then i will have a 8/12 Mhz on the SPI and i can easily see if there is a clock speed problem.

ok i slowed with prescale baud rate to: (24mhz/32) and configured master as MSB:
now i have this:

0,0,1,0,0,2,3,0,0,0,1,4,4,6,7,0,0,0,1,0,0,2,3,8,8,8,9,C,C,E,F,0, 
8,8,9,C,C,E,F,0,0,0,1,0,0,2,3,0,0,0,1,4,4,6,7,0,0,0,1,0,0,2,3,8, 
6,7,0,0,0,1,0,0,2,3,8,8,8,9,C,C,E,F,0,0,0,1,0,0,2,3,0,0,0,1,4,4, 
1,4,4,6,7,0,0,0,1,0,0,2,3,8,8,8,9,C,C,E,F,0,0,0,1,0,0,2,3,0,0,0, 
0,0,1,4,4,6,7,0,0,0,1,0,0,2,3,8,8,8,9,C,C,E,F,0,0,0,1,0,0,2,3,0,

P.S.
Multiple lines isn't a problem i use a delay to master to send only 32bit, i write here more than 1 line cause it can help to identify the problem.
P.P.S
I try to change DORD, for have LSB or MSB but nothing change.

i try to use new libraries of spi (1.01)

#include <SPI.h>

#define SCK   13
#define MISO  12
#define MOSI  11
#define SS    10


uint8_t RX_Data[32] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                       0x00, 0x00, 0x00, 0x00};

uint8_t ReadByte(void) {
uint8_t *ptr = RX_Data;
	 for (int i = 0; i < 32; i++){
		 // SPDR = 0x01;			 // preload the data reg
  while(!(SPSR & (1<<SPIF))) ;
		 *ptr++ = SPDR;			 // save byte
	 }
}

void setup()
{
  pinMode(SCK, INPUT);
  pinMode(MOSI, INPUT);
  pinMode(MISO, OUTPUT);
  pinMode(SS, INPUT);
  
  Serial.begin(9600);
  SPI.setBitOrder(MSBFIRST);
 SPI.setDataMode(SPI_MODE3);
  //SPI.setClockDivider();
  SPI.begin();
   
}

void loop()
{

ReadByte();
 
for (int j = 0;j<32;j++){  // note loop values
  Serial.print(RX_Data[j], HEX);
  Serial.print(',');
  }
Serial.println(' ');
}

With this code SPI doesn't starts, i should to add "SPCR = (1<<SPE); but this shouldn't be necessary from library...
if i add this i have this output:

C,F,0,1,0,3,0,1,4,7,0,1,0,3,8,9,C,F,0,1,0,3,0,1,4,7,0,1,0,3,8,9, 
C,F,0,1,0,3,0,1,4,7,0,1,0,3,8,9,C,F,0,1,0,3,0,1,4,7,0,1,0,3,8,9,