I am trying to configure SPI2 in my primer2 to connect with TLX905 radio module, but without any results;/ I am using GPIO_Pin_4 for SPI_NSS.
The problem is that, my program is stopping into this loop:
Code:
while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_RXNE) == RESET);
I don't know what I configured wrong. I checked TLX905 with AVR and there everything works fine: I'm sending byte (0x15) to TLX905, and I'm getting 5 bytes of data.
I have read, that I should disable microphone when I want to use SPI2, but I dont know how to do that.
I think the mistake is SPI2_NSS that is connected to PB12 and not PC4. Secondly, with SPI bus, you must send dummy data during receiving, in order to maintain the SPI clock running. In your code, the clock will stop after the send of the 0x15 value.
You should use this type of function :
Code:
u8 SendByte( u8 byte )
{
/* Loop while DR register in not empty */
while ( SPI_I2S_GetFlagStatus( SPIX, SPI_I2S_FLAG_TXE ) == RESET );
/* Send byte through the SPIx peripheral */
SPI_I2S_SendData( SPIX, byte );
/* Wait to receive a byte */
while ( SPI_I2S_GetFlagStatus( SPIX, SPI_I2S_FLAG_RXNE ) == RESET );
/* Return the byte read from the SPI bus */
return SPI_I2S_ReceiveData( SPIX );
}
I also suggest that you call first the "SPI_I2S_DeInit" function in order to stop the I2S2 used by the CircleOS audio handler.
At last, I don't understand the usefulness of the "NVIC_Configuration" function, because the vector table is already configured during the init of the CircleOS.