adc stuff

This commit is contained in:
hg 2014-10-03 16:09:57 +02:00
parent 6c832eeb88
commit 8867d95837
5 changed files with 71 additions and 2 deletions

View File

@ -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
View 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
View 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_ */

View File

@ -14,6 +14,7 @@
#include "time.h"
#include "meterBusClient.h"
#include "debug.h"
#include "adc.h"
MeterBusClient meterBusClient;
@ -25,6 +26,7 @@ int main() {
debugInit();
uartInit();
adcInit();
timeInit();
meterBusClient.begin();

View File

@ -7,6 +7,7 @@
#include "meterBusClient.h"
#include "stdint.h"
#include "adc.h"
void MeterBusClient::aSB(unsigned char v) {
m_sendBuffer[m_sendBufferLen] = v;
@ -105,7 +106,8 @@ void MeterBusClient::REQ_UD2() {
aSB(getStatus()); // Status
aSB((unsigned int)0); // Signatur
uint16_t measVal = adcGet();
aSB(measVal);
aSB(calcSendChecksum());
aSB((unsigned char)0x16);