cancel
Showing results for 
Search instead for 
Did you mean: 

Hal spi wait ?

antonius
Senior
Posted on December 22, 2015 at 07:16

Hal spi wait ?

9 REPLIES 9
Nesrine M_O
Lead II
Posted on December 22, 2015 at 09:18

Hi  h.rick,

Could you please provide more explanation on your case, so that it will be easier to understand the issue and may bring you some help?

-Syrine-

antonius
Senior
Posted on December 22, 2015 at 15:19

I want to migrate this function to HAL_SPI...

How can I make SPIwait on HAL_SPI ? Thanks

Mp3SelectData();
00180 SPIPutCharWithoutWaiting(0);
00181 for (temp.i=0; temp.i<1048; temp.i++){ /* TESTING 1048 TESTING */
00182 while (!MP3_DREQ)
00183 ;
00184 SPIPutChar(0);
00185 }
00186 SPIWait();
00187 Mp3DeselectData();
00188 }

antonius
Senior
Posted on December 22, 2015 at 15:30

On STM32F107...this register :

23.5.3 SPI status register (SPI_SR), page 617 reference manual....

bit 0 and bit 1, how can I check it ?

Bit 1 TXE: Transmit buffer empty

0: Tx buffer not empty

1: Tx buffer empty

Bit 0 RXNE: Receive buffer not empty

0: Rx buffer empty

1: Rx buffer not empty

How can I check SPI status on HAL_SPI stm32cubeMX ?

Similar like this one from AT89C51

#define SPIWait(){while(!(SPSTA & 0x80));;}

antonius
Senior
Posted on December 22, 2015 at 15:57

How can I make this on HAL_SPI ?

while (!(SPI->SR & SPI_SR_TXE)); // Wait while receive buffer is not empty
SPI->DR = data; // Send byte to SPI
while (!(SPI->SR & SPI_SR_RXNE)); // Wait while receive buffer is empty

Posted on December 22, 2015 at 16:57

Wouldn't the register level access remain pretty much identical?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
antonius
Senior
Posted on December 22, 2015 at 22:51

How can I acces register SPI_SR and bit

SPI_SR_TXE

on STMCubeMx... Thanks
antonius
Senior
Posted on December 22, 2015 at 23:02

is it this one ? I've found it at stm32fxx_hal_spi.c

How can I use it ??

/**

  * @brief  This function handles SPI Communication Timeout.

  * @param  hspi: pointer to a SPI_HandleTypeDef structure that contains

  *                the configuration information for SPI module.

  * @param  Flag: SPI flag to check

  * @param  Status: Flag status to check: RESET or set

  * @param  Timeout: Timeout duration

  * @retval HAL status

  */

static HAL_StatusTypeDef SPI_WaitOnFlagUntilTimeout(SPI_HandleTypeDef *hspi, uint32_t Flag, FlagStatus Status, uint32_t Timeout)

Probably

SPI_WaitOnFlagUntilTimeout(&hspi1, SPI_SR, RESET, 1000); 

???

I got :

error:  #20: identifier ''SPI_SR'' is undefined

How can I define SPI_SR on STM32CubeMx ?

Thanks

antonius
Senior
Posted on December 23, 2015 at 06:09

Please correct me if I'm wrong....

#define SPI_Transmit_Wait() {while (__HAL_SPI_GET_FLAG(&hspi1, SPI_FLAG_TXE) = RESET); } //while TX not empty
#define SPI_Receive_Wait() {while (__HAL_SPI_GET_FLAG(&hspi1, SPI_FLAG_RXNE) = RESET); } //while RX not empty

Thanks
matic
Associate III
Posted on December 23, 2015 at 06:39

Regardless of using HAL or SPL, you can use your previous approach. Registers are same.

Maybe only definition of TXE bit (SPI_SR_TXE) and RXNE bit are not exactly the same, but I am almost sure they are.

while (!(SPI->SR & SPI_SR_TXE)); // Wait while receive buffer is not empty
SPI->DR = data; // Send byte to SPI
while (!(SPI->SR & SPI_SR_RXNE)); // Wait while receive buffer is empty