STM32F103 Nucleo Board: SPI Problem. SPI Slave Receive does not work









up vote
1
down vote

favorite












I'm trying to get an SPI connection between two of the above mentioned Boards to work.

The Master seems to work well, I am using a timer Interrupt to periodically send 8bit Information "0xA5". That's what I can confirm at the MOSI Pin with an Oscilloscope. That's basically everything the Master does in my test setup.

I will now include the Initializing Code for the Slave:



void mainInit(void)

// System Initialisierung
SystemInit();


// Strukturen anlegen
RCC_ClocksTypeDef RCC_Clocks; // Struktur für Clocks anlegen (optional)
GPIO_InitTypeDef GPIO_InitStructure;
SPI_InitTypeDef SPI_InitStructure; //Struktur für SPI. SS: PA8; MOSI:PA7, MISO:PA6; CLK:PA5
NVIC_InitTypeDef NVIC_InitSPI1;



// Auslesen der Clocks und Speichern in der Struktur
RCC_PCLK2Config(RCC_HCLK_Div16); // Timer Clock teilen
RCC_GetClocksFreq(&RCC_Clocks); // (optional)



// Enable Clock für Port A, Alternate Functions, SPI1 und Timer2
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);


// Interrupt Initialisieren mit SPI1
NVIC_InitSPI1.NVIC_IRQChannel = SPI1_IRQn;
NVIC_InitSPI1.NVIC_IRQChannelCmd = ENABLE;
NVIC_InitSPI1.NVIC_IRQChannelPreemptionPriority = 0x0F;
NVIC_InitSPI1.NVIC_IRQChannelSubPriority = 0x0F;
NVIC_Init(&NVIC_InitSPI1);


// Initialisierung CLK PA5
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);


// Initialisierung MOSI PA7
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);


// Initialisierung MISO PA6
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);


// Initialisierung SS PA8
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);


// Initialisierung Toggle pin
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);



// Initialisierung SPI. SPI Write ist in Funktion "TIM2_IRQHandler" in stm32f1xx_it.c
SPI_I2S_DeInit (SPI1); // Einmal deinitialisieren
SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;
SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;
SPI_InitStructure.SPI_CRCPolynomial = 7;
SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
SPI_InitStructure.SPI_Mode = SPI_Mode_Slave;
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;

// SPI1 Enable
SPI_Init(SPI1, &SPI_InitStructure);
SPI_Cmd(SPI1, ENABLE);

SPI_I2S_ITConfig(SPI1, SPI_I2S_IT_RXNE, ENABLE); // RXNE Interrupt Enable
//SPI_I2S_ITConfig(SPI1, SPI_I2S_IT_TXE, ENABLE); // TXE Interrupt Enable






The pins are connected between the Master and the Slave as following:
* MOSI to MOSI (Pin A7),
* MISO to MISO(Pin A6),
* CLK to CLK (Pin A5),
* CS to CS (PinA8).

MOSI, MISO and CLK are the assigned Pins for SPI1 on the board, but I am using a custom Pin for CS. CS is always pulled to LOW by the Master just before the Transmission begins.



Since I want to work with the SPI Interrupt, when the RXNE Flag is set, I am assuming that the RXNE is never set. But I can't figure out why.
I will also show you the interrupt Routine, but since the Interrupt Routine is never called by the µC, the problem should be elsewhere.



void SPI1_IRQHandler(void)
if(GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_8) == Bit_RESET)
if (SPI_I2S_ReceiveData(SPI1) == 0xA5)
GPIO_WriteBit(GPIOA, GPIO_Pin_10, Bit_SET);






Thanks for your help and if you need additional information, just let me know.



/* Edit */
I just found out, that my configuration works on a single board. So when I just Connect MOSI to MISO on one board, it runs perfectly. So, do you guys have any hint on where I mess up when it comes to a Master - Slave Connection with two boards?










