cancel
Showing results for 
Search instead for 
Did you mean: 

Low-Level SPI Transmit

Steven Keeter
Associate III

Hello, I am using the stm32H745 device (on DISCO bd.), and am using the HAL driver to transmit and receive spi2 data without problems. However, as many people have complained on-line the HAL overhead delay to send the byte is too long.

   // Send Convert for Temp Signal

   txbyte[0] = 0x48;

   HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, GPIO_PIN_RESET);

// This section doesn't seem to work in hope to replace the HAL transmit below   

//   SPI2->CR1 = 0x1201;

//   SPI2->CR2 = 0x1;

//   while(!(SPI2->SR & SPI_SR_TXP));

//   *(volatile uint8_t *)&CEC->TXDR = txbyte[0];    

    

   // This works fine 

   HAL_SPI_Transmit(&hspi2, (uint8_t *)&txbyte,1,10); 

I'm basically setup as a master, single byte transfers. Can anyone help?

BTW, here's the init structure:

 hspi2.Instance = SPI2;

 hspi2.Init.Mode = SPI_MODE_MASTER;

 hspi2.Init.Direction = SPI_DIRECTION_2LINES;

 hspi2.Init.DataSize = SPI_DATASIZE_8BIT;

 hspi2.Init.CLKPolarity = SPI_POLARITY_LOW;

 hspi2.Init.CLKPhase = SPI_PHASE_1EDGE;

 hspi2.Init.NSS = SPI_NSS_SOFT;

 hspi2.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8;

 hspi2.Init.FirstBit = SPI_FIRSTBIT_MSB;

 hspi2.Init.TIMode = SPI_TIMODE_DISABLE;

 hspi2.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;

 hspi2.Init.CRCPolynomial = 0x0;

 hspi2.Init.NSSPMode = SPI_NSS_PULSE_DISABLE;

 hspi2.Init.NSSPolarity = SPI_NSS_POLARITY_LOW;

 hspi2.Init.FifoThreshold = SPI_FIFO_THRESHOLD_01DATA;

 hspi2.Init.TxCRCInitializationPattern = SPI_CRC_INITIALIZATION_ALL_ZERO_PATTERN;

 hspi2.Init.RxCRCInitializationPattern = SPI_CRC_INITIALIZATION_ALL_ZERO_PATTERN;

 hspi2.Init.MasterSSIdleness = SPI_MASTER_SS_IDLENESS_00CYCLE;

 hspi2.Init.MasterInterDataIdleness = SPI_MASTER_INTERDATA_IDLENESS_00CYCLE;

 hspi2.Init.MasterReceiverAutoSusp = SPI_MASTER_RX_AUTOSUSP_DISABLE;

 hspi2.Init.MasterKeepIOState = SPI_MASTER_KEEP_IO_STATE_DISABLE;

 hspi2.Init.IOSwap = SPI_IO_SWAP_DISABLE;

 if (HAL_SPI_Init(&hspi2) != HAL_OK)

 {

  Error_Handler();

 }

11 REPLIES 11
Steven Keeter
Associate III

BTW, I have the SPI1(master) CLK and MISO tied to SPI2(slave) CLK and MOSI inputs respectively.

Steven Keeter
Associate III

For some reason I am getting HAL_DMA_ERROR_TE flag during the interrupt

void DMA1_Stream0_IRQHandler(void)

{

 /* USER CODE BEGIN DMA1_Stream0_IRQn 0 */

 /* USER CODE END DMA1_Stream0_IRQn 0 */

 HAL_DMA_IRQHandler(&hdma_spi2_rx);

 /* USER CODE BEGIN DMA1_Stream0_IRQn 1 */

 /* USER CODE END DMA1_Stream0_IRQn 1 */

}