2014-10-18 11:19 AM
Hi,
I want to send ten bits from my STM32F4 Discovery to a SPI slave. The SPI Init struct only allows 8- or 16 bit (SPI_DataSize_8b, SPI_DataSize_16b) Whats the best way to send the required ten bits to the SPI slave? Thanks.2014-10-18 02:26 PM
Send as 40-bits (5 x 8-bit), or bit bang
2014-10-18 11:26 PM
Hi Clive,
Is there a typical SPI bit-banging example available? Thanks.2014-10-21 12:43 PM
Hi,
to send SPI data I use the code below:GPIOE->BSRRH |= GPIO_Pin_13;
received_val=SPI2_send(0x16);
GPIOE->BSRRL |= GPIO_Pin_13;
The problem is the CS (GPIO_Pin_13) already becomes high at the rising edge of the last CLK pulse. I have implemented several checks (code below) to make sure the data has been send before raising the CS signal again.
while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) == RESET);
SPI_I2S_SendData(SPI2, data / 256);
// be sure that the character goes to the shift register
while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) == RESET);
SPI_I2S_SendData(SPI2, data);
// be sure that the character goes to the shift register
while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) == RESET);
// and then be sure it has been sent over the wire
while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_BSY) == SET);
Whats the best solution in order prevent the CS level already going high at the rising edge of the last CLK pulse?
Thanks.