Go Down

Topic: SPI Slave [SOLVED] (Read 6412 times) previous topic - next topic

Graynomad

How about the slave code?

Mind you if it's stm32 code using their libraries I don't know if we can help, but maybe.


Just a thought, add a small delay() here

digitalWrite(SS, LOW);
delay (10);
for (int i = 0; i < 32; i++){

Maybe the stm can't respond in time after SS goes LOW. That might explain why you are missing the first number.

______
Rob
Rob Gray aka the GRAYnomad www.robgray.com

zuzzuz


How about the slave code?

Mind you if it's stm32 code using their libraries I don't know if we can help, but maybe.


Just a thought, add a small delay() here

digitalWrite(SS, LOW);
delay (10);
for (int i = 0; i < 32; i++){

Maybe the stm can't respond in time after SS goes LOW. That might explain why you are missing the first number.

______
Rob

I use that dalay for being sure it's not too fast than slave (cause i tryed without and i have same result) also i try with 10 but same result.
This is Slave code of stm32 (i used it with 2 stm32VLdiscovery and run good)
When i used arduino as slave i have had same problem if u remember same post ago cause "while (!(SPSR & _BV(SPIF)))".
Code: [Select]
   while (1)
   {
     
     /* Transfer procedure */
     for (RxIdx=0; RxIdx < BufferSize;RxIdx++)
     {

       
   
       //    /* Wait for SPIz data reception */
       while (SPI_I2S_GetFlagStatus(SPIy, SPI_I2S_FLAG_RXNE) == RESET);
       
       //    /* Read SPIz received data */
       SPIy_Buffer_Rx[RxIdx] = SPI_I2S_ReceiveData(SPIy);
   
     
       
     }
     
     STM32vldiscovery_LEDToggle(LED3);
     
   }
}

this is the setting:
Code: [Select]
SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
  SPI_InitStructure.SPI_Mode = SPI_Mode_Slave;
  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_2;
  SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
  SPI_InitStructure.SPI_CRCPolynomial = 7;
  SPI_Init(SPIy, &SPI_InitStructure);



Graynomad

Quote
I use that dalay for being sure it's not too fast than slave

But did you have a delay in the same place I did? It's no use after the byte has been sent (I'm referring here to the apparent loss of the first byte, not the overall problem).

What does "SPI_CPHA_2Edge" mean?

_____
Rob
Rob Gray aka the GRAYnomad www.robgray.com

zuzzuz

SPI_CPHA_2Edge = data is captured on the second edge.
rising is first edge and falling is second edge.
CPOL and CPHA have same use in stm32 like SPI.setDataMode()

Nick Gammon

http://www.gammon.com.au/spi
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

zuzzuz

Solved:
i don't know why but mode0 of arduino doesn't work with
Code: [Select]
SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;
SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;

That configure the same state at stm32, then i changed arduino to mode1 and stm32 to
Code: [Select]

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

and work good with 0x00 to 0x20 number.
Thx for help.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy