summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.cpp27
-rw-r--r--rcc.cpp3
2 files changed, 28 insertions, 2 deletions
diff --git a/main.cpp b/main.cpp
index c95731f..35ccbb2 100644
--- a/main.cpp
+++ b/main.cpp
@@ -63,7 +63,25 @@ I2C i2c;
ITG3200 gyro(i2c);
BMA150 accel(i2c);
+volatile uint16_t dmabuf[2];
void threadmain() {
+ ADC1.CR2 = 0x9;
+ while(ADC1.CR2 & 0x8);
+ ADC1.CR2 = 0x5;
+ while(ADC1.CR2 & 0x4);
+
+ DMA1.CH[0].CMAR = (uint32_t)&dmabuf;
+ DMA1.CH[0].CPAR = (uint32_t)&ADC1.DR;
+ DMA1.CH[0].CNDTR = 2;
+ DMA1.CH[0].CCR = 0x05a1;
+
+ ADC1.SMPR2 = 0x003f000;
+ ADC1.SQR1 = 0x100000;
+ ADC1.SQR3 = 5 | (4 << 5);
+ ADC1.CR1 = 0x100;
+ ADC1.CR2 = 0x103;
+ ADC1.CR2 = 0x103;
+
while(1) {
uint16_t buf[] = {
gyro.x,
@@ -72,6 +90,8 @@ void threadmain() {
accel.x,
accel.y,
accel.z,
+ dmabuf[0],
+ dmabuf[1],
};
xbee_send(1, sizeof(buf), (uint8_t*)buf);
@@ -107,13 +127,16 @@ int main() {
RCC.enable(RCC.IOPA);
RCC.enable(RCC.IOPB);
- GPIOA.CRL = 0x4444bbbb;
+ GPIOA.CRL = 0x4400bbbb;
GPIOA.CRH = 0x444444b4;
GPIOB.CRL = 0xff444434;
GPIOB.CRH = 0x44444444;
GPIOB.ODR = 1 << 1;
+ RCC.enable(RCC.DMA1);
+ RCC.enable(RCC.ADC1);
+
// Give all hardware enough time to initialize.
Time::sleep(100);
@@ -144,7 +167,7 @@ int main() {
gps.enable();
thread.start();
- gps_thread.start();
+ //gps_thread.start();
while(1) {
// Wait for a new update.
diff --git a/rcc.cpp b/rcc.cpp
index 79bbc69..e3ae38d 100644
--- a/rcc.cpp
+++ b/rcc.cpp
@@ -20,4 +20,7 @@ void rcc_init() {
// Set APB1 prescaler to /2.
RCC.CFGR |= 0x400;
+
+ // Set ADCCLK prescaler to /6.
+ RCC.CFGR |= 0x8000;
}