cancel
Showing results for 
Search instead for 
Did you mean: 

SPI Transmitting on NUCLEO32-l432kc

Ond?ej Bure¨
Associate II
Posted on December 11, 2017 at 14:21

Hello dear STM32.

I have problem with SPI communicatoin on my nucleo32 board with STM32 l432kc. Already 2 days, I am trying to make SPI communicatin work, but without any result. When I was measuring with my Osciloscope, I saw something just on MOSI. On SCK there was no signal. I need just transmit some data on my display (I am trying to communicate with display dogs102-6 ->

http://www.lcd-module.com/eng/pdf/grafik/dogs102-6e.pdf

). But wit osciloscope

Can anyone help me please ?

:(

Thanks for any help .

Here is my code:

int main(void)

{

  /* USER CODE BEGIN 1 */

  /* USER CODE END 1 */

  /* MCU Configuration----------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */

  HAL_Init();

  /* USER CODE BEGIN Init */

  /* USER CODE END Init */

  /* Configure the system clock */

  SystemClock_Config();

  /* USER CODE BEGIN SysInit */

  /* USER CODE END SysInit */

  /* Initialize all configured peripherals */

  MX_GPIO_Init();

  MX_I2C1_SMBUS_Init();

  MX_SPI1_Init();

  MX_USART2_UART_Init();

  /* USER CODE BEGIN 2 */

  initDisplay();

  /* USER CODE END 2 */

  /* Infinite loop */

  /* USER CODE BEGIN WHILE */

  while (1)

  {

  /* USER CODE END WHILE */

  initDisplay();

  /* USER CODE BEGIN 3 */

  }

  /* USER CODE END 3 */

}

/* SPI1 init function */

static void MX_SPI1_Init(void)

{

__HAL_RCC_SPI1_CLK_ENABLE();

  hspi1.Instance = SPI1;

  hspi1.Init.Mode = SPI_MODE_MASTER;

  hspi1.Init.Direction = SPI_DIRECTION_2LINES;

  hspi1.Init.DataSize = SPI_DATASIZE_8BIT ;

  hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;

  hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;

  hspi1.Init.NSS = SPI_NSS_SOFT;

  hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_256;

  hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;

  hspi1.Init.TIMode = SPI_TIMODE_DISABLE;

  hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;

  hspi1.Init.CRCPolynomial = 7;

  hspi1.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;

  hspi1.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;

//-------------------------------------------------------------------------------------------------

/* USER CODE BEGIN 4 */

void initDisplay(){

/*

uint32_t CD = GPIO_PIN_8;

uint32_t RST = GPIO_PIN_9;

uint32_t CS0 = GPIO_PIN_10;

uint32_t LCDBacklight = GPIO_PIN_11;

*/

  uint8_t configData[13] = {0x40, 0xA1, 0xC0, 0xA4, 0xA6, 0xA2, 0x2F, 0x27, 0x81, 0x10, 0xFA, 0x90, 0xAF};

  uint8_t data[1] = {0b11111111};

  __HAL_RCC_SPI1_CLK_ENABLE();

  HAL_Delay(100);

  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET);

  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_9, GPIO_PIN_RESET);

  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, GPIO_PIN_RESET);

  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_11, GPIO_PIN_SET);

  HAL_Delay(100);

  HAL_SPI_Transmit(&hspi1, configData, 13, 500);

  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET);

  HAL_Delay(100);

  HAL_SPI_Transmit(&hspi1, data, 1,500);

  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET);

}

#clk-spi-problem #spi #spi_transmit #hal_spi_transmit
3 REPLIES 3
Posted on December 12, 2017 at 07:57

Check that there are no conflicts with connections on the board (Nucleo boards are relatively sparse but it never hurts to check).

Read out and check/post the content of relevant SPI and GPIO registers.

JW

Posted on December 12, 2017 at 10:24

Thank you very much for your reply !!

I checked the connection and tried to change SCK (In cubeMX ).

Can I ask, what should be the frequency of SCK. Becouse I have Osciloscope that can measure set frequency without problem(

http://www.hantek.com/en/ProductDetail_123

)

  hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_256

That is wierd, becouse I remember that, when I was setting up the frequency, it was in kHz.

BUT, when i connected diode between GND and new SCK, that diode blinked for a moment, when data was transfering. So I think, SCK is just on some realy high frequency, that ma Scope can not measure. But my scope has bandwidth 100 Mhz. So I think that is wierd.

Thanks for any help

Posted on December 12, 2017 at 10:55

Read out and check/post the content of relevant SPI and GPIO registers.