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.










share|improve this question









New contributor




Alex is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • Did you try debugging by setting a break-point inside the IRQHandler?
    – clmno
    yesterday










  • 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
    yesterday










  • check this out stackoverflow.com/questions/20319801
    – clmno
    yesterday










  • 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
    yesterday















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.










share|improve this question









New contributor




Alex is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • Did you try debugging by setting a break-point inside the IRQHandler?
    – clmno
    yesterday










  • 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
    yesterday










  • check this out stackoverflow.com/questions/20319801
    – clmno
    yesterday










  • 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
    yesterday













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.










share|improve this question









New contributor




Alex is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











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.







interrupt stm32 spi






share|improve this question









New contributor




Alex is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Alex is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited yesterday









clmno

489211




489211






New contributor




Alex is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 2 days ago









Alex

62




62




New contributor




Alex is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Alex is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Alex is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • Did you try debugging by setting a break-point inside the IRQHandler?
    – clmno
    yesterday










  • 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
    yesterday










  • check this out stackoverflow.com/questions/20319801
    – clmno
    yesterday










  • 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
    yesterday


















  • Did you try debugging by setting a break-point inside the IRQHandler?
    – clmno
    yesterday










  • 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
    yesterday










  • check this out stackoverflow.com/questions/20319801
    – clmno
    yesterday










  • 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
    yesterday
















Did you try debugging by setting a break-point inside the IRQHandler?
– clmno
yesterday




Did you try debugging by setting a break-point inside the IRQHandler?
– clmno
yesterday












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
yesterday




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
yesterday












check this out stackoverflow.com/questions/20319801
– clmno
yesterday




check this out stackoverflow.com/questions/20319801
– clmno
yesterday












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
yesterday




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
yesterday












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
    yesterday












  • 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.
    yesterday










  • 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
    yesterday












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










  • Did anyone use any additional Hardware like Resistors or Capacitors or anything?
    – Alex
    yesterday











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


}
});






Alex is a new contributor. Be nice, and check out our Code of Conduct.










 

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
































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
    yesterday












  • 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.
    yesterday










  • 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
    yesterday












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










  • Did anyone use any additional Hardware like Resistors or Capacitors or anything?
    – Alex
    yesterday















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
    yesterday












  • 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.
    yesterday










  • 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
    yesterday












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










  • Did anyone use any additional Hardware like Resistors or Capacitors or anything?
    – Alex
    yesterday













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 2 days ago









A.R.C.

1088




1088












  • 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
    yesterday












  • 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.
    yesterday










  • 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
    yesterday












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










  • Did anyone use any additional Hardware like Resistors or Capacitors or anything?
    – Alex
    yesterday


















  • 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
    yesterday












  • 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.
    yesterday










  • 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
    yesterday












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










  • Did anyone use any additional Hardware like Resistors or Capacitors or anything?
    – Alex
    yesterday
















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
yesterday






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
yesterday














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.
yesterday




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.
yesterday












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
yesterday






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
yesterday














Update: I tried your recommended configuration, but still no success. The RXNE Flag just doesn't trigger.
– Alex
yesterday




Update: I tried your recommended configuration, but still no success. The RXNE Flag just doesn't trigger.
– Alex
yesterday












Did anyone use any additional Hardware like Resistors or Capacitors or anything?
– Alex
yesterday




Did anyone use any additional Hardware like Resistors or Capacitors or anything?
– Alex
yesterday










Alex is a new contributor. Be nice, and check out our Code of Conduct.










 

draft saved


draft discarded


















Alex is a new contributor. Be nice, and check out our Code of Conduct.













Alex is a new contributor. Be nice, and check out our Code of Conduct.












Alex is a new contributor. Be nice, and check out our Code of Conduct.















 


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




















































































Popular posts from this blog

Guess what letter conforming each word

Port of Spain

Run scheduled task as local user group (not BUILTIN)