2020-05-05 09:04 AM
Hi
I am trying to talk to a Winbond W25Q64 SPI Flash and it seems to write data ok but for some reason the call to do a SPI Read actually forces it to clock16 bits - which is wrong. It is set to 8.
I do a HAL_SPI_TransmitReceive to send a 0x9F to read the 3 byte ID. I get the first byte straight back according to the trace. But then I call HAL_SPI_Receive and it still seems to clock 16 bits (and seems to call TransmitRecieve) internally
Any ideas?
The trace is the clock and then the MISO line. Code Is below - I am just calling the Flash_ReadID and it returns all zero. The initial function is below that
uint8_t Flash_Spi(uint8_t Data)
{
uint8_t ret;
HAL_SPI_TransmitReceive(&_FLASH_SPI, &Data, &ret, 1, 100);
return ret;
}
uint8_t Flash_Read_Byte(void)
{
uint8_t ret;
HAL_SPI_Receive(&_FLASH_SPI, &ret, 1, 100);
return ret;
}
uint8_t Flash_Write_Byte(uint8_t Data)
{
return(HAL_SPI_Transmit(&_FLASH_SPI, &Data, 1, 100));
}
uint32_t Flash_ReadID(void)
{
uint32_t Temp = 0, Temp0 = 0, Temp1 = 0, Temp2 = 0;
HAL_GPIO_WritePin(_FLASH_CS_GPIO, _FLASH_CS_PIN, GPIO_PIN_RESET);
Temp0 = Flash_Spi(0x9F);
Temp1 = Flash_Read_Byte();
Temp2 = Flash_Read_Byte();
HAL_GPIO_WritePin(_FLASH_CS_GPIO,_FLASH_CS_PIN,GPIO_PIN_SET);
Temp = (Temp0 << 16) | (Temp1 << 8) | Temp2;
return Temp;
}
INIT FUNCTION
/* 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_DISABLE;
if (HAL_SPI_Init(&hspi1) != HAL_OK)
{
Error_Handler(SENSOR_HAL_ERROR);
}
/* DMA controller clock enable */
__HAL_RCC_DMA_CLK_ENABLE();
/* DMA interrupt init */
/* DMA_IRQn interrupt configuration */
HAL_NVIC_SetPriority(DMA_IRQn, 0);
HAL_NVIC_EnableIRQ(DMA_IRQn);
while(HAL_GetTick()<100)
Flash_Delay(1);
HAL_GPIO_WritePin(_FLASH_CS_GPIO,_FLASH_CS_PIN,GPIO_PIN_SET);