eeprom not yet working correctly

This commit is contained in:
Wolfgang Hottgenroth
2017-06-11 22:02:07 +02:00
parent c0e370c802
commit cbb8f8d188
9 changed files with 109 additions and 23 deletions

View File

@ -7,6 +7,7 @@
#include "eeprom.h"
#include "stm32f1xx_hal.h"
#include <string.h>
#define HIGH GPIO_PIN_SET
@ -28,28 +29,46 @@ static void __EEPROM_CS(GPIO_PinState v) {
}
static void __HAL_SPI_Transmit_One_ByValue(SPI_HandleTypeDef *hspi, uint8_t c) {
HAL_SPI_Transmit(hspi, &c, 1, 0);
HAL_SPI_Transmit(hspi, &c, 1, HAL_MAX_DELAY);
}
void eepromWrite(uint16_t addr, uint8_t *buf, uint8_t len) {
struct {
uint8_t wren;
uint8_t write;
uint16_t addr;
uint8_t data[32];
} msg = {
.wren = EEPROM_WREN,
.write = EEPROM_WRITE,
.addr = addr
};
memcpy(msg.data, buf, len);
__EEPROM_CS(LOW);
__HAL_SPI_Transmit_One_ByValue(&hspi1, EEPROM_WREN);
__HAL_SPI_Transmit_One_ByValue(&hspi1, EEPROM_WRITE);
HAL_SPI_Transmit(&hspi1, (uint8_t*)&addr, 2, 0);
HAL_SPI_Transmit(&hspi1, buf, len, 0);
HAL_SPI_Transmit(&hspi1, &msg, ((uint16_t)(len+4)), HAL_MAX_DELAY);
__EEPROM_CS(HIGH);
}
void eepromRead(uint16_t addr, uint8_t *buf, uint8_t len) {
struct {
uint8_t read;
uint16_t addr;
uint8_t data[32];
} txMsg = {
.read = EEPROM_READ,
.addr = addr
},
rxMsg;
__EEPROM_CS(LOW);
__HAL_SPI_Transmit_One_ByValue(&hspi1, EEPROM_READ);
HAL_SPI_Transmit(&hspi1, (uint8_t*)&addr, 2, 0);
HAL_SPI_Receive(&hspi1, buf, len, 0);
HAL_SPI_TransmitReceive(&hspi1, &txMsg, &rxMsg, ((uint16_t)(len+3)), HAL_MAX_DELAY);
__EEPROM_CS(HIGH);
// __EEPROM_CS(LOW);
// __HAL_SPI_Transmit_One_ByValue(&hspi1, EEPROM_READ);
// HAL_SPI_Transmit(&hspi1, &addr, 2, HAL_MAX_DELAY);
// HAL_SPI_Receive(&hspi1, buf, ((uint16_t)len), HAL_MAX_DELAY);
// __EEPROM_CS(HIGH);
}