share|improve this question























  • Did you try debugging by setting a break-point inside the IRQHandler?
    – clmno
    Nov 8 at 12:06










  • Yes, that's how i know that the Interrupt Routine is never called by the Slave. Since I am using Atollic TrueStudio, I can have a look at the Special Function Registers while debugging. Here I could see, that in the Special Function Register of SPI1, in the Shift Register (Adress 0x40013008), the value of RXNE is always 0. To my understanding, it should be 1, when Data has been received.
    – Alex
    Nov 8 at 12:13










  • check this out stackoverflow.com/questions/20319801
    – clmno
    Nov 8 at 12:27










  • Thank you, I already checked this thread before I opened this thread. Unfortunately it could not help me with my problem. I tried different Pin configurations on the Slave board. Since I am only trying to receive on the Slave and send on the Master, I did not touch the Master settings, since it works as expected.
    – Alex
    Nov 8 at 12:41














up vote
1
down vote

favorite












I'm trying to get an SPI connection between two of the above mentioned Boards to work.

The Master seems to work well, I am using a timer Interrupt to periodically send 8bit Information "0xA5". That's what I can confirm at the MOSI Pin with an Oscilloscope. That's basically everything the Master does in my test setup.

I will now include the Initializing Code for the Slave:



void mainInit(void)

// System Initialisierung
SystemInit();


// Strukturen anlegen
RCC_ClocksTypeDef RCC_Clocks; // Struktur für Clocks anlegen (optional)
GPIO_InitTypeDef GPIO_InitStructure;
SPI_InitTypeDef SPI_InitStructure; //Struktur für SPI. SS: PA8; MOSI:PA7, MISO:PA6; CLK:PA5
NVIC_InitTypeDef NVIC_InitSPI1;



// Auslesen der Clocks und Speichern in der Struktur
RCC_PCLK2Config(RCC_HCLK_Div16); // Timer Clock teilen
RCC_GetClocksFreq(&RCC_Clocks); // (optional)



// Enable Clock für Port A, Alternate Functions, SPI1 und Timer2
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);


// Interrupt Initialisieren mit SPI1
NVIC_InitSPI1.NVIC_IRQChannel = SPI1_IRQn;
NVIC_InitSPI1.NVIC_IRQChannelCmd = ENABLE;
NVIC_InitSPI1.NVIC_IRQChannelPreemptionPriority = 0x0F;
NVIC_InitSPI1.NVIC_IRQChannelSubPriority = 0x0F;
NVIC_Init(&NVIC_InitSPI1);


// Initialisierung CLK PA5
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);


// Initialisierung MOSI PA7
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);


// Initialisierung MISO PA6
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);


// Initialisierung SS PA8
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);


// Initialisierung Toggle pin
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);



// Initialisierung SPI. SPI Write ist in Funktion "TIM2_IRQHandler" in stm32f1xx_it.c
SPI_I2S_DeInit (SPI1); // Einmal deinitialisieren
SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;
SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;
SPI_InitStructure.SPI_CRCPolynomial = 7;
SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
SPI_InitStructure.SPI_Mode = SPI_Mode_Slave;
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;

// SPI1 Enable
SPI_Init(SPI1, &SPI_InitStructure);
SPI_Cmd(SPI1, ENABLE);

SPI_I2S_ITConfig(SPI1, SPI_I2S_IT_RXNE, ENABLE); // RXNE Interrupt Enable
//SPI_I2S_ITConfig(SPI1, SPI_I2S_IT_TXE, ENABLE); // TXE Interrupt Enable






The pins are connected between the Master and the Slave as following:
* MOSI to MOSI (Pin A7),
* MISO to MISO(Pin A6),
* CLK to CLK (Pin A5),
* CS to CS (PinA8).

MOSI, MISO and CLK are the assigned Pins for SPI1 on the board, but I am using a custom Pin for CS. CS is always pulled to LOW by the Master just before the Transmission begins.



Since I want to work with the SPI Interrupt, when the RXNE Flag is set, I am assuming that the RXNE is never set. But I can't figure out why.
I will also show you the interrupt Routine, but since the Interrupt Routine is never called by the µC, the problem should be elsewhere.



