last day (25 days later) » 

6:13 PM
0
A: SPI1 doesn't work

Ashton HeartsThe GPIO pins that you are using for SPI communication should be assigned for the SPI alternate function. For example, the following code will assign Pin5 of PORTA to SPI AF: GPIO_PinAFConfig(GPIOA, GPIO_PinSource5, GPIO_AF_SPI1); The same assignment has to be made for all the SPI pins that you...

 
Roh
I couldn't find such function in HAL library of both MCU. note that the HAL lib of MCUs isn't the same (Cortex-M series of STM32). then your answer is incorrect.
 
What library are you referring to? Are you using library from ST? I've just checked STM32F0 Standard Peripheral Library from ST and it does contain function GPIO_PinAFConfig.
 
Roh
In fact, I use STM32CubeMX (it's a free program from the ST for configure your MCUs) and it uses the STM32Cube_FW_F0_V1.0.0 that content the HAL library V1.0.1 from ST for itself. I checked the GPIO header and source file for find this API but I couldn't find. totally I doubt that it need to that function that you mentioned. Also I found that API in STM32F0xx_StdPeriph_Lib_V1.3.1
 
If you don't configure GPIO pins properly, your SPI will not function at all, unless it is somehow taken care of by HAL. You can refer to the datasheet page 27 of your uC for more details. For the function I've mentioned take a look here. I am aware of CubeMX but never worked with it. As far as I know it uses the same StdPeriphLibrary from ST.
By the way, ST has lots of SPI examples and you can have a look at the source code and GPIO initialization routine.
 
Roh
I wrote a program for UART and there wasn't any API like that and that works nicely. I think the HAL lib automaticaly configur the GPIOs...
 
6:15 PM
Which SPI pins are you using? Your function MX_GPIO_Init() is missing any gpio configurations for spi
 
Roh
@AshtonHearts PA4-7
There is a function, look:
__weak void HAL_SPI_MspInit(SPI_HandleTypeDef *hspi)
{
/* NOTE : This function Should not be modified, when the callback is needed,
the HAL_SPI_MspInit could be implenetd in the user file
*/
}
 
Ok, after you've generated source code in Cube, what files do you have inc Src folder?
 
Roh
main.c and stm32f0xx_hal_msp.c and stm32f0xx_it.c
 
Can you upload stm32f0xx_hal_msp.c?
 
Roh
in stm32f0xx_hal_msp.c you can see this:
/**
******************************************************************************
* File Name : stm32f0xx_hal_msp.c
* Date : 01/01/2002 04:57:48
* Description : This file provides code for the MSP Initialization
* and de-Initialization codes.
******************************************************************************
*
* COPYRIGHT(c) 2002 STMicroelectronics
*
* Redistribution and use in source and binary forms, with or without modification,
 
6:31 PM
Ok, we have a function HAL_SPI_MspInit() which does actually take care of gpio configurations for spi (as well as setting gpi alternate function)
But I don't see HAL_SPI_MspInit() called anywhere in your main.c
By the way, where is HAL_Init() defined?
 
Roh
Do you want to upload my project for you?
completly in zip file
?
 
Ok, I'll take a look
 
Roh
@AshtonHearts Wait to uplaod it...
 
Roh
6:50 PM
sorry for delay...
Now, In Iran, the time is 11:16pm
then I'm going to bed
bay untill tomorrow
 
Ok. Try adding the following line:
HAL_SPI_MspInit(&hspi1);
at the end of void MX_SPI1_Init(void) in main.c
No, it's not the problem. I guess the problem is most likely with your interrupt routine.
You have a function void EXTI0_1_IRQHandler(void) where you transmit your data. But it handles external interrupts, not internal. Do you have the source for the external interrupts connected to your board?
Here's what you have to check: try sending the data in your program's main loop instead of the interrupts and see if it works.
See you tomorrow
 

  last day (25 days later) »