cancel
Showing results for 
Search instead for 
Did you mean: 

M95P32 EEPROM cannot read or write from custom STM32 board

Marmelade
Associate

Hello,

I have an issue reading and writing to and from the M95P32. So far it has never worked. I tried using the official ST driver https://github.com/STMicroelectronics/stm32-m95p32/tree/main  but nothing happened. I don't know if the write was successfull but when I tried to read back the data, I only receive 0x00.

 

Here is a sample of the code used

#define USE_SPI

#include "m95p32.h"

std::int32_t eeprom_init() {

    return 0;
}

std::int32_t eeprom_deinit() {

    return 0;
}

std::int32_t eeprom_read( uint8_t *data, uint8_t size ) {

    silentlib::spi_lock cs_pin{ device::instance().eeprom_cs };

    return HAL_SPI_Receive( &hspi3, data, size, 1000U ) == HAL_OK ? 0 : -1;
}

std::int32_t eeprom_write( uint8_t *data, uint32_t size ) {

    silentlib::spi_lock cs_pin{ device::instance().eeprom_cs };

    return HAL_SPI_Transmit( &hspi3, data, size, 1000U ) == HAL_OK ? 0 : -1;
}

std::int32_t eeprom_sendrecv( uint8_t *data_transmit, uint8_t *data_receive, uint16_t size ) {

    silentlib::spi_lock cs_pin{ device::instance().eeprom_cs };

    return HAL_SPI_TransmitReceive( &hspi3, data_transmit, data_receive, size, 1000U ) == HAL_OK ? 0 : -1;
}

void eeprom_delay( uint32_t amount ) {

    silentlib::delay_ms( amount );
}

// snip

int main() {

    MX_SPI3_Init(); // 500kHz; CPOL = 0; CPHA = 0;

    // ...

    M95_Object_t eeprom {
        .IO = {
            .Init = eeprom_init,
            .DeInit = eeprom_deinit,
            .Read = eeprom_read,
            .Write = eeprom_write,
            .SendRecv = eeprom_sendrecv,
            .Delay = eeprom_delay,
            .Address = 0x00,
        },
    };

    std::uint8_t message_to_write[] {"Test M95P32"};
    const std::size_t address_to_write {};

    std::uint8_t message_to_read[ 128 ]{};
    const std::size_t address_to_read { address_to_write };

    Page_Write( &eeprom, message_to_write, address_to_write, std::size( message_to_write ) );
    Single_Read( &eeprom, message_to_read, address_to_read, std::size( message_to_read ) );

    // message_to_read => 0x00
}

We pulled up the CS line to VDD line ( ~3.5V ) of the EEPROM with a 47kohm resistor instead of 100kohm.

HOLD and WP pins are held high.

Is there anything I forgot ?

Thanks for your help.

0 REPLIES 0