AnsweredAssumed Answered

spi1 send data error in slave mode

Question asked by qiu.guo on Jul 25, 2013
I am using STM32F051R8T6 through spi interface to communicate with ADF7021. STM32 works in slave mode and ADF7021 works in master mode . ADF7021 provide the continually clock.
But the data output from PA6  was inconsistent with what I really send . When I send 00010100 ,the output is 000110. When I send 1001001001, the output is 1010101. It has puzzled me for two weeks. Here are parts of my code , may someone can give me a hand :)

GPIO configuation :
/*Configure SPI1 pins: PA4<-->NSS, PA5<-->SCK, PA6<-->MISO, PA7<-->MOSI      */
GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;          
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource5, GPIO_AF_0);  
GPIO_PinAFConfig(GPIOA, GPIO_PinSource6, GPIO_AF_0);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource7, GPIO_AF_0);

SPI communication format:
void SPI1S_Configuration(void)
    SPI_InitTypeDef  SPI_InitStructure;
    SPI_StructInit( (SPI_InitTypeDef *)&SPI_InitStructure);
    SPI_InitStructure.SPI_Direction           = SPI_Direction_2Lines_FullDuplex;
    SPI_InitStructure.SPI_Mode                = SPI_Mode_Slave;               
    SPI_InitStructure.SPI_DataSize            = SPI_DataSize_8b;               
    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_4;    
    SPI_InitStructure.SPI_FirstBit            = SPI_FirstBit_MSB;           
    SPI_InitStructure.SPI_CRCPolynomial       = 7;  
    SPI_Init(SPI1, &SPI_InitStructure);
    SPI_NSSInternalSoftwareConfig(SPI1, SPI_NSSInternalSoft_Reset);
    SPI_RxFIFOThresholdConfig(SPI1, SPI_RxFIFOThreshold_QF);
    SPI_CalculateCRC(SPI1, DISABLE);
    SPI_Cmd(SPI1, ENABLE);

SPI1 interrupt deal:
void SPI1_IRQHandler(void)
    if( SPI_I2S_GetITStatus(SPI1, SPI_I2S_IT_TXE) == SET )
        SPI_SendData8(SPI1, spi1_tx_buffer[spi1_tx_count]);
    if(  SPI_I2S_GetITStatus(SPI1, SPI_I2S_IT_RXNE) == SET )   
        spi1_rx_buffer[spi1_rx_count]  = SPI_ReceiveData8(SPI1);