Pages: 1 2 [3]   Go Down
Author Topic: SPI Slave [SOLVED]  (Read 4658 times)
0 Members and 1 Guest are viewing this topic.
nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 126
Posts: 8471
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Offline Offline
Jr. Member
**
Karma: 1
Posts: 96
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
   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:
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);

Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 126
Posts: 8471
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Offline Offline
Jr. Member
**
Karma: 1
Posts: 96
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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()
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

http://www.gammon.com.au/spi
Logged

Offline Offline
Jr. Member
**
Karma: 1
Posts: 96
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Solved:
i don't know why but mode0 of arduino doesn't work with
Code:
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:
  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.
Logged

Pages: 1 2 [3]   Go Up
Jump to: