Merge pull request #100 from RobertGawron/feature/basic_sw_components_implementation

Feature/basic sw components implementation
pull/101/head
Robert 2019-08-03 14:14:23 +02:00 zatwierdzone przez GitHub
commit 0d7b27d968
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
2 zmienionych plików z 33 dodań i 30 usunięć

Wyświetl plik

@ -7,7 +7,7 @@
#include "Logger.h" #include "Logger.h"
//#define USE_PRINTF #define USE_PRINTF
#if defined USE_PRINTF #if defined USE_PRINTF
#include <stdio.h> #include <stdio.h>
#endif #endif
@ -21,7 +21,7 @@ static void GPIO_setup(void);
static void UART1_setup(void); static void UART1_setup(void);
#if defined USE_PRINT #if defined USE_PRINTF
int putchar(int c) int putchar(int c)
#else #else
void putchar(char c) void putchar(char c)

Wyświetl plik

@ -9,34 +9,35 @@
#include "PinoutConfiguration.h" #include "PinoutConfiguration.h"
#include "UserInterface.h" #include "UserInterface.h"
#include "stm8s_i2c.h" #include "stm8s_i2c.h"
#include <stdio.h>
#define I2C_OWN_ADDRESS 0x10 #define I2C_OWN_ADDRESS 0x10
// MCP3425 I2C address is 0x68(104), this 7 bits, they need to be // 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 // shifted by one, to make 8 bits variable, where less signifant bit
// is used to signalize communication direction (rx or tx) // is used to signalize communication direction (rx or tx)
#define I2C_SLAVE_ADDRESS (0x68 << 1) #define I2C_SLAVE_ADDRESS (0x68u << 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 void write(uint8_t registerId);
static uint16_t read(uint8_t registerId);
void VoltageSensorActualValue_Init() void VoltageSensorActualValue_Init()
{ {
GPIO_setup(); GPIO_setup();
I2C_setup(); I2C_setup();
// seleect adc configuration and start measurement
write(0x00);
} }
bool VoltageSensorActualValue_GetMeasurementData(VoltageSensorActualValue_MeasurementData_t *measurementData) bool VoltageSensorActualValue_GetMeasurementData(VoltageSensorActualValue_MeasurementData_t *measurementData)
{ {
*measurementData = getRegisterValue(0x0); write(0x10);
*measurementData = read(0);
// read(0);
if (*measurementData == 0)
{
// for temporary debug only
UserInterface_ShowMessage(USER_INTERFACE_COLLECTING_DATA_MSG);
}
// getRegisterValue should return false on timeout and this should be later propagated to GUI component. // getRegisterValue should return false on timeout and this should be later propagated to GUI component.
return TRUE; return TRUE;
@ -63,10 +64,8 @@ void I2C_setup(void)
} }
uint8_t getRegisterValue(uint8_t registerId) static void write(uint8_t registerId)
{ {
uint8_t registerValue = 0xFF;
I2C_GenerateSTART(ENABLE); I2C_GenerateSTART(ENABLE);
while(!I2C_CheckEvent(I2C_EVENT_MASTER_MODE_SELECT)); while(!I2C_CheckEvent(I2C_EVENT_MASTER_MODE_SELECT));
@ -76,32 +75,36 @@ uint8_t getRegisterValue(uint8_t registerId)
I2C_SendData(registerId); I2C_SendData(registerId);
while(!I2C_CheckEvent(I2C_EVENT_MASTER_BYTE_TRANSMITTED)); while(!I2C_CheckEvent(I2C_EVENT_MASTER_BYTE_TRANSMITTED));
I2C_GenerateSTOP(ENABLE);
while(I2C_GetFlagStatus(I2C_FLAG_BUSBUSY));
}
static uint16_t read(uint8_t registerId)
// I2C_GenerateSTOP(ENABLE); {
// while(I2C_GetFlagStatus(I2C_FLAG_BUSBUSY));
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, I2C_DIRECTION_RX); I2C_Send7bitAddress(I2C_SLAVE_ADDRESS, I2C_DIRECTION_RX);
while(!I2C_CheckEvent(I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED)); while(!I2C_CheckEvent(I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED));
UserInterface_ShowMessage(USER_INTERFACE_COLLECTING_DATA_MSG); for(int i=0; i<4; i++)
{
while(!I2C_CheckEvent(I2C_EVENT_MASTER_BYTE_RECEIVED));
uint16_t registerMSB = I2C_ReceiveData();
printf("%d\n", registerMSB);
}
// while (!I2C_CheckEvent(I2C_EVENT_MASTER_BYTE_RECEIVED));
// uint16_t registerLSB = I2C_ReceiveData();
I2C_AcknowledgeConfig(DISABLE); I2C_AcknowledgeConfig(DISABLE);
I2C_GenerateSTOP(ENABLE); I2C_GenerateSTOP(ENABLE);
while(!I2C_CheckEvent(I2C_EVENT_MASTER_BYTE_RECEIVED));
registerValue = I2C_ReceiveData();
I2C_AcknowledgeConfig(ENABLE);
// I2C_GenerateSTOP(ENABLE);
// while(I2C_GetFlagStatus(I2C_FLAG_BUSBUSY)); // while(I2C_GetFlagStatus(I2C_FLAG_BUSBUSY));
uint16_t registerValue = 0;
return registerValue; return registerValue;
} }