AnsweredAssumed Answered

STM32f302cc SPI code assistance needed

Question asked by conrad c on Mar 25, 2018
Latest reply on Apr 8, 2018 by conrad c

Hi,

 

I have recently move from the STM32f101 to the stm32f302, I am using atollic IDE and the Hal library for the initial configuration of the peripherals.  I use register level setup for a lower overhead. having said this, I am having major issues accessing the a SPI eeprom with code that used to work beautifully. I know the register and architecture is different i have gone over the manual quite a few times. I have adjusted the registers to match but the interface still does not want to read the eeprom correctly. Hw is the same as with the old board . The only difference is the software and the MCU.

 

Attached is the eeprom.c which has a function called spi_ee_clear(), this functions tests both reading and writing of the eeprom. it works fie with the stm32f101 but the eeprom fails with the stm32f302

 

Below is my Hal config and the n my register level SPI config , please can someone have a look and let me know what i am missing?

 

HAL setup:

 

/* SPI1 init function */
static void MX_SPI1_Init(void)
{


/* SPI1 parameter configuration*/
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_64;
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;
if (HAL_SPI_Init(&hspi1) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}

__HAL_SPI_ENABLE(&hspi1);

}

 

 

 

Register config: (repeating hal on a register level)

 

void spi1_config0(void)//8bit
{
//1MHz

 RCC->APB2ENR |= RCC_APB2ENR_SPI1EN;
 SPI1->CR1 = 0x0000;//first disable SPI
 SPI1->CR2 = 0x0000;
SPI1->CR1 = 0x0024;//8bit 1mhz cpha=0 cpol=0
 SPI1->CR1 |= 0x0300;// enable soft_NSS
 SPI1->CR2 =0x1700;
SPI1->CR1 |= 0x0040;


}

Attachments

Outcomes