AnsweredAssumed Answered

Change Mode of Pin

Question asked by Se Jasmine on Nov 14, 2017
Latest reply on Nov 15, 2017 by waclawek.jan

Hey,

i have a STMF070CB microcontroller and use one pin for exti and spi-miso.

The pin is configured as EXTI as follows:

 

GPIO_InitStruct.Pin = GPIO_PIN_6;
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_6, GPIO_PIN_SET);

 

/* EXTI interrupt init*/
HAL_NVIC_SetPriority(EXTI4_15_IRQn, 0, 3);
HAL_NVIC_EnableIRQ(EXTI4_15_IRQn);

SPI is configured as follows:

static void MX_SPI1_Init(void)
{

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_2EDGE;
hspi1.Init.NSS = SPI_NSS_SOFT;
hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_32; //APB:48MHz -> Prescaler 16 -> 3MHz (nearest possible above 2MHz) should be 16, but 32 took since didn't work properly on nucleo
hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
hspi1.Init.CRCPolynomial = 10;
hspi1.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;
hspi1.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;
if (HAL_SPI_Init(&hspi1) != HAL_OK)
{
Error_Handler();
}
}

In stm32f0xx_it.c there are the lines

void EXTI4_15_IRQHandler(void){
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_6);
}

which just yield towards a counter in the main file.

 

At first it works just as MISO. Then i use it for a while just as EXTI. When i then want to use it for SPI again i always get with HAL_SPI_TransmitReceive 0x00 for receive even when on the line 0xFF would be. The rest is working fine.

 

Why does that happen? And have you any ideas how i can avoid this?

 

Cheers

Outcomes