void SPI1_IRQHandler(void)
if(GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_8) == Bit_RESET)
if (SPI_I2S_ReceiveData(SPI1) == 0xA5)
GPIO_WriteBit(GPIOA, GPIO_Pin_10, Bit_SET);






Thanks for your help and if you need additional information, just let me know.



/* Edit */
I just found out, that my configuration works on a single board. So when I just Connect MOSI to MISO on one board, it runs perfectly. So, do you guys have any hint on where I mess up when it comes to a Master - Slave Connection with two boards?










share|improve this question























  • Did you try debugging by setting a break-point inside the IRQHandler?
    – clmno
    Nov 8 at 12:06










  • Yes, that's how i know that the Interrupt Routine is never called by the Slave. Since I am using Atollic TrueStudio, I can have a look at the Special Function Registers while debugging. Here I could see, that in the Special Function Register of SPI1, in the Shift Register (Adress 0x40013008), the value of RXNE is always 0. To my understanding, it should be 1, when Data has been received.
    – Alex
    Nov 8 at 12:13










  • check this out stackoverflow.com/questions/20319801
    – clmno
    Nov 8 at 12:27










  • Thank you, I already checked this thread before I opened this thread. Unfortunately it could not help me with my problem. I tried different Pin configurations on the Slave board. Since I am only trying to receive on the Slave and send on the Master, I did not touch the Master settings, since it works as expected.
    – Alex
    Nov 8 at 12:41












up vote
1
down vote

favorite









up vote
1
down vote

favorite











I'm trying to get an SPI connection between two of the above mentioned Boards to work.

The Master seems to work well, I am using a timer Interrupt to periodically send 8bit Information "0xA5". That's what I can confirm at the MOSI Pin with an Oscilloscope. That's basically everything the Master does in my test setup.

I will now include the Initializing Code for the Slave:



void mainInit(void)

// System Initialisierung
SystemInit();


// Strukturen anlegen
RCC_ClocksTypeDef RCC_Clocks; // Struktur für Clocks anlegen (optional)
GPIO_InitTypeDef GPIO_InitStructure;
SPI_InitTypeDef SPI_InitStructure; //Struktur für SPI. SS: PA8; MOSI:PA7, MISO:PA6; CLK:PA5
NVIC_InitTypeDef NVIC_InitSPI1;



// Auslesen der Clocks und Speichern in der Struktur
RCC_PCLK2Config(RCC_HCLK_Div16); // Timer Clock teilen
RCC_GetClocksFreq(&RCC_Clocks); // (optional)



// Enable Clock für Port A, Alternate Functions, SPI1 und Timer2
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);


// Interrupt Initialisieren mit SPI1
NVIC_InitSPI1.NVIC_IRQChannel = SPI1_IRQn;
NVIC_InitSPI1.NVIC_IRQChannelCmd = ENABLE;
NVIC_InitSPI1.NVIC_IRQChannelPreemptionPriority = 0x0F;
NVIC_InitSPI1.NVIC_IRQChannelSubPriority = 0x0F;
NVIC_Init(&NVIC_InitSPI1);


// Initialisierung CLK PA5
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);


// Initialisierung MOSI PA7
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);


// Initialisierung MISO PA6
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);


// Initialisierung SS PA8
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);


// Initialisierung Toggle pin
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);



// Initialisierung SPI. SPI Write ist in Funktion "TIM2_IRQHandler" in stm32f1xx_it.c
SPI_I2S_DeInit (SPI1); // Einmal deinitialisieren
SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;
SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;
SPI_InitStructure.SPI_CRCPolynomial = 7;
SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
SPI_InitStructure.SPI_Mode = SPI_Mode_Slave;
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;

// SPI1 Enable
SPI_Init(SPI1, &SPI_InitStructure);
SPI_Cmd(SPI1, ENABLE);

SPI_I2S_ITConfig(SPI1, SPI_I2S_IT_RXNE, ENABLE); // RXNE Interrupt Enable
//SPI_I2S_ITConfig(SPI1, SPI_I2S_IT_TXE, ENABLE); // TXE Interrupt Enable






