cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4Cube HAL_SPI_TransmitReceive_IT()

marsenault
Associate II
Posted on June 19, 2014 at 21:42

Hello,

I am interfacing an STM32F407 (on DISCOVERY eval) to several devices using SPI bus.  One of the devices clocks 4 bytes of data out simultaneously as 4 bytes of config data is clocked in (LTC2446 ADC).  I am attempting to use the HAL driver routine HAL_SPI_TransmitReceive_IT() to perform this transfer. I am finding that I only get 3 bytes and then the SPI hangs in a busy state.  Has anyone used this driver and could perhaps tell if there is a limitation or different approach? I could bit-bang the SPI to the ADC, however, I have successfully interfaced to another SPI temperature sensor and don't have run-time to deinitialize the SPI driver, use GPIO for the ADC, then reinitialize SPI for the temperature sensor.
5 REPLIES 5
joe
Associate II
Posted on June 20, 2014 at 11:13

Check this post, it may be a related issue.

[DEAD LINK /public/STe2ecommunities/mcu/Lists/STM32Java/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/STM32Java/STM32F4xx%20HAL_TIM_IRQHandler%20misses%20interrupts%20on%20nearly%20overlapping%20TIM%20interrupts&FolderCTID=0x01200200770978C69A1141439FE559EB459D758000F9A0E3A95BA69146A17C2E80209ADC21&currentviews=90]https://my.st.com/public/STe2ecommunities/mcu/Lists/STM32Java/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/STM32Java/STM32F4xx%20HAL_TIM_IRQHandler%20misses%20interrupts%20on%20nearly%20overlapping%20TIM%20interrupts&FolderCTID=0x01200200770978C69A1141439FE559EB459D758000F9A0E3A95BA69146A17C2E80209ADC21¤tviews=90

See: Note to any STM32CubeF4 developers: The __HAL_TIM_CLEAR_IT( ) macro is incorrect!

marsenault
Associate II
Posted on June 20, 2014 at 15:53

Ok, so what is the correct way to clear a specific bit in the CR2? The referenced post recommended CR2 = ~MASK, however, if the MASK was TXEIE, ~MASK would set CR2 bits that may not have been already set.

joe
Associate II
Posted on June 22, 2014 at 06:58

The link refers to clearing bits in the SR register. The bits in the SR are set by hardware and cleared by writing 0, writing 1 won't affect them so writing SR = ~MASK will clear relevant bits and not affect others ( bits are 'rc_w0', ie can be read and cleared by writing 0 ).

If it's CR2 your trying to clear then CR2 &= ~MASK will be ok. ( bits are 'rw' )

Not sure if any of this is related to your original issue but worth checking it out.

Posted on June 23, 2014 at 12:52

Hi,

Since your are developing an application to interface the STM32F407 to several devices using SPI bus, it seems that the previous transfer is not properly finished. Thus, an overrun is may be detected when starting the HAL_SPI_TransmitReceive_IT() process. In this case, the first but is not received.

Please try to clear the overrun flag using the macro: __HAL_SPI_CLEAR_OVRFLAG() before starting the process.

With regards.

marsenault
Associate II
Posted on June 23, 2014 at 17:47

Hi,

I tried your suggestion, __HAL_SPI_CLEAR_OVRFLAG(&hspi1), with no better results. 

Am I correct in understanding HAL_SPI_TransmitReceive_IT( ) routine that it is capable of full-duplex reading the received data whilst simultaneously transmitting the same number of bytes?

Thanks in advance for your help,

Mark