Electrical Engineering Asked by IHK on January 30, 2021
I am trying to communicate with IS25LP128F Flash IC via SPI on STM32F407.
Firstly, I tried to send RDID command as you see in the picture.How
to send commands and reading respond of them is explained in datasheet.
I use HAL library. When I checked low layer codes of "HAL_SPI_TransmitReceive or Transmit and Receive", I realized that there is a problem due to the Tx data register. The problem is when hspi2′ pTxBuffPtr is load to hspi->Instance->DR, hspi->Instance->DR is always zero regardless hspi2′ pTxBuffPtr‘ content.
Are there anyone to had this problem before ?
Ty.
Here is my code.
`void IS25LP128F_ReadID()
{
spiData[0]=RDID;
spiData[1]=DUMMY;
spiData[2]=DUMMY;
spiData[3]=DUMMY;
StartSPI();
HAL_SPI_Transmit(&hspi2, spiData,4, 100);
HAL_SPI_Receive(&hspi2, spiData,1, 100);
StopSPI();
IS25LP128F.ID=spiData[0];
}`
Here is low layer code block of HAL_SPI_Transmit function.
while (hspi->TxXferCount > 0U)
{
/* Wait until TXE flag is set to send data */
if (__HAL_SPI_GET_FLAG(hspi, SPI_FLAG_TXE))
{
*((__IO uint8_t *)&hspi->Instance->DR) = (*hspi->pTxBuffPtr);
hspi->pTxBuffPtr += sizeof(uint8_t);
hspi->TxXferCount--;
}
spi setup
`
hspi2.Instance = SPI2;
hspi2.Init.Mode = SPI_MODE_MASTER;
hspi2.Init.Direction = SPI_DIRECTION_2LINES;
hspi2.Init.DataSize = SPI_DATASIZE_8BIT;
hspi2.Init.CLKPolarity = SPI_POLARITY_LOW;
hspi2.Init.CLKPhase = SPI_PHASE_1EDGE;
hspi2.Init.NSS = SPI_NSS_SOFT;
hspi2.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;
hspi2.Init.FirstBit = SPI_FIRSTBIT_MSB;
hspi2.Init.TIMode = SPI_TIMODE_DISABLE;
hspi2.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
hspi2.Init.CRCPolynomial = 10;
chip select pin setup
GPIO_InitStruct.Pin = IS25LP128F_CHIP_SELECT_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(IS25LP128F_CHIP_SELECT_GPIO_Port, &GPIO_InitStruct);
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP