Skip to main content
VOliv.5
Associate II
Nov 27, 2018 6:39 PM UTC
Question

How I do for receive data from a SPI EEPROM?

I'm using the STM32l053R8Tx, I configured the board NUCLEO-l053R8 by STM32CubeMX and I transmitted a data for an EEPROM with the function HAL_SPI_Transmit(...); and I'm trying receive the data with this function HAL_SPI_Receive(...); but I only receive " 0xFF 'ÿ' " as data. The memory that I use is that 25lc512, I send the instructions like the datasheet reported, but I can't receive another value, Can anybody help me?

This topic has been closed for replies.

6 replies

Tesla DeLorean
Guru
Nov 27, 2018 7:33 PM UTC

Check the wiring and scope the signals. Ideally hook up a logic analyzer and review what you see at the pins. If the EEPROM is non-responsive you aren't going to get any usable data. Make sure the CS (chip select) pin is operational.

Easier to help if you provide a schematic and provide code.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
VOliv.5
VOliv.5Author
Associate II
Nov 28, 2018 4:38 PM UTC
void mem_start(void)
{
 HAL_GPIO_WritePin(M_CS_GPIO_Port, M_CS_Pin, GPIO_PIN_RESET);
 HAL_Delay(1);
 HAL_SPI_Transmit(&hspi2, &WREN, 1, 100);
 HAL_GPIO_WritePin(M_CS_GPIO_Port, M_CS_Pin, GPIO_PIN_SET);
 HAL_Delay(10); 
}
 
void send_data(unsigned int addr0, unsigned int addr1)
{
 mem_start();
 
 address = 0x01;
 
 uint8_t buffer[5];
 
 buffer [0] = 0x02;
 buffer [1] = 0x00;
 buffer [2] = address;
 buffer [3] = 0x03;
 buffer [4] = 0x06;
 
 HAL_GPIO_WritePin(M_CS_GPIO_Port, M_CS_Pin, GPIO_PIN_RESET);
 HAL_SPI_Transmit(&hspi2, buffer, 5,100);
 //HAL_Delay(5);
 HAL_GPIO_WritePin(M_CS_GPIO_Port, M_CS_Pin, GPIO_PIN_SET);
 HAL_Delay(10);
}
 
void receive_data(void)
{
 uint8_t buffer_in [3];
 uint8_t data[3];
 data [0] = 0x03; 
 data [1] = 0x00;
 data [2] = address;
 
//********************* receive data ***************************** 
 
 HAL_GPIO_WritePin(M_CS_GPIO_Port, M_CS_Pin, GPIO_PIN_RESET);
 HAL_SPI_Transmit(&hspi2, data, 3,100);
 HAL_SPI_Receive(&hspi2, buffer_in, 2,100);
 HAL_Delay(5);
 HAL_GPIO_WritePin(M_CS_GPIO_Port, M_CS_Pin, GPIO_PIN_SET);
 
//********************* transmit data *************************
 buffer_in [2] = buffer_in[0] | buffer_in[1];
 
 HAL_SPI_Transmit(&hspi1, &buffer_in[2], 1,100);
 HAL_GPIO_WritePin(LCLK_GPIO_Port, LAT_Pin, GPIO_PIN_SET);
 HAL_GPIO_WritePin(LCLK_GPIO_Port, LAT_Pin, GPIO_PIN_RESET);
}

0690X000006CXSaQAO.jpg Right, here it is the schematic (did on 'paint') and a part of my code that I use for the comunication with the EEPROM.

Tesla DeLorean
Guru
Nov 28, 2018 4:49 PM UTC

And does the signalling look right on the analyzer?

I'd perhaps use the TransmitReceive variant to send the command and dummy data, and be wary of the rising edge of the CS pin

See also SPI implementation in STM32Cube_FW_L0_V1.10.0\Drivers\BSP\STM32L0xx_Nucleo\stm32l0xx_nucleo.c

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..