The pins are connected between the Master and the Slave as following:
* MOSI to MOSI (Pin A7),
* MISO to MISO(Pin A6),
* CLK to CLK (Pin A5),
* CS to CS (PinA8).

MOSI, MISO and CLK are the assigned Pins for SPI1 on the board, but I am using a custom Pin for CS. CS is always pulled to LOW by the Master just before the Transmission begins.



Since I want to work with the SPI Interrupt, when the RXNE Flag is set, I am assuming that the RXNE is never set. But I can't figure out why.
I will also show you the interrupt Routine, but since the Interrupt Routine is never called by the µC, the problem should be elsewhere.



void SPI1_IRQHandler(void)
if(GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_8) == Bit_RESET)
if (SPI_I2S_ReceiveData(SPI1) == 0xA5)
GPIO_WriteBit(GPIOA, GPIO_Pin_10, Bit_SET);






Thanks for your help and if you need additional information, just let me know.



/* Edit */
I just found out, that my configuration works on a single board. So when I just Connect MOSI to MISO on one board, it runs perfectly. So, do you guys have any hint on where I mess up when it comes to a Master - Slave Connection with two boards?










share|improve this question















I'm trying to get an SPI connection between two of the above mentioned Boards to work.

The Master seems to work well, I am using a timer Interrupt to periodically send 8bit Information "0xA5". That's what I can confirm at the MOSI Pin with an Oscilloscope. That's basically everything the Master does in my test setup.

I will now include the Initializing Code for the Slave:



void mainInit(void)

// System Initialisierung
SystemInit();


// Strukturen anlegen
RCC_ClocksTypeDef RCC_Clocks; // Struktur für Clocks anlegen (optional)
GPIO_InitTypeDef GPIO_InitStructure;
SPI_InitTypeDef SPI_InitStructure; //Struktur für SPI. SS: PA8; MOSI:PA7, MISO:PA6; CLK:PA5
NVIC_InitTypeDef NVIC_InitSPI1;



// Auslesen der Clocks und Speichern in der Struktur
RCC_PCLK2Config(RCC_HCLK_Div16); // Timer Clock teilen
RCC_GetClocksFreq(&RCC_Clocks); // (optional)



// Enable Clock für Port A, Alternate Functions, SPI1 und Timer2
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);


// Interrupt Initialisieren mit SPI1
NVIC_InitSPI1.NVIC_IRQChannel = SPI1_IRQn;
NVIC_InitSPI1.NVIC_IRQChannelCmd = ENABLE;
NVIC_InitSPI1.NVIC_IRQChannelPreemptionPriority = 0x0F;
NVIC_InitSPI1.NVIC_IRQChannelSubPriority = 0x0F;
NVIC_Init(&NVIC_InitSPI1);


// Initialisierung CLK PA5
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);


// Initialisierung MOSI PA7
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);


// Initialisierung MISO PA6
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);


// Initialisierung SS PA8
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);


// Initialisierung Toggle pin
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);



// Initialisierung SPI. SPI Write ist in Funktion "TIM2_IRQHandler" in stm32f1xx_it.c
SPI_I2S_DeInit (SPI1); // Einmal deinitialisieren
SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;
SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;
SPI_InitStructure.SPI_CRCPolynomial = 7;
SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
SPI_InitStructure.SPI_Mode = SPI_Mode_Slave;
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;

// SPI1 Enable
SPI_Init(SPI1, &SPI_InitStructure);
SPI_Cmd(SPI1, ENABLE);

SPI_I2S_ITConfig(SPI1, SPI_I2S_IT_RXNE, ENABLE); // RXNE Interrupt Enable
//SPI_I2S_ITConfig(SPI1, SPI_I2S_IT_TXE, ENABLE); // TXE Interrupt Enable






