Winbond W25 Q和STM32 F411 Blackpill - SPI无响应

uubf1zoe  于 2023-06-28  发布在  其他
关注(0)|答案(2)|浏览(142)

我正在STM32 F411 Blackpill板上为W25 Q(25 Q64 FVSIG)编写CMSIS顶部的SPI驱动程序。我的问题是闪存不响应通过SPI的信号。MCU配置为主,闪存配置为从。产生时钟和MOSI信号,CS设置为低电平。然而,我没有观察到MISO的答案,如下图所示。
引脚Map:(PA4 - CS)(PA5 - SCK)(PA7 - MOSI)(PB4 - MISO)
我怀疑闪存芯片有问题,但换成新的后,我观察到没有改善。与此同时,我看着代码和波形,却不知道我做错了什么。我身边也没有人陪我看。所以我指望你的帮助!
Oscilloscope measurement picture - attempt to read JEDEC ID
这是我的驱动程序代码的样子:

uint32_t w25_pin_spi_init(void)
{
    RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN;
    RCC->AHB1ENR |= RCC_AHB1ENR_GPIOBEN;
    /* setup alternate functions of PA5/PA7/PB4 and output to PA4 (NSS)*/
    GPIOA->MODER &= ~GPIO_MODER_MODE4;
    GPIOA->MODER &= ~GPIO_MODER_MODE5;
    GPIOA->MODER &= ~GPIO_MODER_MODE7;
    GPIOB->MODER &= ~GPIO_MODER_MODE4;

    GPIOA->MODER |= GPIO_MODER_MODE4_0; //output
    GPIOA->MODER |= GPIO_MODER_MODE5_1; //alternate
    GPIOA->MODER |= GPIO_MODER_MODE7_1;
    GPIOB->MODER |= GPIO_MODER_MODE4_1;

    GPIOA->OSPEEDR |= (GPIO_OSPEEDR_OSPEED4_0 | GPIO_OSPEEDR_OSPEED4_1);

    /* OTYPER in reset state */
    GPIOA->PUPDR &= ~GPIO_PUPDR_PUPD5;
    GPIOA->PUPDR &= ~GPIO_PUPDR_PUPD7;
    GPIOB->PUPDR &= ~GPIO_PUPDR_PUPD4;
    GPIOA->PUPDR &= ~GPIO_PUPDR_PUPD4;
    /* pull-up for MISO */
    GPIOB->PUPDR |= GPIO_PUPDR_PUPD4_0;

    GPIOA->AFR[0] |= (GPIO_AFRL_AFSEL5_0 | GPIO_AFRL_AFSEL5_2);
    GPIOA->AFR[0] |= (GPIO_AFRL_AFSEL7_0 | GPIO_AFRL_AFSEL7_2);
    GPIOB->AFR[0] |= (GPIO_AFRL_AFSEL4_0 | GPIO_AFRL_AFSEL4_2);

    return 0;
}

void w25_CS_enable(void)
{
    GPIOA->BSRR |= GPIO_BSRR_BR4;
}

void w25_CS_disable (void)
{
    GPIOA->BSRR |= GPIO_BSRR_BS4;
}

uint32_t w25_spi_init(void)
{
    RCC->APB2ENR |= RCC_APB2ENR_SPI1EN;
    SPI1->CR1 &= ~SPI_CR1_DFF;
    SPI1->CR1 |= (SPI_CR1_BR_2 | SPI_CR1_BR_1 | SPI_CR1_BR_0);
    SPI1->CR1 |= SPI_CR1_MSTR;
    SPI1->CR1 |= SPI_CR1_SSM;
    SPI1->CR1 |= SPI_CR1_SSI;
    SPI1->CR1 |= SPI_CR1_SPE;
    return 0;
}

uint16_t w25_send_receive_data(uint16_t data)
{
    while(!(SPI1->SR & SPI_SR_TXE));
    SPI1->DR = data;
    while(!(SPI1->SR & SPI_SR_RXNE));
    return SPI1->DR;
}

它的使用方式是读取JEDEC ID:

w25_pin_spi_init();
w25_spi_init();
[...]
w25_CS_enable();
w25_send_receive_data(0x9F);
uint16_t manuf = w25_send_receive_data(0x00);
uint16_t mem_type = w25_send_receive_data(0x00);
uint16_t capa = w25_send_receive_data(0x00);
w25_CS_disable();

/WP和/FLASH引脚通过电路板设计设置为高电平,原理图如下所示。
STM32 F411 Blackpill原理图(左下角 Flink ):STM32F411 Blackpill schematic

ohtdti5x

ohtdti5x1#

我发现问题了。这是我的板上的闪存的MISO连接到引脚PA 7,而不是像文档中的PB 4。我可能有一个不同版本的黑板。
千万别相信图纸!在真实的的棋盘上为自己检查!

p8h8hvxi

p8h8hvxi2#

GPIOA->MODER &= ~GPIO_MODER_MODE4;
    GPIOA->MODER &= ~GPIO_MODER_MODE5;
    GPIOA->MODER &= ~GPIO_MODER_MODE7;
    GPIOB->MODER &= ~GPIO_MODER_MODE4;

三次GPIOA和仅一次GPIOB。设置时也一样。复制粘贴错误我相信。检查代码中的类似错误。
您应该使用函数来避免此类问题。

相关问题