adc stuff
This commit is contained in:
parent
6c832eeb88
commit
8867d95837
2
.project
2
.project
@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<projectDescription>
|
<projectDescription>
|
||||||
<name>MSP430test</name>
|
<name>MBusLightSensor</name>
|
||||||
<comment></comment>
|
<comment></comment>
|
||||||
<projects>
|
<projects>
|
||||||
</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,6 +14,7 @@
|
|||||||
#include "time.h"
|
#include "time.h"
|
||||||
#include "meterBusClient.h"
|
#include "meterBusClient.h"
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
#include "adc.h"
|
||||||
|
|
||||||
|
|
||||||
MeterBusClient meterBusClient;
|
MeterBusClient meterBusClient;
|
||||||
@ -25,6 +26,7 @@ int main() {
|
|||||||
|
|
||||||
debugInit();
|
debugInit();
|
||||||
uartInit();
|
uartInit();
|
||||||
|
adcInit();
|
||||||
timeInit();
|
timeInit();
|
||||||
|
|
||||||
meterBusClient.begin();
|
meterBusClient.begin();
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
#include "meterBusClient.h"
|
#include "meterBusClient.h"
|
||||||
#include "stdint.h"
|
#include "stdint.h"
|
||||||
|
#include "adc.h"
|
||||||
|
|
||||||
void MeterBusClient::aSB(unsigned char v) {
|
void MeterBusClient::aSB(unsigned char v) {
|
||||||
m_sendBuffer[m_sendBufferLen] = v;
|
m_sendBuffer[m_sendBufferLen] = v;
|
||||||
@ -105,7 +106,8 @@ void MeterBusClient::REQ_UD2() {
|
|||||||
aSB(getStatus()); // Status
|
aSB(getStatus()); // Status
|
||||||
aSB((unsigned int)0); // Signatur
|
aSB((unsigned int)0); // Signatur
|
||||||
|
|
||||||
|
uint16_t measVal = adcGet();
|
||||||
|
aSB(measVal);
|
||||||
|
|
||||||
aSB(calcSendChecksum());
|
aSB(calcSendChecksum());
|
||||||
aSB((unsigned char)0x16);
|
aSB((unsigned char)0x16);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user