cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F107 SPI receiving problem

parisa
Senior

Hello,

Here is my SPI configuration and interrupt codes:

void SPIConfiguration(void){
	SPI_InitTypeDef  SPI_InitStructure;
 	 GPIO_InitTypeDef GPIO_InitStructure;
	NVIC_InitTypeDef NVIC_InitStructure;
	
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI3,ENABLE);
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);
	GPIO_PinRemapConfig(GPIO_Remap_SPI3,DISABLE);
	GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable,ENABLE);
	
	
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1,ENABLE);
	GPIO_PinRemapConfig(GPIO_Remap_SPI1,DISABLE);
	
	
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5| GPIO_Pin_7;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(GPIOA, &GPIO_InitStructure);
 
  SPI_InitStructure.SPI_Direction =SPI_Direction_1Line_Rx;
  SPI_InitStructure.SPI_Mode = SPI_Mode_Slave ;
  SPI_InitStructure.SPI_DataSize = SPI_DataSize_16b;
  SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;
  SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;
  SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
  SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_32;
  SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
  SPI_InitStructure.SPI_CRCPolynomial = 7;
  SPI_Init(SPI1, &SPI_InitStructure);
  SPI_Cmd(SPI1, ENABLE);
  SPI_SSOutputCmd(SPI1,DISABLE);
  SPI_I2S_ITConfig(SPI1,SPI_I2S_IT_RXNE,ENABLE);
	
	
  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_3);	
  NVIC_InitStructure.NVIC_IRQChannel = SPI1_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);	
	
	
	
}
 
void SPI1_IRQHandler(void){		
 
	
			if (SPI_I2S_GetITStatus(SPI1,SPI_I2S_IT_RXNE)== SET) 
       				 {  		 						
							SendTest=SPI_I2S_ReceiveData(SPI1);							
				}
				 		 
				if (SPI_I2S_GetITStatus(SPI1, SPI_I2S_IT_TXE)== SET )  
					{  		
							SPI_I2S_ITConfig(SPI1, SPI_I2S_IT_TXE, DISABLE);
					}
					
}

But I just receive 0 while the input data and CLK are available and valid(I checked them on the oscilloscope)(the transmitter is another STM32 whose settings is approximately the same (instead of SPI_Mode_Slave, SPI_Direction_1Line_Rx).

MOSI->MOSI

CLK->CLK

what is my mistake?

0 REPLIES 0