cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F746ZG SPI not receiving data, using CubeMX

Matt Jackson
Associate II
Posted on July 19, 2017 at 14:34

Hi there, 

I'm trying to receive data over SPI using the Nucleo-F746ZG. I'm using Cube MX and AC6 Workbench. 

Unfortunately, there are no SPI examples for this board that use the drivers generated by Cube MX (That I can find at least..)

I have SPI1 enabled as a full duplex (Have also tried half duplex).

NSS is set to hardware input.

I have my pins configured like this: 

    

/**SPI1 GPIO Configuration    

    PA4     ------> SPI1_NSS

    PA5     ------> SPI1_SCK

    PA6     ------> SPI1_MISO

    PA7     ------> SPI1_MOSI 

    */

I then used a logic analyser to ensure that all pins are connected properly and receiving data as they should. 

I have triple checked my SPI data/clock config and it's definitely correct.

I have enabled SPI global interrupt in both the SPI config and NVIC config in cube MX.

I then added this function to my main.c, just before the main function. I copied this from the weak declaration in the HAL driver.

void

HAL_SPI_RxCpltCallback(

SPI_HandleTypeDef

*hspi)

  {

      

HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_0);

  }

The green LED on the Nucleo board should toggle every time a byte of data is received on MOSI. It's not happening.

I have also checked the SPI1 data register, and there is never anything in it. 

I would put up more code, but it's all generated by CubeMX, so it should be fine.

Any help would be greatly appreciated - I'm pulling my hair out!!

Thanks, 

Matt

1 ACCEPTED SOLUTION

Accepted Solutions
Posted on July 19, 2017 at 21:13

Hello again!!

You wrote ' now that Ihave HAL_SPI_RxCpItCallback() being called, my program hangs there and it isn't called again.'

this is normal

Every time you want to begin a new 'read' transaction you must call the HAL_SPI_Receive_IT(,,,) or any other suitable function..

So Every time you finish 'read' the data.. you must find a way to put the SPI port to 'read' state again.( not recomended from callback function ofcourse)

The best way to understand the HAL functiomality is to spend a lot of time to read the source code and to read the functionality of of registers in combination with

/external-link.jspa?url=http%3A%2F%2Fwww.st.com%2Fcontent%2Fccc%2Fresource%2Ftechnical%2Fdocument%2Fuser_manual%2F45%2F27%2F9c%2F32%2F76%2F57%2F48%2Fb9%2FDM001897pdf%2Ffiles%2FDM001897pdf%2Fjcr%3Acontent%2Ftranslations%2Fen.DM001897pdf

manual. (this pre includes a good knowledge about Ser Ports)

A good way to start is to analyse the existing examples and to learn from this analysis .. Does not matter if there aren't examples for your board or chip.

You may analyse examples from other 'similar' chips.

View solution in original post

8 REPLIES 8
Posted on July 19, 2017 at 15:52

Hello Mat!!

Don't  pull your hair out!!!

you wrote  'I'm trying to receive data'   As slave or as Master? 

Write more detail about  your hardware configuration..

Matt Jackson
Associate II
Posted on July 19, 2017 at 16:13

Hey Vangelis, 

Thanks for the reply!

The STM32F7 is configured as a full duplex slave.  It is receiving data from a Raspberry Pi 3 configured as master.  I've used this Pi to send SPI data successfully to various other dev boards. 

Here's a pic to give you an idea.   The wires are nice and short, and as I stated above, I've checked that the Nucleo is receiving he SPI data as intended.

0690X00000603wJQAQ.jpg

Here are the connections as it's hard to see from the photo:

NSS / CS = CN7 pin 17 (PA4)

SCK = CN7 pin 10 (PA5)

MISO =  CN7 pin 12 (PA6)

MOSI = CN7 pin 14 (PA7)

Interestingly, there appears to be some sort of inconsistency  between the Nucleo Manual and the CubeMX configurator.

This pin table says that I should use CN7 Pin16 (PD14) as SPI slave select:

  0690X00000607d9QAA.png

However in the configurator, I'm unable to select that option for pin PD14:

0690X00000607dJQAQ.png

Hope that helps you help me!

Matt

Posted on July 19, 2017 at 16:37

Hello again ! 

you wrote before '

I would put up more code, but it's all generated by CubeMX, so it should be fine.

'

Unfortunately its not fine

After your Initialisation function called by main() function , you must initiate the transaction by call  HAL_SPI_Receive_IT(...) function (to use the interrupt and your callback function)

Unfortunately  again I don't have now enough time to give you more explanations because i must leave home (something emergency) .

Posted on July 19, 2017 at 17:05

Ahhhh awesome, thank you!

It is now calling the interrupt. 

Can you please point me towards the documentation for the HAL drivers that might say what function needs to be called and when?  I've not been able to find it anywhere.

Thanks again

Matt

Posted on July 19, 2017 at 18:01

Hi

matt

,

You have this manual

http://www.st.com/content/ccc/resource/technical/document/user_manual/45/27/9c/32/76/57/48/b9/DM001897pdf/files/DM001897pdf/jcr:content/translations/en.DM001897pdf

Description of STM32F7 HAL and Low-layer drivers (in section : 62 HAL SPI Generic Driver)

Regards

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen
Posted on July 19, 2017 at 18:36

Thanks - But that manual actually doesn't give any guidance on how to use the API.  

For example, now that I have HAL_SPI_RxCpItCallback() being called, my program hangs there and it isn't called again.

I presume I need to acknowledge the interrupt or clear a buffer somewhere, but I don't see any information like that in the SPI section of that manual...  I feel like I'm missing a manual somewhere!!

Posted on July 19, 2017 at 21:13

Hello again!!

You wrote ' now that Ihave HAL_SPI_RxCpItCallback() being called, my program hangs there and it isn't called again.'

this is normal

Every time you want to begin a new 'read' transaction you must call the HAL_SPI_Receive_IT(,,,) or any other suitable function..

So Every time you finish 'read' the data.. you must find a way to put the SPI port to 'read' state again.( not recomended from callback function ofcourse)

The best way to understand the HAL functiomality is to spend a lot of time to read the source code and to read the functionality of of registers in combination with

/external-link.jspa?url=http%3A%2F%2Fwww.st.com%2Fcontent%2Fccc%2Fresource%2Ftechnical%2Fdocument%2Fuser_manual%2F45%2F27%2F9c%2F32%2F76%2F57%2F48%2Fb9%2FDM001897pdf%2Ffiles%2FDM001897pdf%2Fjcr%3Acontent%2Ftranslations%2Fen.DM001897pdf

manual. (this pre includes a good knowledge about Ser Ports)

A good way to start is to analyse the existing examples and to learn from this analysis .. Does not matter if there aren't examples for your board or chip.

You may analyse examples from other 'similar' chips.

Posted on July 20, 2017 at 11:28

Ok, great. I have that up and running now. 

Thanks a lot for your quick help, I'll no doubt be back before too long!!

M