diff --git a/software/Firmware/Inc/Logger.h b/software/Firmware/Inc/Logger.h index 14b85e6..0ba3ab3 100755 --- a/software/Firmware/Inc/Logger.h +++ b/software/Firmware/Inc/Logger.h @@ -12,10 +12,6 @@ void Logger_Init(); -void Logger_Tick(); - - -// used to redirect printf to UART -void putchar(char c); +void Logger_Print(uint8_t data); #endif /* INC_LOGGER_H_ */ diff --git a/software/Firmware/Inc/UserInterface.h b/software/Firmware/Inc/UserInterface.h index 72ee9f9..855734f 100755 --- a/software/Firmware/Inc/UserInterface.h +++ b/software/Firmware/Inc/UserInterface.h @@ -12,7 +12,8 @@ typedef enum UserInterface_Status { USER_INTERFACE_COLLECTING_DATA_MSG, USER_INT void UserInterface_Init(); +void UserInterface_Tick(); + void UserInterface_ShowMessage(UserInterface_Status status); - #endif /* SRC_GUI_H_ */ diff --git a/software/Firmware/Inc/VoltageSensorActualValue.h b/software/Firmware/Inc/VoltageSensorActualValue.h index 436bd14..a00453e 100644 --- a/software/Firmware/Inc/VoltageSensorActualValue.h +++ b/software/Firmware/Inc/VoltageSensorActualValue.h @@ -1,5 +1,5 @@ /* - * MCP3425A0T.h + * VoltageSensorActualValue.h * * Created on: 04.06.2019 * Author: robert @@ -10,7 +10,7 @@ #include "CommonDataTypes.h" -#define VoltageSensorActualValue_MeasurementData_t uint8_t +#define VoltageSensorActualValue_MeasurementData_t uint8_t typedef struct MCP3425A0TConfig_t { int i2cAddress; diff --git a/software/Firmware/Inc/VoltageSensorPeakValue.h b/software/Firmware/Inc/VoltageSensorPeakValue.h index 65a9011..8c7c8ab 100755 --- a/software/Firmware/Inc/VoltageSensorPeakValue.h +++ b/software/Firmware/Inc/VoltageSensorPeakValue.h @@ -8,6 +8,7 @@ #ifndef INC_VOLTAGESENSORPEAKVALUE_H_ #define INC_VOLTAGESENSORPEAKVALUE_H_ +// no implementation yet, because peak value sensor is not used #endif /* INC_VOLTAGESENSORPEAKVALUE_H_ */ diff --git a/software/Firmware/Src/ApplicationBuilder.c b/software/Firmware/Src/ApplicationBuilder.c index 5be9b73..a4d0e98 100644 --- a/software/Firmware/Src/ApplicationBuilder.c +++ b/software/Firmware/Src/ApplicationBuilder.c @@ -26,7 +26,7 @@ void ApplicationBuilder_Init() UserInterface_Init(); VoltageSensorActualValue_Init(); MeasurementCollector_Init(); - + enableInterrupts(); // UserInterface_ShowMessage(USER_INTERFAE_STATE_OK_MSG); diff --git a/software/Firmware/Src/Logger.c b/software/Firmware/Src/Logger.c index 2eb977b..346f368 100644 --- a/software/Firmware/Src/Logger.c +++ b/software/Firmware/Src/Logger.c @@ -6,30 +6,28 @@ */ #include "Logger.h" -//#include + +#define USE_PRINTF +#if defined USE_PRINTF + #include +#endif + #include "stm8s_uart1.h" #include "PinoutConfiguration.h" +#define UART_SPEED 9600 + static void GPIO_setup(void); static void UART1_setup(void); -#ifdef USE_FULL_ASSERT - -void assert_failed(uint8_t* file, uint32_t line) +int putchar(int c) { - (void)file; - (void)line; - - //printf("[error] asset failed %s %d\r\n", file, line); - - while (TRUE) - { - // empty - } + /* Write a character to the UART1 */ + UART1_SendData8(c); + /* Loop until the end of transmission */ + while (UART1_GetFlagStatus(UART1_FLAG_TXE) == RESET); } -#endif - void Logger_Init() { @@ -38,19 +36,30 @@ void Logger_Init() } -void Logger_Tick() +void Logger_Print(uint8_t data) { - // printf ("ok "); + printf("%d\n\r", data); + //putchar(data); } -void putchar(char c) +#ifdef USE_FULL_ASSERT +void assert_failed(uint8_t* file, uint32_t line) { - /* Write a character to the UART1 */ - UART1_SendData8(c); - /* Loop until the end of transmission */ - while (UART1_GetFlagStatus(UART1_FLAG_TXE) == RESET); + (void)file; + (void)line; + +#if defined USE_PRINTF + printf("[error] asset failed %s %d\r\n", file, line); +#endif + + while (TRUE) + { + // empty + } } +#endif + void GPIO_setup(void) @@ -64,10 +73,9 @@ void GPIO_setup(void) void UART1_setup(void) { - // TODO: magic numbers UART1_DeInit(); - UART1_Init(9600, + UART1_Init(UART_SPEED, UART1_WORDLENGTH_8D, UART1_STOPBITS_1, UART1_PARITY_NO, @@ -77,4 +85,3 @@ void UART1_setup(void) UART1_Cmd(ENABLE); } - diff --git a/software/Firmware/Src/MeasurementCollector.c b/software/Firmware/Src/MeasurementCollector.c index 41dd2cc..88d2d5b 100755 --- a/software/Firmware/Src/MeasurementCollector.c +++ b/software/Firmware/Src/MeasurementCollector.c @@ -7,6 +7,8 @@ #include "MeasurementCollector.h" #include "VoltageSensorActualValue.h" +#include "Logger.h" + void MeasurementCollector_Init() { @@ -15,5 +17,9 @@ void MeasurementCollector_Init() void MeasurementCollector_Tick() { - VoltageSensorActualValue_GetMeasurementData(0); + VoltageSensorActualValue_MeasurementData_t sample; + VoltageSensorActualValue_GetMeasurementData(&sample); + + Logger_Print(sample); } + diff --git a/software/Firmware/Src/UserInterface.c b/software/Firmware/Src/UserInterface.c index 05394b7..e1ce216 100644 --- a/software/Firmware/Src/UserInterface.c +++ b/software/Firmware/Src/UserInterface.c @@ -17,6 +17,12 @@ void UserInterface_Init() GPIO_WriteLow(PORT_GPIO_LED, GPIO_LED_PINS); } + +void UserInterface_Tick() +{ +} + + void UserInterface_ShowMessage(UserInterface_Status status) { switch(status) diff --git a/software/Firmware/Src/VoltageSensorActualValue.c b/software/Firmware/Src/VoltageSensorActualValue.c index b3431c8..d5473c8 100644 --- a/software/Firmware/Src/VoltageSensorActualValue.c +++ b/software/Firmware/Src/VoltageSensorActualValue.c @@ -9,18 +9,18 @@ #include "PinoutConfiguration.h" #include "UserInterface.h" #include "stm8s_i2c.h" -//#include "stm8s.h" #define I2C_OWN_ADDRESS 0x10 -#define I2C_SLAVE_ADDRESS 0x68 // MCP3425 I2C address is 0x68(104) - +// MCP3425 I2C address is 0x68(104), this 7 bits, they need to be +// shifted by one, to make 8 bits variable, where less signifant bit +// is used to signalize communication direction (rx or tx) +#define I2C_SLAVE_ADDRESS (0x68 << 1) static void GPIO_setup(void); static void I2C_setup(void); static uint8_t getRegisterValue(uint8_t registerId); - void VoltageSensorActualValue_Init() { GPIO_setup(); @@ -30,9 +30,9 @@ void VoltageSensorActualValue_Init() bool VoltageSensorActualValue_GetMeasurementData(VoltageSensorActualValue_MeasurementData_t *measurementData) { - measurementData = getRegisterValue(0x00); + *measurementData = getRegisterValue(0x00); - if (measurementData == 0) + if (*measurementData == 0) { // for temporary debug only UserInterface_ShowMessage(USER_INTERFACE_COLLECTING_DATA_MSG); @@ -70,7 +70,7 @@ uint8_t getRegisterValue(uint8_t registerId) I2C_GenerateSTART(ENABLE); while(!I2C_CheckEvent(I2C_EVENT_MASTER_MODE_SELECT)); - I2C_Send7bitAddress((I2C_SLAVE_ADDRESS << 1), I2C_DIRECTION_TX); + I2C_Send7bitAddress(I2C_SLAVE_ADDRESS, I2C_DIRECTION_TX); while(!I2C_CheckEvent(I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)); I2C_SendData(registerId); @@ -82,6 +82,6 @@ uint8_t getRegisterValue(uint8_t registerId) I2C_GenerateSTOP(ENABLE); while(I2C_GetFlagStatus(I2C_FLAG_BUSBUSY)); - return registerValue; + return registerValue; } diff --git a/software/Firmware/Src/VoltageSensorPeakValue.c b/software/Firmware/Src/VoltageSensorPeakValue.c index 11127e8..d0d3b4f 100755 --- a/software/Firmware/Src/VoltageSensorPeakValue.c +++ b/software/Firmware/Src/VoltageSensorPeakValue.c @@ -6,3 +6,4 @@ */ #include "VoltageSensorPeakValue.h" + diff --git a/software/Firmware/makefile b/software/Firmware/makefile index 8c8980c..c481cc3 100755 --- a/software/Firmware/makefile +++ b/software/Firmware/makefile @@ -102,7 +102,7 @@ $(IHX): $(SRCS)/$(TARGET).c \ $(BUILD_DIR)/stm8s_tim1.rel \ $(BUILD_DIR)/stm8s_it.rel \ $(BUILD_DIR)/Logger.rel \ - $(BUILD_DIR)/VoltageSensorPeakValue.rel + $(BUILD_DIR)/VoltageSensorPeakValue.rel \ $(BUILD_DIR)/MeasurementCollector.rel $(CC) $(CFLAGS) $(LDFLAGS) -o $(BUILD_DIR)/ $< \ @@ -119,7 +119,7 @@ $(IHX): $(SRCS)/$(TARGET).c \ $(BUILD_DIR)/ClockConfigurator.rel \ $(BUILD_DIR)/TimerConfigurator.rel \ $(BUILD_DIR)/stm8s_tim1.rel \ - $(BUILD_DIR)/VoltageSensorPeakValue.rel + $(BUILD_DIR)/VoltageSensorPeakValue.rel \ $(BUILD_DIR)/MeasurementCollector.rel $(SIZE) $@