The pins are connected between the Master and the Slave as following:
* MOSI to MOSI (Pin A7),
* MISO to MISO(Pin A6),
* CLK to CLK (Pin A5),
* CS to CS (PinA8).

MOSI, MISO and CLK are the assigned Pins for SPI1 on the board, but I am using a custom Pin for CS. CS is always pulled to LOW by the Master just before the Transmission begins.



Since I want to work with the SPI Interrupt, when the RXNE Flag is set, I am assuming that the RXNE is never set. But I can't figure out why.
I will also show you the interrupt Routine, but since the Interrupt Routine is never called by the µC, the problem should be elsewhere.



void SPI1_IRQHandler(void)
if(GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_8) == Bit_RESET)
if (SPI_I2S_ReceiveData(SPI1) == 0xA5)
GPIO_WriteBit(GPIOA, GPIO_Pin_10, Bit_SET);






Thanks for your help and if you need additional information, just let me know.



/* Edit */
I just found out, that my configuration works on a single board. So when I just Connect MOSI to MISO on one board, it runs perfectly. So, do you guys have any hint on where I mess up when it comes to a Master - Slave Connection with two boards?







interrupt stm32 spi






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 10 at 14:04

























asked Nov 8 at 8:49









Alex

63




63











  • Did you try debugging by setting a break-point inside the IRQHandler?
    – clmno
    Nov 8 at 12:06










  • Yes, that's how i know that the Interrupt Routine is never called by the Slave. Since I am using Atollic TrueStudio, I can have a look at the Special Function Registers while debugging. Here I could see, that in the Special Function Register of SPI1, in the Shift Register (Adress 0x40013008), the value of RXNE is always 0. To my understanding, it should be 1, when Data has been received.
    – Alex
    Nov 8 at 12:13










  • check this out stackoverflow.com/questions/20319801
    – clmno
    Nov 8 at 12:27










  • Thank you, I already checked this thread before I opened this thread. Unfortunately it could not help me with my problem. I tried different Pin configurations on the Slave board. Since I am only trying to receive on the Slave and send on the Master, I did not touch the Master settings, since it works as expected.
    – Alex
    Nov 8 at 12:41
















  • Did you try debugging by setting a break-point inside the IRQHandler?
    – clmno
    Nov 8 at 12:06










  • Yes, that's how i know that the Interrupt Routine is never called by the Slave. Since I am using Atollic TrueStudio, I can have a look at the Special Function Registers while debugging. Here I could see, that in the Special Function Register of SPI1, in the Shift Register (Adress 0x40013008), the value of RXNE is always 0. To my understanding, it should be 1, when Data has been received.
    – Alex
    Nov 8 at 12:13










  • check this out stackoverflow.com/questions/20319801
    – clmno
    Nov 8 at 12:27










  • Thank you, I already checked this thread before I opened this thread. Unfortunately it could not help me with my problem. I tried different Pin configurations on the Slave board. Since I am only trying to receive on the Slave and send on the Master, I did not touch the Master settings, since it works as expected.
    – Alex
    Nov 8 at 12:41















Did you try debugging by setting a break-point inside the IRQHandler?
– clmno
Nov 8 at 12:06




Did you try debugging by setting a break-point inside the IRQHandler?
– clmno
Nov 8 at 12:06












Yes, that's how i know that the Interrupt Routine is never called by the Slave. Since I am using Atollic TrueStudio, I can have a look at the Special Function Registers while debugging. Here I could see, that in the Special Function Register of SPI1, in the Shift Register (Adress 0x40013008), the value of RXNE is always 0. To my understanding, it should be 1, when Data has been received.
– Alex
Nov 8 at 12:13




Yes, that's how i know that the Interrupt Routine is never called by the Slave. Since I am using Atollic TrueStudio, I can have a look at the Special Function Registers while debugging. Here I could see, that in the Special Function Register of SPI1, in the Shift Register (Adress 0x40013008), the value of RXNE is always 0. To my understanding, it should be 1, when Data has been received.
– Alex
Nov 8 at 12:13












check this out stackoverflow.com/questions/20319801
– clmno
Nov 8 at 12:27




