Rev Author Line No. Line
2108 paro 1 // Oscilloscope firmware, Roman Pavelka, 2011
2 // written for atmega8
3  
4 #define F_CPU 16000000
5 #define BAUD 1000000
6 //#define MYUBRR F_CPU/8/BAUD-1
7 #define MYUBRR 1
8  
9 #include "./libs/usart.h"
10 #include "./libs/spi.h"
11  
12 #include <avr/io.h>
13 #include <avr/interrupt.h>
14 #include <util/delay.h>
15 #include <inttypes.h>
16  
17 #define LEN 100
18 uint8_t data[2*LEN];
19  
20 void measure(void);
21 void send(void);
22  
23  
24 int main (void) {
25 USART_Init(MYUBRR);
26  
27 DDRB = 0b00100100; //SCK, SS out
28 PORTB = 0b00000000; // CONV low
29  
30 SPI_MasterInit();
31  
32 sei();
33  
34 while(1) {}
35  
36 return 0;
37  
38 }
39  
40  
41 void measure(void) {
42 uint8_t i;
43  
44 for(i=0;i<LEN;i++) {
45 PORTB |= 0b00000100;
46 _delay_us(4);
47 PORTB &= 0b11111011; //one conversion
48  
49 data[2*i] = SPI_MasterTransmit(0x0);
50 data[2*i+1] = SPI_MasterTransmit(0x0);
51 }
52 }
53  
54 void send(void) {
55 uint8_t i;
56  
57 for(i=0;i<LEN;i++) {
58  
59 /* USART_Transmit_uint16(data[i]); //ASCII transfer
60 USART_Transmit('\n');*/
61  
62 USART_Transmit(data[2*i]); //Binary transfer
63 USART_Transmit(data[2*i+1]);
64 // USART_Transmit('\n');
65  
66 }
67 }
68  
69  
70 ISR(USART_RXC_vect) {
71 char data;
72  
73 data=UDR; //must be read to untrigger interupt
74  
75 if (data=='m') {
76 measure();
77 send();
78 }
79 }