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

@ -223,7 +223,10 @@ static void MX_GPIO_Init(void)
HAL_GPIO_WritePin(GPIOC, LED_Pin|ERROR_Pin, GPIO_PIN_RESET);
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOB, EEPROM_CS_Pin|OLED_CS_Pin|OLED_DC_Pin|OLED_RST_Pin, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOB, EEPROM_CS_Pin|OLED_CS_Pin, GPIO_PIN_SET);
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOB, OLED_DC_Pin|OLED_RST_Pin, GPIO_PIN_RESET);
/*Configure GPIO pins : LED_Pin ERROR_Pin */
GPIO_InitStruct.Pin = LED_Pin|ERROR_Pin;

View File

@ -90,13 +90,15 @@ PB5.GPIO_ModeDefaultEXTI=GPIO_MODE_IT_RISING_FALLING
PB5.GPIO_PuPd=GPIO_PULLUP
PB5.Locked=true
PB5.Signal=GPXTI5
PB6.GPIOParameters=GPIO_Label
PB6.GPIOParameters=PinState,GPIO_Label
PB6.GPIO_Label=EEPROM_CS
PB6.Locked=true
PB6.PinState=GPIO_PIN_SET
PB6.Signal=GPIO_Output
PB7.GPIOParameters=GPIO_Label
PB7.GPIOParameters=PinState,GPIO_Label
PB7.GPIO_Label=OLED_CS
PB7.Locked=true
PB7.PinState=GPIO_PIN_SET
PB7.Signal=GPIO_Output
PB8.GPIOParameters=GPIO_Label
PB8.GPIO_Label=OLED_DC

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);
}

View File

@ -11,6 +11,8 @@
#include "stm32f1xx_hal.h"
#define STORAGE_ADDRESS 0x10
void eepromWrite(uint16_t addr, uint8_t *buf, uint8_t len);
void eepromRead(uint16_t addr, uint8_t *buf, uint8_t len);

View File

@ -11,6 +11,11 @@
#include "alarm.h"
#include <PontCoopScheduler.h>
#include "oled.h"
#include "eeprom.h"
const uint32_t STORAGE_MAGIC = 0xaffe0001;
@ -23,8 +28,30 @@ volatile tDisplay display = {
.overrunTime = 0
};
typedef struct {
uint32_t magic;
uint32_t savedTemperature;
uint32_t savedTime;
} tStorage;
tStorage storage;
void updateDisplay(void *handle) {
static uint8_t eetoggle = 0;
if (eetoggle == 0) {
eetoggle = 1;
eepromRead(STORAGE_ADDRESS, &storage, sizeof(storage));
} else {
eetoggle = 0;
storage.magic = STORAGE_MAGIC;
storage.savedTemperature = 1;
storage.savedTime = 2;
eepromWrite(STORAGE_ADDRESS, &storage, sizeof(storage));
}
tDisplay *lDisplay = (tDisplay*) handle;
lDisplay->toggle ^= 0x01;
char buf[32];
@ -46,13 +73,31 @@ void updateDisplay(void *handle) {
}
LED_P8x16Str(0, 4, buf);
sprintf(buf, " %5ds", lDisplay->overrunTime);
// sprintf(buf, " %5ds", lDisplay->overrunTime);
static uint32_t h = 0;
static uint32_t c = 0;
uint32_t i = HAL_GetTick();
sprintf(buf, "%d %d %d", c, i, i-h);
h = i;
c++;
LED_P8x16Str(0, 6, buf);
}
void hmiInit() {
eepromRead(STORAGE_ADDRESS, &storage, sizeof(storage));
if (storage.magic == STORAGE_MAGIC) {
display.targetTemperature = storage.savedTemperature;
display.targetTime = storage.savedTime;
} else {
storage.magic = STORAGE_MAGIC;
storage.savedTemperature = 0;
storage.savedTime = 0;
eepromWrite(STORAGE_ADDRESS, &storage, sizeof(storage));
}
schAdd(updateDisplay, &display, 0, 250);
}
void clearSetMode(void *handle) {
@ -100,12 +145,16 @@ void displayIncValue() {
reEnableSetModeTimer();
if (display.targetTemperature < 100) {
display.targetTemperature++;
// storage.savedTemperature = display.targetTemperature;
// eepromWrite(STORAGE_ADDRESS, &storage, sizeof(storage));
}
}
if (display.setModeTime == 1) {
reEnableSetModeTimer();
if (display.targetTime < 999) {
display.targetTime += 10;
// storage.savedTime = display.targetTime;
// eepromWrite(STORAGE_ADDRESS, &storage, sizeof(storage));
}
}
}
@ -115,12 +164,16 @@ void displayDecValue() {
reEnableSetModeTimer();
if (display.targetTemperature > 0) {
display.targetTemperature--;
// storage.savedTemperature = display.targetTemperature;
// eepromWrite(STORAGE_ADDRESS, &storage, sizeof(storage));
}
}
if (display.setModeTime == 1) {
reEnableSetModeTimer();
if (display.targetTime >= 10) {
display.targetTime -= 10;
// storage.savedTime = display.targetTime;
// eepromWrite(STORAGE_ADDRESS, &storage, sizeof(storage));
}
}
}

View File

@ -14,11 +14,11 @@
typedef struct {
uint8_t toggle;
uint8_t setModeTemperature;
uint8_t setModeTime;
uint32_t toggle;
uint32_t setModeTemperature;
uint32_t setModeTime;
tTimerState timerState;
uint8_t toggleModeState;
uint32_t toggleModeState;
uint32_t targetTemperature;
uint32_t currentTemperature;
uint32_t targetTime;

View File

@ -12,7 +12,8 @@ typedef enum {
IDLE = 0,
STARTED = 1,
RUNNING = 2,
OVERRUN = 3
OVERRUN = 3,
MAX = 0xffffffff
} tTimerState;

View File

@ -227,7 +227,10 @@ static void MX_GPIO_Init(void)
HAL_GPIO_WritePin(GPIOC, LED_Pin|ERROR_Pin, GPIO_PIN_RESET);
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOB, EEPROM_CS_Pin|OLED_CS_Pin|OLED_DC_Pin|OLED_RST_Pin, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOB, EEPROM_CS_Pin|OLED_CS_Pin, GPIO_PIN_SET);
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOB, OLED_DC_Pin|OLED_RST_Pin, GPIO_PIN_RESET);
/*Configure GPIO pins : LED_Pin ERROR_Pin */
GPIO_InitStruct.Pin = LED_Pin|ERROR_Pin;

View File

@ -223,7 +223,10 @@ static void MX_GPIO_Init(void)
HAL_GPIO_WritePin(GPIOC, LED_Pin|ERROR_Pin, GPIO_PIN_RESET);
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOB, EEPROM_CS_Pin|OLED_CS_Pin|OLED_DC_Pin|OLED_RST_Pin, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOB, EEPROM_CS_Pin|OLED_CS_Pin, GPIO_PIN_SET);
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOB, OLED_DC_Pin|OLED_RST_Pin, GPIO_PIN_RESET);
/*Configure GPIO pins : LED_Pin ERROR_Pin */
GPIO_InitStruct.Pin = LED_Pin|ERROR_Pin;