logging semi-dummy adc readings to uart

pull/97/head
RobertGawron 2019-07-28 14:06:13 +01:00
rodzic 40a319723c
commit f82d2862d5
11 zmienionych plików z 63 dodań i 45 usunięć

Wyświetl plik

@ -12,10 +12,6 @@
void Logger_Init(); void Logger_Init();
void Logger_Tick(); void Logger_Print(uint8_t data);
// used to redirect printf to UART
void putchar(char c);
#endif /* INC_LOGGER_H_ */ #endif /* INC_LOGGER_H_ */

Wyświetl plik

@ -12,7 +12,8 @@ typedef enum UserInterface_Status { USER_INTERFACE_COLLECTING_DATA_MSG, USER_INT
void UserInterface_Init(); void UserInterface_Init();
void UserInterface_Tick();
void UserInterface_ShowMessage(UserInterface_Status status); void UserInterface_ShowMessage(UserInterface_Status status);
#endif /* SRC_GUI_H_ */ #endif /* SRC_GUI_H_ */

Wyświetl plik

@ -1,5 +1,5 @@
/* /*
* MCP3425A0T.h * VoltageSensorActualValue.h
* *
* Created on: 04.06.2019 * Created on: 04.06.2019
* Author: robert * Author: robert
@ -10,7 +10,7 @@
#include "CommonDataTypes.h" #include "CommonDataTypes.h"
#define VoltageSensorActualValue_MeasurementData_t uint8_t #define VoltageSensorActualValue_MeasurementData_t uint8_t
typedef struct MCP3425A0TConfig_t { typedef struct MCP3425A0TConfig_t {
int i2cAddress; int i2cAddress;

Wyświetl plik

@ -8,6 +8,7 @@
#ifndef INC_VOLTAGESENSORPEAKVALUE_H_ #ifndef INC_VOLTAGESENSORPEAKVALUE_H_
#define INC_VOLTAGESENSORPEAKVALUE_H_ #define INC_VOLTAGESENSORPEAKVALUE_H_
// no implementation yet, because peak value sensor is not used
#endif /* INC_VOLTAGESENSORPEAKVALUE_H_ */ #endif /* INC_VOLTAGESENSORPEAKVALUE_H_ */

Wyświetl plik

@ -26,7 +26,7 @@ void ApplicationBuilder_Init()
UserInterface_Init(); UserInterface_Init();
VoltageSensorActualValue_Init(); VoltageSensorActualValue_Init();
MeasurementCollector_Init(); MeasurementCollector_Init();
enableInterrupts(); enableInterrupts();
// UserInterface_ShowMessage(USER_INTERFAE_STATE_OK_MSG); // UserInterface_ShowMessage(USER_INTERFAE_STATE_OK_MSG);

Wyświetl plik

@ -6,30 +6,28 @@
*/ */
#include "Logger.h" #include "Logger.h"
//#include <stdio.h>
#define USE_PRINTF
#if defined USE_PRINTF
#include <stdio.h>
#endif
#include "stm8s_uart1.h" #include "stm8s_uart1.h"
#include "PinoutConfiguration.h" #include "PinoutConfiguration.h"
#define UART_SPEED 9600
static void GPIO_setup(void); static void GPIO_setup(void);
static void UART1_setup(void); static void UART1_setup(void);
#ifdef USE_FULL_ASSERT int putchar(int c)
void assert_failed(uint8_t* file, uint32_t line)
{ {
(void)file; /* Write a character to the UART1 */
(void)line; UART1_SendData8(c);
/* Loop until the end of transmission */
//printf("[error] asset failed %s %d\r\n", file, line); while (UART1_GetFlagStatus(UART1_FLAG_TXE) == RESET);
while (TRUE)
{
// empty
}
} }
#endif
void Logger_Init() 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 */ (void)file;
UART1_SendData8(c); (void)line;
/* Loop until the end of transmission */
while (UART1_GetFlagStatus(UART1_FLAG_TXE) == RESET); #if defined USE_PRINTF
printf("[error] asset failed %s %d\r\n", file, line);
#endif
while (TRUE)
{
// empty
}
} }
#endif
void GPIO_setup(void) void GPIO_setup(void)
@ -64,10 +73,9 @@ void GPIO_setup(void)
void UART1_setup(void) void UART1_setup(void)
{ {
// TODO: magic numbers
UART1_DeInit(); UART1_DeInit();
UART1_Init(9600, UART1_Init(UART_SPEED,
UART1_WORDLENGTH_8D, UART1_WORDLENGTH_8D,
UART1_STOPBITS_1, UART1_STOPBITS_1,
UART1_PARITY_NO, UART1_PARITY_NO,
@ -77,4 +85,3 @@ void UART1_setup(void)
UART1_Cmd(ENABLE); UART1_Cmd(ENABLE);
} }

Wyświetl plik

@ -7,6 +7,8 @@
#include "MeasurementCollector.h" #include "MeasurementCollector.h"
#include "VoltageSensorActualValue.h" #include "VoltageSensorActualValue.h"
#include "Logger.h"
void MeasurementCollector_Init() void MeasurementCollector_Init()
{ {
@ -15,5 +17,9 @@ void MeasurementCollector_Init()
void MeasurementCollector_Tick() void MeasurementCollector_Tick()
{ {
VoltageSensorActualValue_GetMeasurementData(0); VoltageSensorActualValue_MeasurementData_t sample;
VoltageSensorActualValue_GetMeasurementData(&sample);
Logger_Print(sample);
} }

Wyświetl plik

@ -17,6 +17,12 @@ void UserInterface_Init()
GPIO_WriteLow(PORT_GPIO_LED, GPIO_LED_PINS); GPIO_WriteLow(PORT_GPIO_LED, GPIO_LED_PINS);
} }
void UserInterface_Tick()
{
}
void UserInterface_ShowMessage(UserInterface_Status status) void UserInterface_ShowMessage(UserInterface_Status status)
{ {
switch(status) switch(status)

Wyświetl plik

@ -9,18 +9,18 @@
#include "PinoutConfiguration.h" #include "PinoutConfiguration.h"
#include "UserInterface.h" #include "UserInterface.h"
#include "stm8s_i2c.h" #include "stm8s_i2c.h"
//#include "stm8s.h"
#define I2C_OWN_ADDRESS 0x10 #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 GPIO_setup(void);
static void I2C_setup(void); static void I2C_setup(void);
static uint8_t getRegisterValue(uint8_t registerId); static uint8_t getRegisterValue(uint8_t registerId);
void VoltageSensorActualValue_Init() void VoltageSensorActualValue_Init()
{ {
GPIO_setup(); GPIO_setup();
@ -30,9 +30,9 @@ void VoltageSensorActualValue_Init()
bool VoltageSensorActualValue_GetMeasurementData(VoltageSensorActualValue_MeasurementData_t *measurementData) bool VoltageSensorActualValue_GetMeasurementData(VoltageSensorActualValue_MeasurementData_t *measurementData)
{ {
measurementData = getRegisterValue(0x00); *measurementData = getRegisterValue(0x00);
if (measurementData == 0) if (*measurementData == 0)
{ {
// for temporary debug only // for temporary debug only
UserInterface_ShowMessage(USER_INTERFACE_COLLECTING_DATA_MSG); UserInterface_ShowMessage(USER_INTERFACE_COLLECTING_DATA_MSG);
@ -70,7 +70,7 @@ uint8_t getRegisterValue(uint8_t registerId)
I2C_GenerateSTART(ENABLE); I2C_GenerateSTART(ENABLE);
while(!I2C_CheckEvent(I2C_EVENT_MASTER_MODE_SELECT)); 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)); while(!I2C_CheckEvent(I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));
I2C_SendData(registerId); I2C_SendData(registerId);
@ -82,6 +82,6 @@ uint8_t getRegisterValue(uint8_t registerId)
I2C_GenerateSTOP(ENABLE); I2C_GenerateSTOP(ENABLE);
while(I2C_GetFlagStatus(I2C_FLAG_BUSBUSY)); while(I2C_GetFlagStatus(I2C_FLAG_BUSBUSY));
return registerValue; return registerValue;
} }

Wyświetl plik

@ -6,3 +6,4 @@
*/ */
#include "VoltageSensorPeakValue.h" #include "VoltageSensorPeakValue.h"

Wyświetl plik

@ -102,7 +102,7 @@ $(IHX): $(SRCS)/$(TARGET).c \
$(BUILD_DIR)/stm8s_tim1.rel \ $(BUILD_DIR)/stm8s_tim1.rel \
$(BUILD_DIR)/stm8s_it.rel \ $(BUILD_DIR)/stm8s_it.rel \
$(BUILD_DIR)/Logger.rel \ $(BUILD_DIR)/Logger.rel \
$(BUILD_DIR)/VoltageSensorPeakValue.rel $(BUILD_DIR)/VoltageSensorPeakValue.rel \
$(BUILD_DIR)/MeasurementCollector.rel $(BUILD_DIR)/MeasurementCollector.rel
$(CC) $(CFLAGS) $(LDFLAGS) -o $(BUILD_DIR)/ $< \ $(CC) $(CFLAGS) $(LDFLAGS) -o $(BUILD_DIR)/ $< \
@ -119,7 +119,7 @@ $(IHX): $(SRCS)/$(TARGET).c \
$(BUILD_DIR)/ClockConfigurator.rel \ $(BUILD_DIR)/ClockConfigurator.rel \
$(BUILD_DIR)/TimerConfigurator.rel \ $(BUILD_DIR)/TimerConfigurator.rel \
$(BUILD_DIR)/stm8s_tim1.rel \ $(BUILD_DIR)/stm8s_tim1.rel \
$(BUILD_DIR)/VoltageSensorPeakValue.rel $(BUILD_DIR)/VoltageSensorPeakValue.rel \
$(BUILD_DIR)/MeasurementCollector.rel $(BUILD_DIR)/MeasurementCollector.rel
$(SIZE) $@ $(SIZE) $@