Hi everyone,
I have been working on this for about a week, looking at examples from
all over the place and pouring through datasheets, but I cannot get this
to work(or many ARM Features for that matter)
I have worked with AVRs for a while and I love them, but I wanted to
move up to ARM. I know a reasonable amount of C, and no assembler. I
don't really want to get this example working as much as I want to learn
what im not doing right. I really want to learn how to be able to do
ARM programs on my own and not rely on forums to help me, so any
tutorials or books would be greatly appreciated.
So, I am trying to get the ADC working so it will print the 10-bit value
of ADC0.3 over uart0 at 19200 baud. Here is my code:
1 | #include "LPC214x.h"
|
2 |
|
3 | #define ADC_CLK 1000000 /* set to 1Mhz */
|
4 |
|
5 | #include "serial.h"
|
6 | #include "rprintf.h"
|
7 | #include "target.h"
|
8 |
|
9 | void delay_ms(int x);
|
10 |
|
11 | int main(void)
|
12 | {
|
13 | init_serial0(19200);
|
14 | rprintf_devopen(putc_serial0);
|
15 | rprintf("Hello!\n\n");
|
16 |
|
17 | PINSEL0 = 0x10000000;
|
18 |
|
19 | AD0CR = (0x01 << 0) |
|
20 | (1 << 3) | //Turn analog 3 on
|
21 | (( Fpclk / ADC_CLK - 1 ) << 8) |
|
22 | (0 << 16) | // BURST = 0, no BURST, software controlled
|
23 | (0 << 17) | // CLKS = 000, 11 clocks/10 bits
|
24 | (0 << 18) | //^
|
25 | (0 << 19) | //^
|
26 | (1 << 21) | // PDN = 1, normal operation
|
27 | (0 << 22) | // TEST1:0 = 00
|
28 | (0 << 24); // START = 0 A/D conversion stops
|
29 |
|
30 | while(1) {
|
31 | AD0CR |= (1 << 24); //Start Conversion
|
32 | delay_ms(1); //Give it time to convert(I doubt this is necessary?)
|
33 | rprintf("%luH", ((AD0DR3 >> 6) & 0x000003ff) * 0x40);
|
34 | AD0CR &= (1 << 24); //Stop Conversion
|
35 | delay_ms(50);
|
36 | }
|
37 | }
|
38 |
|
39 | void delay_ms(int x)
|
40 | //Rough, not meant to be accurate
|
41 | {
|
42 | int a,b;
|
43 | for(a=0;a<x;a++){
|
44 | for(b=0;b<3000;b++);
|
45 | }
|
46 | }
|
And when I run the code this is all I get:
Any ideas for what I am doing wrong?
Thanks!