kopia lustrzana https://github.com/RobertGawron/IonizationChamber
logging semi-dummy adc readings to uart
rodzic
40a319723c
commit
f82d2862d5
|
|
@ -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_ */
|
||||
|
|
|
|||
|
|
@ -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_ */
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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_ */
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ void ApplicationBuilder_Init()
|
|||
UserInterface_Init();
|
||||
VoltageSensorActualValue_Init();
|
||||
MeasurementCollector_Init();
|
||||
|
||||
|
||||
enableInterrupts();
|
||||
|
||||
// UserInterface_ShowMessage(USER_INTERFAE_STATE_OK_MSG);
|
||||
|
|
|
|||
|
|
@ -6,30 +6,28 @@
|
|||
*/
|
||||
|
||||
#include "Logger.h"
|
||||
//#include <stdio.h>
|
||||
|
||||
#define USE_PRINTF
|
||||
#if defined USE_PRINTF
|
||||
#include <stdio.h>
|
||||
#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);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,3 +6,4 @@
|
|||
*/
|
||||
|
||||
#include "VoltageSensorPeakValue.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -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) $@
|
||||
|
|
|
|||
Ładowanie…
Reference in New Issue