check this out stackoverflow.com/questions/20319801
– clmno
Nov 8 at 12:27












Thank you, I already checked this thread before I opened this thread. Unfortunately it could not help me with my problem. I tried different Pin configurations on the Slave board. Since I am only trying to receive on the Slave and send on the Master, I did not touch the Master settings, since it works as expected.
– Alex
Nov 8 at 12:41




Thank you, I already checked this thread before I opened this thread. Unfortunately it could not help me with my problem. I tried different Pin configurations on the Slave board. Since I am only trying to receive on the Slave and send on the Master, I did not touch the Master settings, since it works as expected.
– Alex
Nov 8 at 12:41












1 Answer
1






active

oldest

votes

















up vote
0
down vote













Do you know the meaning of MOSI and MISO?
MOSI: Master OUT Slave IN.
MISO: Master IN Slave OUT.
Try if this connection is working.



Are the mosi and miso pins configured as Alternative function? How is "GPIO_Mode_IN_FLOATING" defined?



Please initialize your structures with 0 to be sure the configuration is clear.






share|improve this answer




















  • I know the meanings of MOSI and MISO. On the Master board, MOSI is defined as Alternative function PushPull. The MISO is defined as Floating Input. On the Slave, MOSI is defined as Floating Input and MISO as Alternative function PushPull. GPIO_Mode_IN_FLOATING is defined as "0x04". I initialized the structures with 0, but it did not fix the problem.
    – Alex
    Nov 8 at 11:16











  • I always configure all pins assigned to SPI or any other peripheral as Alternative function. Are you sure with Floating Input, the pin will be connected to the peripheral module?
    – A.R.C.
    Nov 8 at 12:59










  • What confuses me about configuring the receiving Pins (CS and MOSI) on the Slave board is, that the only way of configuring as an AF with the F10x Controller is "GPIO_Mode_AF_PP" which translates to 0x18. Isn't a PushPull configuration always an Output? I will try to set everything to AF_PP. To answer your question: No, I am not sure about the connection to the peripheral module. I am quite unsure about everything right now.
    – Alex
    Nov 8 at 13:15











  • Update: I tried your recommended configuration, but still no success. The RXNE Flag just doesn't trigger.
    – Alex
    Nov 8 at 14:42










  • Did anyone use any additional Hardware like Resistors or Capacitors or anything?
    – Alex
    Nov 8 at 15:21










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53204223%2fstm32f103-nucleo-board-spi-problem-spi-slave-receive-does-not-work%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote













Do you know the meaning of MOSI and MISO?
MOSI: Master OUT Slave IN.
MISO: Master IN Slave OUT.
Try if this connection is working.



Are the mosi and miso pins configured as Alternative function? How is "GPIO_Mode_IN_FLOATING" defined?



Please initialize your structures with 0 to be sure the configuration is clear.






share|improve this answer




















  • I know the meanings of MOSI and MISO. On the Master board, MOSI is defined as Alternative function PushPull. The MISO is defined as Floating Input. On the Slave, MOSI is defined as Floating Input and MISO as Alternative function PushPull. GPIO_Mode_IN_FLOATING is defined as "0x04". I initialized the structures with 0, but it did not fix the problem.
    – Alex
    Nov 8 at 11:16











  • I always configure all pins assigned to SPI or any other peripheral as Alternative function. Are you sure with Floating Input, the pin will be connected to the peripheral module?
    – A.R.C.
    Nov 8 at 12:59










  • What confuses me about configuring the receiving Pins (CS and MOSI) on the Slave board is, that the only way of configuring as an AF with the F10x Controller is "GPIO_Mode_AF_PP" which translates to 0x18. Isn't a PushPull configuration always an Output? I will try to set everything to AF_PP. To answer your question: No, I am not sure about the connection to the peripheral module. I am quite unsure about everything right now.
    – Alex
    Nov 8 at 13:15











  • Update: I tried your recommended configuration, but still no success. The RXNE Flag just doesn't trigger.
    – Alex
    Nov 8 at 14:42










  • Did anyone use any additional Hardware like Resistors or Capacitors or anything?
    – Alex
    Nov 8 at 15:21














