2021-10-14 02:18 AM
I am using STM32H743 and trying to test my FRAM (FM25V20A) using SPI, I am able to read the device ID correctly but when I tried to write to the FRAM and read back I received zeros.
I sent ULBPR and then WREN, when I read the status register using RDSR I received zeros which means that the WEL was not set.
Solved! Go to Solution.
2021-11-03 12:10 AM
It turned out to be a silly mistake of using the wrong the SPI in the second part of the code.
2021-10-14 02:51 AM
Hi,
I propose change in configuration for SPI1 Datasize from SPI_DATASIZE_4BIT to SPI_DATASIZE_8BIT.
Best Regards,
Slawek
2021-10-14 02:56 AM
It still isnt working, thank you anyway!
2021-10-14 03:38 AM
Hi,
Please see my code for write and read from FRAM FM25V10A
Best regards,
Slawek
void Write_UI_FR (uint16_t addr, uint16_t *data)
{
uint8_t data_to_transmit[5];
Enable_Write_FR();
data_to_transmit[0] = OPCODE_WRITE;
data_to_transmit[1] = addr >> 8;
data_to_transmit[2] = addr;
data_to_transmit[3] = *((uint8_t*)data);
data_to_transmit[4] = *((uint8_t*)data+1);
HAL_GPIO_WritePin(FR_CS_GPIO_Port, FR_CS_Pin, RESET);
HAL_SPI_Transmit(&hspi2, &data_to_transmit[0], 5, 5);
HAL_GPIO_WritePin(FR_CS_GPIO_Port, FR_CS_Pin, SET);
}
uint16_t Read_UI_FR (uint16_t addr, uint16_t *data)
{
uint8_t data_recv[2];
uint8_t data_to_transmit[4];
uint16_t data_ret=0;
Enable_Write_FR();
data_to_transmit[0] = OPCODE_READ;
data_to_transmit[1] = addr >> 8;
data_to_transmit[2] = addr;
HAL_GPIO_WritePin(FR_CS_GPIO_Port, FR_CS_Pin, RESET);
HAL_SPI_Transmit(&hspi2, &data_to_transmit[0], 3, 5);
HAL_SPI_Receive(&hspi2, &data_recv[0], 2, 5);
HAL_GPIO_WritePin(FR_CS_GPIO_Port, FR_CS_Pin, SET);
*((uint8_t*)data) = data_recv[0];
*((uint8_t*)data+1) = data_recv[1];
data_ret = (((uint16_t)(data_recv[0] << 8)) | data_recv[1]);
return data_ret;
}
void Enable_Write_FR (void)
{
opcodes_t code_func;
code_func = OPCODE_WREN;
HAL_GPIO_WritePin(FR_CS_GPIO_Port, FR_CS_Pin, RESET);
HAL_SPI_Transmit(&hspi2, &code_func, 1, 5);
HAL_GPIO_WritePin(FR_CS_GPIO_Port, FR_CS_Pin, SET);
}
void Disable_Write_FR (void)
{
opcodes_t code_func;
code_func = OPCODE_WRDI;
HAL_GPIO_WritePin(FR_CS_GPIO_Port, FR_CS_Pin, RESET);
HAL_SPI_Transmit(&hspi2, &code_func, 1, 5);
HAL_GPIO_WritePin(FR_CS_GPIO_Port, FR_CS_Pin, SET);
}
typedef enum opcodes_e
{
OPCODE_WREN = 0b00000110, /* Write Enable Latch */
OPCODE_WRDI = 0b00000100, /* Reset Write Enable Latch */
OPCODE_RDSR = 0b00000101, /* Read Status Register */
OPCODE_WRSR = 0b00000001, /* Write Status Register */
OPCODE_READ = 0b00000011, /* Read Memory */
OPCODE_WRITE = 0b00000010, /* Write Memory */
OPCODE_RDID = 0b10011111 /* Read Device ID */
} opcodes_t;
2021-11-03 12:10 AM
It turned out to be a silly mistake of using the wrong the SPI in the second part of the code.