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?
interrupt stm32 spi
add a comment |
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?
interrupt stm32 spi
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
add a comment |
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?
interrupt stm32 spi
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
interrupt stm32 spi
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
add a comment |
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
add a comment |
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.
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
|
show 2 more comments
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.
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
|
show 2 more comments
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.
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
|
show 2 more comments
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.
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.
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
|
show 2 more comments
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
|
show 2 more comments
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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