up vote
0
down vote













Do you know the meaning of MOSI and MISO?
MOSI: Master OUT Slave IN.
MISO: Master IN Slave OUT.
Try if this connection is working.



Are the mosi and miso pins configured as Alternative function? How is "GPIO_Mode_IN_FLOATING" defined?



Please initialize your structures with 0 to be sure the configuration is clear.






share|improve this answer




















  • I know the meanings of MOSI and MISO. On the Master board, MOSI is defined as Alternative function PushPull. The MISO is defined as Floating Input. On the Slave, MOSI is defined as Floating Input and MISO as Alternative function PushPull. GPIO_Mode_IN_FLOATING is defined as "0x04". I initialized the structures with 0, but it did not fix the problem.
    – Alex
    Nov 8 at 11:16











  • I always configure all pins assigned to SPI or any other peripheral as Alternative function. Are you sure with Floating Input, the pin will be connected to the peripheral module?
    – A.R.C.
    Nov 8 at 12:59










  • What confuses me about configuring the receiving Pins (CS and MOSI) on the Slave board is, that the only way of configuring as an AF with the F10x Controller is "GPIO_Mode_AF_PP" which translates to 0x18. Isn't a PushPull configuration always an Output? I will try to set everything to AF_PP. To answer your question: No, I am not sure about the connection to the peripheral module. I am quite unsure about everything right now.
    – Alex
    Nov 8 at 13:15











  • Update: I tried your recommended configuration, but still no success. The RXNE Flag just doesn't trigger.
    – Alex
    Nov 8 at 14:42










  • Did anyone use any additional Hardware like Resistors or Capacitors or anything?
    – Alex
    Nov 8 at 15:21












up vote
0
down vote










up vote
0
down vote









Do you know the meaning of MOSI and MISO?
MOSI: Master OUT Slave IN.
MISO: Master IN Slave OUT.
Try if this connection is working.



Are the mosi and miso pins configured as Alternative function? How is "GPIO_Mode_IN_FLOATING" defined?



Please initialize your structures with 0 to be sure the configuration is clear.






share|improve this answer












Do you know the meaning of MOSI and MISO?
MOSI: Master OUT Slave IN.
MISO: Master IN Slave OUT.
Try if this connection is working.



Are the mosi and miso pins configured as Alternative function? How is "GPIO_Mode_IN_FLOATING" defined?



Please initialize your structures with 0 to be sure the configuration is clear.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 8 at 10:15









A.R.C.

1388




1388











  • I know the meanings of MOSI and MISO. On the Master board, MOSI is defined as Alternative function PushPull. The MISO is defined as Floating Input. On the Slave, MOSI is defined as Floating Input and MISO as Alternative function PushPull. GPIO_Mode_IN_FLOATING is defined as "0x04". I initialized the structures with 0, but it did not fix the problem.
    – Alex
    Nov 8 at 11:16











  • I always configure all pins assigned to SPI or any other peripheral as Alternative function. Are you sure with Floating Input, the pin will be connected to the peripheral module?
    – A.R.C.
    Nov 8 at 12:59










  • What confuses me about configuring the receiving Pins (CS and MOSI) on the Slave board is, that the only way of configuring as an AF with the F10x Controller is "GPIO_Mode_AF_PP" which translates to 0x18. Isn't a PushPull configuration always an Output? I will try to set everything to AF_PP. To answer your question: No, I am not sure about the connection to the peripheral module. I am quite unsure about everything right now.
    – Alex
    Nov 8 at 13:15











  • Update: I tried your recommended configuration, but still no success. The RXNE Flag just doesn't trigger.
    – Alex
    Nov 8 at 14:42










  • Did anyone use any additional Hardware like Resistors or Capacitors or anything?
    – Alex
    Nov 8 at 15:21
















  • I know the meanings of MOSI and MISO. On the Master board, MOSI is defined as Alternative function PushPull. The MISO is defined as Floating Input. On the Slave, MOSI is defined as Floating Input and MISO as Alternative function PushPull. GPIO_Mode_IN_FLOATING is defined as "0x04". I initialized the structures with 0, but it did not fix the problem.
    – Alex
    Nov 8 at 11:16











  • I always configure all pins assigned to SPI or any other peripheral as Alternative function. Are you sure with Floating Input, the pin will be connected to the peripheral module?
    – A.R.C.
    Nov 8 at 12:59










  • What confuses me about configuring the receiving Pins (CS and MOSI) on the Slave board is, that the only way of configuring as an AF with the F10x Controller is "GPIO_Mode_AF_PP" which translates to 0x18. Isn't a PushPull configuration always an Output? I will try to set everything to AF_PP. To answer your question: No, I am not sure about the connection to the peripheral module. I am quite unsure about everything right now.
    – Alex
    Nov 8 at 13:15











  • Update: I tried your recommended configuration, but still no success. The RXNE Flag just doesn't trigger.
    – Alex
    Nov 8 at 14:42










  • Did anyone use any additional Hardware like Resistors or Capacitors or anything?
    – Alex
    Nov 8 at 15:21















