Associate II
January 22, 2021
Solved
Cannot communicate with ext SPI Flash
- January 22, 2021
- 3 replies
- 1087 views
Hey guys,
I am trying to communicate with S25FL064L Cypress Flash and almost for one week I cant reach the redec ID , I checked the hardware, and communication with digital analyzer just with S25FL064L no any hardware.Tried the HAL library , checked the websites and compare with my codes, I couldn'd find a mistake, so where is my mistake now.Thank you for answers and spending time.These are codes related.
int main(void)
{
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_SYSCFG);
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_PWR);
SystemClock_Config();
// 0xEBFF FCFF for port A
// 0xFFFF FFFF for the other ports
// I have read some info from the users and that is why this code is below
CLEAR_REG(CS_FLASH_GPIO_Port->MODER);
MX_GPIO_Init();
MX_SPI1_Init();
MX_SPI2_Init();
MX_USART1_UART_Init();
MX_USART2_UART_Init();
MX_ADC_Init();
MX_RTC_Init();
MX_I2C1_Init();
LL_SPI_Enable(SPI1);
}
void read_Jedec_ID(uint8_t *p)
{
LL_GPIO_ResetOutputPin(GPIOA, LL_GPIO_PIN_15);
spi_transmit_receive(SPI1, SPI_RDID_CMD);//0x9F
for (uint8_t i = 0; i < 8; i++)
{
p[i] = spi_transmit_receive(SPI1, 0x00);
}
LL_GPIO_SetOutputPin(CS_FLASH_GPIO_Port, CS_FLASH_Pin);
}
uint8_t spi_transmit_receive(SPI_TypeDef *SPIx, uint16_t val)
{
uint8_t ret_val;
while (!(READ_BIT(SPI1->SR, SPI_SR_TXE) == (SPI_SR_TXE)))
;
LL_SPI_TransmitData8(SPIx, (uint8_t)val);
while (!(READ_BIT(SPIx->SR, SPI_SR_RXNE) == (SPI_SR_RXNE)))
;
ret_val = LL_SPI_ReceiveData8(SPIx);
return ret_val;
}