2020-02-07 12:51 AM
Hi,
I'm working with B-L072Z-LRWAN1 platform and struggle to see a signal on SPI2.
My SPI2 is connected on an accelerometer. It is configured as follow:
void HW_IMU_SPI_Init( void )
{
/*##-1- Configure the SPI peripheral */
/* Set the SPI parameters */
hspi2.Instance = SPI2;
hspi2.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;
hspi2.Init.Direction = SPI_DIRECTION_2LINES;
hspi2.Init.Mode = SPI_MODE_MASTER;
hspi2.Init.CLKPolarity = SPI_POLARITY_LOW;
hspi2.Init.CLKPhase = SPI_PHASE_1EDGE;
hspi2.Init.DataSize = SPI_DATASIZE_8BIT;
hspi2.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
hspi2.Init.FirstBit = SPI_FIRSTBIT_MSB;
hspi2.Init.NSS = SPI_NSS_SOFT;
hspi2.Init.TIMode = SPI_TIMODE_DISABLE;
IMU_SPI_CLK_ENABLE();
if(HAL_SPI_Init( &hspi2) != HAL_OK)
{
/* Initialization Error */
Error_Handler();
}
/*##-2- Configure the SPI GPIOs */
HW_IMU_SPI_IoInit( );
}
void HW_IMU_SPI_IoInit( void )
{
GPIO_InitTypeDef initStruct={0};
IMU_GPIO_CLK_ENABLE();
initStruct.Pin = IMU_SCLK_PIN | IMU_MISO_PIN | IMU_MOSI_PIN;
initStruct.Mode =GPIO_MODE_AF_PP;
initStruct.Pull =GPIO_NOPULL ;
initStruct.Speed = GPIO_SPEED_HIGH;
initStruct.Alternate= IMU_SPI2_AF ;
HAL_GPIO_Init(GPIOB, &initStruct);
initStruct.Mode = GPIO_MODE_OUTPUT_PP;
initStruct.Pull = GPIO_NOPULL;
HW_GPIO_Init( IMU_NSS_PORT, IMU_NSS_PIN, &initStruct );
HW_GPIO_Write ( IMU_NSS_PORT, IMU_NSS_PIN, 1 );
}
Systemclock is configured as follow:
void SystemClock_Config(void)
{
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
/* Enable HSE Oscillator and Activate PLL with HSE as source */
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
RCC_OscInitStruct.HSEState = RCC_HSE_OFF;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLLMUL_6;
RCC_OscInitStruct.PLL.PLLDIV = RCC_PLLDIV_3;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
/* Set Voltage scale1 as MCU will run at 32MHz */
__HAL_RCC_PWR_CLK_ENABLE();
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
/* Poll VOSF bit of in PWR_CSR. Wait until it is reset to 0 */
while (__HAL_PWR_GET_FLAG(PWR_FLAG_VOS) != RESET) {};
/* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2
clocks dividers */
RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK)
{
Error_Handler();
}
}
Chip select is defined as GPIO. I can see it toggling.
I'm not quite sure what I'm missing here. Could anyone help?
2020-02-07 01:39 AM
What pins? Double check AF settings.
2020-02-07 01:43 AM
It is set as Alternate Function AF0 Push-Pull.
MOSI = PB15
MISO = PB14
SCK = PB13
And I set them to very high speed.
2020-02-07 05:03 PM
Check the solder bridges, especially those relating to PB13 SB2/D13 and SB9/D3
2020-02-09 10:15 PM
The resistors are populated