I know the meanings of MOSI and MISO. On the Master board, MOSI is defined as Alternative function PushPull. The MISO is defined as Floating Input. On the Slave, MOSI is defined as Floating Input and MISO as Alternative function PushPull. GPIO_Mode_IN_FLOATING is defined as "0x04". I initialized the structures with 0, but it did not fix the problem.
– Alex
Nov 8 at 11:16





I know the meanings of MOSI and MISO. On the Master board, MOSI is defined as Alternative function PushPull. The MISO is defined as Floating Input. On the Slave, MOSI is defined as Floating Input and MISO as Alternative function PushPull. GPIO_Mode_IN_FLOATING is defined as "0x04". I initialized the structures with 0, but it did not fix the problem.
– Alex
Nov 8 at 11:16













I always configure all pins assigned to SPI or any other peripheral as Alternative function. Are you sure with Floating Input, the pin will be connected to the peripheral module?
– A.R.C.
Nov 8 at 12:59




I always configure all pins assigned to SPI or any other peripheral as Alternative function. Are you sure with Floating Input, the pin will be connected to the peripheral module?
– A.R.C.
Nov 8 at 12:59












What confuses me about configuring the receiving Pins (CS and MOSI) on the Slave board is, that the only way of configuring as an AF with the F10x Controller is "GPIO_Mode_AF_PP" which translates to 0x18. Isn't a PushPull configuration always an Output? I will try to set everything to AF_PP. To answer your question: No, I am not sure about the connection to the peripheral module. I am quite unsure about everything right now.
– Alex
Nov 8 at 13:15





What confuses me about configuring the receiving Pins (CS and MOSI) on the Slave board is, that the only way of configuring as an AF with the F10x Controller is "GPIO_Mode_AF_PP" which translates to 0x18. Isn't a PushPull configuration always an Output? I will try to set everything to AF_PP. To answer your question: No, I am not sure about the connection to the peripheral module. I am quite unsure about everything right now.
– Alex
Nov 8 at 13:15













Update: I tried your recommended configuration, but still no success. The RXNE Flag just doesn't trigger.
– Alex
Nov 8 at 14:42




Update: I tried your recommended configuration, but still no success. The RXNE Flag just doesn't trigger.
– Alex
Nov 8 at 14:42












Did anyone use any additional Hardware like Resistors or Capacitors or anything?
– Alex
Nov 8 at 15:21




Did anyone use any additional Hardware like Resistors or Capacitors or anything?
– Alex
Nov 8 at 15:21

















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53204223%2fstm32f103-nucleo-board-spi-problem-spi-slave-receive-does-not-work%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

How to read a connectionString WITH PROVIDER in .NET Core?

In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

Museum of Modern and Contemporary Art of Trento and Rovereto