无法读取华邦W25Q16的JEDEC ID

时间:2018-06-20 07:20:34

标签: stm32 spi

我正在使用stm32f103rct6连接spi闪存。我已经在CMSIS核心中编写了代码,并试图读取spi flash的JEDEC ID。

这是我的 SPI写入功能

uint8_t SPI3_Write(uint8_t value)
{
    uint8_t retVal;    //Initializing variable to store return value
    while (!(SPI3->SR & SPI_SR_TXE));  //Wait till Transmit buffer is Empty
    SPI3->DR = value;           //Send SPI data
    while (!(SPI3->SR & SPI_SR_RXNE));  //Wait till receive buffer is Empty
    retVal = SPI3->DR & 0xFF; //As frame format is 8 bit, storing LSB - Bit[0:7]
    return(retVal);     //Returning the value recieved 
}

这是我读取JEDEC ID的方式

uint32_t Read_ID()
{
    uint32_t Temp = 0, Temp0 = 0, Temp1 = 0, Temp2 = 0;
    CS_LOW();
    SPI3_Write(DEVICE_ID);   //DEVICE_ID = 0x9F
    //DUMMY_BYTE = 0x00
    Temp0 = SPI3_Write(DUMMY_BYTE);   
    Temp1 = SPI3_Write(DUMMY_BYTE);
    Temp2 = SPI3_Write(DUMMY_BYTE);
    CS_HIGH();
    Temp = (Temp0 << 16) | (Temp1 << 8) | Temp2;
    return Temp;
}

根据数据表

Instruction

值将类似于

JEDEC RETURN

在我的读取ID函数中,Temp0将为MF7-MF0,Temp1将为ID15-ID8,Temp2将为ID7-ID0

因此, Temp0 = 0xEF,Temp1 = 0x40和Temp2 = 0x15 和Temp = 0x00EF4015(不确定)

但是我将Temp设置为0。(虽然我通过SPI发送DUMMY_BYTE,但我什么也没回来,也没有从SPIx-> DR寄存器读取相同的值,因为SPI是全双工的,所以从设备向我发送了一些cuz信息我应该得到一个有价值的价值

我猜我的 SPI_Write()函数有问题

我的SPI初始化是这样的。

void SPI3_Init()
{
    RCC->APB1ENR |= RCC_APB1ENR_SPI3EN; //Initialize clocks
    SPI3->CR1 |= SPI_CR1_BR_2;      //Set Prescale for SPI
    SPI3->CR1 |= SPI_CR1_BIDIMODE;  //Select SPI as Bi-Directional as to read and write
    SPI3->CR1 |= SPI_CR1_MSTR;  //Select Device as master
    SPI3->CR1 &= ~SPI_CR1_DFF;  //Select 8-Bit Data
    /*For Software NSS*/
    SPI3->CR1 |= SPI_CR1_SSM;   //Set SSM bit
    SPI3->CR1 |= SPI_CR1_SSI;   //Clear SSI bit
    SPI3->CR1 &= ~SPI_CR1_LSBFIRST; //Select MSB first
    SPI3->CR1 |= SPI_CR1_CPOL;  //Select CPOL (clock polarity) High CK to 1 when idle
    SPI3->CR1 |= SPI_CR1_CPHA; //Select CPHA (clock Phase) to The second clock transition is the first data capture edge
}

我的GPIO初始化为

void GPIO_Init()
{
    RCC->APB2ENR |= RCC_APB2ENR_IOPAEN; //Clock for Port A - as PA15 is CS
    RCC->APB2ENR |= RCC_APB2ENR_IOPBEN; //Clock for Port B - as PB3(SCK), PB4(MISO) & PB5(MOSI)
    RCC->APB2ENR |= RCC_APB2ENR_AFIOEN; //ENABLE clock for alternate function

    /*LED Configuration - PA8*/
    GPIOA->CRH |= GPIO_CRH_MODE8;   /Output mode, max speed 50 MHz.
    GPIOA->CRH &= ~GPIO_CRH_CNF8;   //General purpose output push-pull

    /*CS Configuration - PA15*/
    GPIOA->CRH |= GPIO_CRH_MODE15;  //Output mode, max speed 50 MHz.
    GPIOA->CRH &= ~GPIO_CRH_CNF15;  //General purpose output push-pull

    /*MISO Configuration - PB4(MISO)*/
    GPIOB->CRL |= GPIO_CRL_MODE4;   //Output mode, max speed 50 MHz.
    GPIOB->CRL |= GPIO_CRL_CNF4_1;  //Alternate Function output push-pull

    /*MOSI Configuration - PB5(MOSI)*/
    GPIOB->CRL |= GPIO_CRL_MODE5;   //Output mode, max speed 50 MHz.
    GPIOB->CRL |= GPIO_CRL_CNF5_1;  //Alternate Function output push-pull

    /*SCK Configuration - PB3(SCK)*/
    GPIOB->CRL |= GPIO_CRL_MODE3;   //Output mode, max speed 50 MHz.
    GPIOB->CRL |= GPIO_CRL_CNF3_1;  //Alternate Function output push-pull

}

请查看该问题,是否有人可以给我一些继续进行的信息。 预先感谢

0 个答案:

没有答案