cancel
Showing results for 
Search instead for 
Did you mean: 

HAL SPI STM32F429 DISCO problem

arkadiuszkoziel93
Associate
Posted on September 01, 2015 at 12:16

Hello, i have following code generated from STM32CubeMx.

Transmit function returns HAL_OK status but under scope clock line stay always low. I have tried several codes to run this bus but always nothing. What im doing wrong? I guess something is missing.


#include ''stm32f4xx_hal.h''

#include ''stm32f4xx_hal_spi.h''


#include ''FreeRTOS.h''

#include ''task.h''

#include ''timers.h''


#include <stdio.h>

#include <string.h>


void
IO_Init( 
void
);

void
vTimerCallback (TimerHandle_t pxTimer);

void
MX_SPI3_Init(
void
);


TimerHandle_t Timer;

SPI_HandleTypeDef hspi3;


int
a = 1000;


int
main (
void
) {


HAL_Init();

IO_Init();

MX_SPI3_Init();


HAL_GPIO_WritePin(GPIOG, GPIO_PIN_14, GPIO_PIN_RESET); 
// led low

HAL_GPIO_WritePin(GPIOG, GPIO_PIN_13, GPIO_PIN_SET); 
// cs high


HAL_GPIO_WritePin(GPIOG, GPIO_PIN_13, GPIO_PIN_RESET); 
// cs low


HAL_SPI_Transmit(&hspi3, (uint8_t*)64, 1, 0xFFFF); 
// transmit device address

HAL_SPI_Transmit(&hspi3, (uint8_t*)0, 1, 0xFFFF); 
// transmit register address

HAL_SPI_Transmit(&hspi3, (uint8_t*)0, 1, 0xFFFF); 
// treanmit value


HAL_GPIO_WritePin(GPIOG, GPIO_PIN_13, GPIO_PIN_SET); 
// cs high


Timer = xTimerCreate(
''Timer''
, a / portTICK_PERIOD_MS, pdTRUE, (
void
*) 12, vTimerCallback);

xTimerStart(Timer, 0);


vTaskStartScheduler();


return
0;

}


void
vTimerCallback( TimerHandle_t pxTimer )

{

HAL_GPIO_TogglePin(GPIOG, GPIO_PIN_14); 
// toggle


// start


HAL_GPIO_WritePin(GPIOG, GPIO_PIN_13, GPIO_PIN_RESET); 
//CS low


HAL_SPI_Transmit(&hspi3, (uint8_t*)0, 1, 0xFFFF); 
// transmit device address

HAL_SPI_Transmit(&hspi3, (uint8_t*)0x12, 1, 0xFFFF); 
// transmit register address

HAL_SPI_Transmit(&hspi3, (uint8_t*)1, 1, 0xFFFF); 
// treanmit value


HAL_GPIO_WritePin(GPIOG, GPIO_PIN_13, GPIO_PIN_SET); 
//CS high

}


void
MX_SPI3_Init(
void
)

{

__SPI3_CLK_ENABLE();


hspi3.Instance = SPI3;

hspi3.Init.Mode = SPI_MODE_MASTER;

hspi3.Init.Direction = SPI_DIRECTION_2LINES;

hspi3.Init.DataSize = SPI_DATASIZE_8BIT;

hspi3.Init.CLKPolarity = SPI_POLARITY_LOW;

hspi3.Init.CLKPhase = SPI_PHASE_1EDGE;

hspi3.Init.NSS = SPI_NSS_SOFT;

hspi3.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;

hspi3.Init.FirstBit = SPI_FIRSTBIT_MSB;

hspi3.Init.TIMode = SPI_TIMODE_DISABLED;

hspi3.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLED;

hspi3.Init.CRCPolynomial = 10;

HAL_SPI_Init(&hspi3);


}


void
IO_Init( 
void
){


GPIO_InitTypeDef GPIO_InitStruct;


__GPIOG_CLK_ENABLE();


GPIO_InitStruct.Pin = GPIO_PIN_14 | GPIO_PIN_13; 
// led and cs

GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; 
// push-pull output

GPIO_InitStruct.Pull = GPIO_PULLDOWN; 
// pull-down enabled

GPIO_InitStruct.Speed = GPIO_SPEED_LOW; 
// analog pin bandwidth limited

HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);

}

#discovery #spi #stm32f429
1 REPLY 1
Amel NASRI
ST Employee
Posted on September 10, 2015 at 18:43

Hi koziel.arkadiusz,

What is about the SPI3 pins? Are they correctly configured? 

There should be a call for ''MX_GPIO_Init'' function generated in stm32f4xx_hal_msp.c file.

-Mayla-

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.