AnsweredAssumed Answered

HAL SPI STM32F429 DISCO problem

Question asked by koziel.arkadiusz on Sep 1, 2015
Latest reply on Sep 10, 2015 by Amel N
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.
01.#include "stm32f4xx_hal.h"
02.#include "stm32f4xx_hal_spi.h"
03.  
04.#include "FreeRTOS.h"
05.#include "task.h"
06.#include "timers.h"
07.  
08.#include <stdio.h>
09.#include <string.h>
10.  
11.void IO_Init( void );
12.void vTimerCallback (TimerHandle_t pxTimer);
13.void MX_SPI3_Init(void);
14.  
15.TimerHandle_t Timer;
16.SPI_HandleTypeDef hspi3;
17.  
18.int a = 1000;
19.  
20.int main (void) {
21.        
22.        HAL_Init();
23.        IO_Init();
24.        MX_SPI3_Init();
25.        
26.        HAL_GPIO_WritePin(GPIOG, GPIO_PIN_14, GPIO_PIN_RESET);                  // led low
27.        HAL_GPIO_WritePin(GPIOG, GPIO_PIN_13, GPIO_PIN_SET);                            // cs high
28.        
29.        HAL_GPIO_WritePin(GPIOG, GPIO_PIN_13, GPIO_PIN_RESET);                  // cs low
30.  
31.        HAL_SPI_Transmit(&hspi3, (uint8_t*)64, 1, 0xFFFF);                                      // transmit device address
32.        HAL_SPI_Transmit(&hspi3, (uint8_t*)0, 1, 0xFFFF);                                               // transmit register address
33.        HAL_SPI_Transmit(&hspi3, (uint8_t*)0, 1, 0xFFFF);                                               // treanmit value
34.  
35.        HAL_GPIO_WritePin(GPIOG, GPIO_PIN_13, GPIO_PIN_SET);                            // cs high
36.        
37.        Timer = xTimerCreate("Timer",  a / portTICK_PERIOD_MS, pdTRUE, (void *) 12, vTimerCallback);
38.        xTimerStart(Timer, 0);
39.        
40.        vTaskStartScheduler();
41.  
42.        return 0;
43.}
44.  
45.void vTimerCallback( TimerHandle_t pxTimer )
46.{
47.                HAL_GPIO_TogglePin(GPIOG, GPIO_PIN_14);                                                                                                 // toggle
48.        
49.                // start
50.  
51.                HAL_GPIO_WritePin(GPIOG, GPIO_PIN_13, GPIO_PIN_RESET);                                  //CS low
52.  
53.                HAL_SPI_Transmit(&hspi3, (uint8_t*)0, 1, 0xFFFF);                                                               // transmit device address
54.                HAL_SPI_Transmit(&hspi3, (uint8_t*)0x12, 1, 0xFFFF);                                            // transmit register address
55.                HAL_SPI_Transmit(&hspi3, (uint8_t*)1, 1, 0xFFFF);                                                               // treanmit value
56.                
57.                HAL_GPIO_WritePin(GPIOG, GPIO_PIN_13, GPIO_PIN_SET);                                            //CS high
58.}
59.  
60.void MX_SPI3_Init(void)
61.{
62.        __SPI3_CLK_ENABLE();
63.        
64.  hspi3.Instance = SPI3;
65.  hspi3.Init.Mode = SPI_MODE_MASTER;
66.  hspi3.Init.Direction = SPI_DIRECTION_2LINES;
67.  hspi3.Init.DataSize = SPI_DATASIZE_8BIT;
68.  hspi3.Init.CLKPolarity = SPI_POLARITY_LOW;
69.  hspi3.Init.CLKPhase = SPI_PHASE_1EDGE;
70.  hspi3.Init.NSS = SPI_NSS_SOFT;
71.  hspi3.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;
72.  hspi3.Init.FirstBit = SPI_FIRSTBIT_MSB;
73.  hspi3.Init.TIMode = SPI_TIMODE_DISABLED;
74.  hspi3.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLED;
75.  hspi3.Init.CRCPolynomial = 10;
76.  HAL_SPI_Init(&hspi3);
77.  
78.}
79.  
80.void IO_Init( void ){
81.        
82.        GPIO_InitTypeDef GPIO_InitStruct;
83.        
84.  __GPIOG_CLK_ENABLE();
85.  
86.  GPIO_InitStruct.Pin   = GPIO_PIN_14 | GPIO_PIN_13;    // led and cs
87.  GPIO_InitStruct.Mode  = GPIO_MODE_OUTPUT_PP;        // push-pull output
88.  GPIO_InitStruct.Pull  = GPIO_PULLDOWN;              // pull-down enabled
89.  GPIO_InitStruct.Speed = GPIO_SPEED_LOW;             // analog pin bandwidth limited
90.  HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);
91.}

Outcomes