Question
Synchronizing SPI in STM32F107
Hello,
In my project, I connected two MCUs to each other (MISO->MISO, MOSI->MOSI, SCK->SCK). I define a new pin as the CS pin (PORTC.10). But in my receiver the sequence is wrong. Here is my code( For example I send 1234 but I get something else, sometimes works many times doesn't)
void SPI1_IRQHandler(void){
unsigned long Input;
if (SPI_I2S_GetITStatus(SPI1,SPI_I2S_IT_RXNE)== SET)
{
Input=SPI_I2S_ReceiveData(SPI1);
MSG[Position]=Input;Position=Position+1;
if(Position>=(PosMax+1)){Position=0;SPI_I2S_ITConfig(SPI1,SPI_I2S_IT_RXNE,DISABLE);}
}
if (SPI_I2S_GetITStatus(SPI1, SPI_I2S_IT_TXE)== SET )
{
SPI_I2S_ITConfig(SPI1, SPI_I2S_IT_TXE, DISABLE);
}
}
void EXTI15_10_IRQHandler(void){
if (EXTI_GetITStatus(EXTI_Line10) != RESET) {
if(GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_10)==0)
{
SPI_I2S_ITConfig(SPI1,SPI_I2S_IT_RXNE,ENABLE);
}
else
{
SPI_I2S_ITConfig(SPI1,SPI_I2S_IT_RXNE,DISABLE);
if(Position>=PosMax)
{
Position=0;
SendTest=MSG[2];
}
}
EXTI_ClearITPendingBit(EXTI_Line10);
}I checked the signal on oscilloscope and all transmitted signals are correct. However, my receiver MCU lose the position of incoming data and lost my data(sometimes when it is synchronized by transmitter works fine but other times it loses my data).
