AnsweredAssumed Answered

SPI Transmitting on NUCLEO32-l432kc

Question asked by Ondřej Bureš on Dec 11, 2017
Latest reply on Dec 12, 2017 by waclawek.jan

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);
}

Outcomes