Compare commits
9 Commits
works_so_f
...
master
Author | SHA1 | Date | |
---|---|---|---|
c1c0d33358 | |||
44bf85a800 | |||
68ae71db28 | |||
2b89c9736b | |||
18d32c860e | |||
33a6a88cc2 | |||
8867d95837 | |||
6c832eeb88 | |||
d6affd7230 |
2
.project
2
.project
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>MSP430test</name>
|
||||
<name>MBusLightSensor</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
|
43
src/adc.cpp
Normal file
43
src/adc.cpp
Normal file
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* adc.cpp
|
||||
*
|
||||
* Created on: 03.10.2014
|
||||
* Author: wn
|
||||
*/
|
||||
|
||||
#include <msp430g2553.h>
|
||||
#include <isr_compat.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "adc.h"
|
||||
|
||||
|
||||
|
||||
void adcInit() {
|
||||
ADC10CTL0 = ADC10SHT_2 | ADC10SR | REFON | REF2_5V | ADC10ON;
|
||||
ADC10CTL1 = INCH_5;
|
||||
ADC10AE0 = BIT5;
|
||||
}
|
||||
|
||||
uint16_t adcGet() {
|
||||
uint16_t res = 0xffff;
|
||||
|
||||
ADC10CTL0 |= ENC | ADC10SC;
|
||||
|
||||
uint32_t timeOut = ADC_TIME_OUT;
|
||||
|
||||
while (1) {
|
||||
timeOut--;
|
||||
if (timeOut == 0)
|
||||
break;
|
||||
|
||||
if ((ADC10CTL0 & ADC10IFG) != 0) {
|
||||
res = ADC10MEM;
|
||||
ADC10CTL0 &= ~(ADC10IFG | ENC);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
22
src/adc.h
Normal file
22
src/adc.h
Normal file
@ -0,0 +1,22 @@
|
||||
/*
|
||||
* adc.h
|
||||
*
|
||||
* Created on: 03.10.2014
|
||||
* Author: wn
|
||||
*/
|
||||
|
||||
#ifndef ADC_H_
|
||||
#define ADC_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
const uint32_t ADC_TIME_OUT = 100000;
|
||||
|
||||
|
||||
void adcInit();
|
||||
uint16_t adcGet();
|
||||
|
||||
|
||||
|
||||
#endif /* ADC_H_ */
|
@ -14,10 +14,12 @@
|
||||
#include "time.h"
|
||||
#include "meterBusClient.h"
|
||||
#include "debug.h"
|
||||
#include "adc.h"
|
||||
#include "uptime.h"
|
||||
|
||||
|
||||
MeterBusClient meterBusClient;
|
||||
|
||||
Uptime uptime;
|
||||
|
||||
int main() {
|
||||
WDTCTL = WDTPW | WDTHOLD;
|
||||
@ -25,9 +27,10 @@ int main() {
|
||||
|
||||
debugInit();
|
||||
uartInit();
|
||||
adcInit();
|
||||
timeInit();
|
||||
|
||||
meterBusClient.begin();
|
||||
meterBusClient.begin(&uptime);
|
||||
|
||||
__enable_interrupt();
|
||||
|
||||
@ -36,6 +39,7 @@ int main() {
|
||||
while (1) {
|
||||
// __bis_status_register(LPM0_bits);
|
||||
meterBusClient.exec();
|
||||
uptime.exec();
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -23,9 +23,10 @@ MeterBusClient::MeterBusClient() : m_address(0),
|
||||
|
||||
|
||||
|
||||
void MeterBusClient::begin() {
|
||||
void MeterBusClient::begin(Uptime *uptime) {
|
||||
// setAddress(Config::getUChar(Config::METERBUSCLIENT_ADDRESS));
|
||||
setAddress(0x22);
|
||||
setAddress(0x53);
|
||||
m_uptime = uptime;
|
||||
}
|
||||
|
||||
void MeterBusClient::setAddress(unsigned char a) {
|
||||
@ -132,7 +133,7 @@ bool MeterBusClient::handleFrame() {
|
||||
|
||||
typedef enum {
|
||||
STATE_START, STATE_IDLE, STATE_SHORT_FRAME, STATE_LONG_CTRL_FRAME, STATE_HANDLE, STATE_INVALID, STATE_DONE,
|
||||
STATE_DELAYED_RESPONSE, STATE_DELAY, STATE_RESPONSE, STATE_RECEIVE_ECHO
|
||||
STATE_DELAYED_RESPONSE, STATE_DELAY, STATE_RECEIVE_ECHO
|
||||
} e_meterBusClientState;
|
||||
|
||||
typedef enum {
|
||||
|
@ -8,7 +8,7 @@
|
||||
#ifndef METERBUSCLIENT_H_
|
||||
#define METERBUSCLIENT_H_
|
||||
|
||||
|
||||
#include "uptime.h"
|
||||
|
||||
|
||||
|
||||
@ -52,9 +52,11 @@ struct MeterBusFrame {
|
||||
class MeterBusClient {
|
||||
public:
|
||||
MeterBusClient();
|
||||
void begin();
|
||||
void begin(Uptime *uptime);
|
||||
void exec();
|
||||
private:
|
||||
Uptime *m_uptime;
|
||||
|
||||
unsigned char m_address;
|
||||
void setAddress(unsigned char address);
|
||||
unsigned char getAddress();
|
||||
|
@ -7,6 +7,8 @@
|
||||
|
||||
#include "meterBusClient.h"
|
||||
#include "stdint.h"
|
||||
#include "adc.h"
|
||||
|
||||
|
||||
void MeterBusClient::aSB(unsigned char v) {
|
||||
m_sendBuffer[m_sendBufferLen] = v;
|
||||
@ -106,6 +108,41 @@ void MeterBusClient::REQ_UD2() {
|
||||
aSB((unsigned int)0); // Signatur
|
||||
|
||||
|
||||
// Uptime
|
||||
// DIF
|
||||
aSB((unsigned char)0x01);
|
||||
// VIF
|
||||
aSB((unsigned char)0x24);
|
||||
aSB(m_uptime->getSeconds());
|
||||
|
||||
// DIF
|
||||
aSB((unsigned char)0x01);
|
||||
// VIF
|
||||
aSB((unsigned char)0x25);
|
||||
aSB(m_uptime->getMinutes());
|
||||
|
||||
// DIF
|
||||
aSB((unsigned char)0x01);
|
||||
// VIF
|
||||
aSB((unsigned char)0x26);
|
||||
aSB(m_uptime->getHours());
|
||||
|
||||
// DIF
|
||||
aSB((unsigned char)0x02);
|
||||
// VIF
|
||||
aSB((unsigned char)0x27);
|
||||
aSB((unsigned int)m_uptime->getDays());
|
||||
|
||||
|
||||
// Measurement Value
|
||||
// DIF
|
||||
aSB((uint8_t)0x02);
|
||||
aSB((uint8_t)0x7f);
|
||||
|
||||
uint16_t measVal = adcGet();
|
||||
aSB(measVal);
|
||||
|
||||
//aSB((uint16_t) 0xaffe);
|
||||
|
||||
aSB(calcSendChecksum());
|
||||
aSB((unsigned char)0x16);
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include <isr_compat.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "time.h"
|
||||
|
||||
|
||||
volatile unsigned long timestamp;
|
||||
@ -47,3 +48,4 @@ void timeInit() {
|
||||
unsigned long millis() {
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
|
@ -14,4 +14,6 @@ void timeInit();
|
||||
unsigned long millis();
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /* TIME_H_ */
|
||||
|
@ -27,16 +27,16 @@ static inline void disableDataRegisterEmptyInterrupt() {
|
||||
void uartInit() {
|
||||
UCA0CTL1 |= UCSWRST;
|
||||
|
||||
P1SEL = BIT1 + BIT2;
|
||||
P1SEL2 = BIT1 + BIT2;
|
||||
P1SEL = BIT1 + BIT2; // select secondary function TX, RX
|
||||
P1SEL2 = BIT1 + BIT2; // dti
|
||||
|
||||
UCA0CTL0 |= UCPEN | UCPAR; // even parity
|
||||
UCA0CTL1 |= UCSSEL0; // ACLK
|
||||
|
||||
UCA0BR0 = 13;
|
||||
UCA0BR0 = 13; // divider for 2400@32768
|
||||
UCA0BR1 = 0;
|
||||
|
||||
UCA0MCTL = UCBRS1 | UCBRS2;
|
||||
UCA0MCTL = UCBRS1 | UCBRS2; // modulator for 2400@32768
|
||||
|
||||
UCA0CTL1 &= ~UCSWRST;
|
||||
|
||||
|
38
src/uptime.cpp
Normal file
38
src/uptime.cpp
Normal file
@ -0,0 +1,38 @@
|
||||
|
||||
#include "uptime.h"
|
||||
#include "time.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Uptime::Uptime() : m_seconds(0), m_minutes(0), m_hours(0), m_days(0) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Uptime::exec() {
|
||||
static unsigned long lastMillis = 0;
|
||||
|
||||
|
||||
unsigned long currentMillis = millis();
|
||||
if (currentMillis >= (lastMillis + 1000)) {
|
||||
m_seconds += ((currentMillis - lastMillis) / 1000);
|
||||
if (m_seconds >= 60) {
|
||||
m_seconds -= 60;
|
||||
m_minutes++;
|
||||
if (m_minutes >= 60) {
|
||||
m_minutes -= 60;
|
||||
m_hours++;
|
||||
if (m_hours >= 24) {
|
||||
m_hours -= 24;
|
||||
m_days++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
lastMillis = currentMillis;
|
||||
}
|
||||
|
||||
}
|
27
src/uptime.h
Normal file
27
src/uptime.h
Normal file
@ -0,0 +1,27 @@
|
||||
#ifndef UPTIME_H_
|
||||
#define UPTIME_H_
|
||||
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
class Uptime;
|
||||
|
||||
|
||||
|
||||
class Uptime {
|
||||
public:
|
||||
Uptime();
|
||||
void exec();
|
||||
uint8_t getSeconds() { return m_seconds; };
|
||||
uint8_t getMinutes() { return m_minutes; };
|
||||
uint8_t getHours() { return m_hours; };
|
||||
uint16_t getDays() { return m_days; };
|
||||
private:
|
||||
uint8_t m_seconds;
|
||||
uint8_t m_minutes;
|
||||
uint8_t m_hours;
|
||||
uint16_t m_days;
|
||||
};
|
||||
|
||||
|
||||
#endif /* TEST_H_ */
|
Reference in New Issue
Block a user