2017-03-06 06:31 AM
Hi,
I have a macronix serial flash(MX66L1G45G) interfaced to my stm32f436 via spi4. hardware connections are correct.Initialization functions are as follows.
int DRV_SPI_Init(void)
{ hspi.Instance = SPI4; hspi.Init.Mode = SPI_MODE_MASTER; hspi.Init.Direction = SPI_DIRECTION_2LINES; hspi.Init.DataSize = SPI_DATASIZE_8BIT; hspi.Init.CLKPolarity = SPI_POLARITY_HIGH; hspi.Init.CLKPhase = SPI_PHASE_2EDGE; hspi.Init.NSS = SPI_NSS_SOFT; //hspi.Init.NSS = SPI_NSS_HARD_OUTPUT ; hspi.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_4; hspi.Init.FirstBit = SPI_FIRSTBIT_MSB; hspi.Init.TIMode = SPI_TIMODE_DISABLED; hspi.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLED;if(HAL_SPI_Init(&hspi) != HAL_OK)
{ retVal = -1; } return 0;}void HAL_SPI_MspInit(SPI_HandleTypeDef *hspi)
{ /* Variable declaration */ GPIO_InitTypeDef GPIO_InitStruct; if(hspi->Instance==SPI4) { /* Peripheral clock enable */ __SPI4_CLK_ENABLE(); __GPIOE_CLK_ENABLE();/**SPI4 GPIO Configuration
PE11 ------> SPI4_NSS PE12 ------> SPI4_SCK PE13 ------> SPI4_MISO PE14 ------> SPI4_MOSI */ GPIO_InitStruct.Pin = GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; //? GPIO_InitStruct.Pull = GPIO_NOPULL; //? GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; //? GPIO_InitStruct.Alternate = GPIO_AF5_SPI4; HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);GPIO_InitStruct.Pin = GPIO_PIN_11;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);/* Peripheral interrupt init*/
HAL_NVIC_SetPriority(SPI4_IRQn, 0, 0); HAL_NVIC_EnableIRQ(SPI4_IRQn); }}When I write some thing i always get HAL_OK in return and when I try to read to confirm I always get 0 back in the reciving buffer with HAL_OK.For example i am trying to read EAR register
//put nss low
HAL_GPIO_WritePin(GPIOE, GPIO_PIN_11, GPIO_PIN_RESET);//read
hStatus = HAL_SPI_TransmitReceive(&(hspi), txData, txData, 3, 4); //static uint8_t txData[3] = {0xC8, 0xFF, 0xFF}; cmd followed by two dummy bytes//wait xmission complete
while( hspi.State == HAL_SPI_STATE_BUSY );//put nss high
HAL_GPIO_WritePin( GPIOE , GPIO_PIN_11 , GPIO_PIN_SET );Can anybody point out any reason of not working, or any recommendation.
Thankyou !
#serial-flash #stm32f439 #spi2017-03-06 08:30 AM
Use an oscilloscope to see what is going on the bus.
Also use different buffer for TX and RX to be sure.
2017-03-07 06:48 AM
thankyou for the reply. Due to form factor its impossible to access pins directly and use oscilloscope. Is it possible to use uvision's logic analyzer or something similar ?
2017-03-07 07:31 AM
If you'd like to probe with oscilloscope, the finest wire usually can by scratching the resist
On the solder iron put a solder drop on both side of the cut wire
Poke the solder drop with the end of the wire to remove the coating
Solder the wire on PCB or package pin. Then you can probe.
Don't use logic analyser. Oscilloscope is the prime tool to make sure the signals looks good, including the slew rate.
When it works on the scope, then the logic analyser is no longer needed...