Forum: Mikrocontroller und Digitale Elektronik STM32 F10x_SPI RX Problem


von Floxx (Gast)


Lesenswert?

Hallo,

ich verzweifle langsam...
ich versuche auf meinem STM32F103RBT per SPI ein Byte zu empfangen.
Ich belege nur SCK und MOSI, da der STM als Slave arbeiten und in 
folgendem Programm immer die SPI auslesen soll.

Der Code bis jetzt:
1
void SPI2_Init2(void){
2
   GPIO_InitTypeDef  GPIO_InitStructure;
3
     SPI_InitTypeDef  REC_SPI;
4
5
     // bring up the GPIOs for SPI mode
6
     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
7
8
     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
9
     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_15;    // MOSI and SCK are inputs
10
     GPIO_Init(GPIOB, &GPIO_InitStructure);
11
12
     // bring up SPI clocks
13
     RCC_APB2PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE);
14
15
   REC_SPI.SPI_Direction = SPI_Direction_1Line_Rx;
16
   REC_SPI.SPI_Mode = SPI_Mode_Slave;
17
   SPI_Init(SPI2, &REC_SPI);
18
19
   SPI_Cmd(SPI2, ENABLE);
20
}
dann in der main nach dem init von oben:
1
//read data
2
  while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_RXNE) == RESET){};
3
  rec_data = SPI_I2S_ReceiveData(SPI2);

Der Controller bleibt in der
1
while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_RXNE) == RESET){};
-Schleife hängen und kommt nicht mehr raus.
Hat irgendwer Tips, was ich falsch gemacht habe? Initialisierung? Ich 
finde kaum ein Beispiel im Internet...

Danke!

von Lötlackl *. (pappnase) Benutzerseite


Lesenswert?

aus stm32f10x_spi.h
1
typedef struct
2
{
3
  uint16_t SPI_Direction;           /*!< Specifies the SPI unidirectional or bidirectional data mode.
4
                                         This parameter can be a value of @ref SPI_data_direction */
5
6
  uint16_t SPI_Mode;                /*!< Specifies the SPI operating mode.
7
                                         This parameter can be a value of @ref SPI_mode */
8
9
  uint16_t SPI_DataSize;            /*!< Specifies the SPI data size.
10
                                         This parameter can be a value of @ref SPI_data_size */
11
12
  uint16_t SPI_CPOL;                /*!< Specifies the serial clock steady state.
13
                                         This parameter can be a value of @ref SPI_Clock_Polarity */
14
15
  uint16_t SPI_CPHA;                /*!< Specifies the clock active edge for the bit capture.
16
                                         This parameter can be a value of @ref SPI_Clock_Phase */
17
18
  uint16_t SPI_NSS;                 /*!< Specifies whether the NSS signal is managed by
19
                                         hardware (NSS pin) or by software using the SSI bit.
20
                                         This parameter can be a value of @ref SPI_Slave_Select_management */
21
 
22
  uint16_t SPI_BaudRatePrescaler;   /*!< Specifies the Baud Rate prescaler value which will be
23
                                         used to configure the transmit and receive SCK clock.
24
                                         This parameter can be a value of @ref SPI_BaudRate_Prescaler.
25
                                         @note The communication clock is derived from the master
26
                                               clock. The slave clock does not need to be set. */
27
28
  uint16_t SPI_FirstBit;            /*!< Specifies whether data transfers start from MSB or LSB bit.
29
                                         This parameter can be a value of @ref SPI_MSB_LSB_transmission */
30
31
  uint16_t SPI_CRCPolynomial;       /*!< Specifies the polynomial used for the CRC calculation. */
32
}SPI_InitTypeDef;

Mir kommt obige Initialisierung reichlich dürftig vor.
In der FW-Lib von STM sind tonnenweise Beispiele (auch) zum Thema SPI zu 
finden.

mfg

von Bastler (Gast)


Lesenswert?

Muss der SlaveSelect Pin beschaltet werden?

von Floxx (Gast)


Lesenswert?

Hi,
Den Code hab ich aus der FW Lib von ST und da brauchts anscheinend nicht 
mehr config arbeit für den Slave.
SPI TX als Master hab ich hinbekommen, nur hier beim Slave klappts 
nicht.

Bei den Atmels war das immer so ein 2-Zeiler, hier gibts irgendwie 10 
verschiedene Möglichkeiten und alle haben 700 Zeilen. Das kann ja nicht 
sein...hat denn keiner eine ganz simple Lösung?

von sdlhf (Gast)


Lesenswert?

Du solltest Dich mit dem Thema

>Muss der SlaveSelect Pin beschaltet werden?

eingehender befassen...

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.