source: firmware/FSC/src/FSC.c@ 10094

Last change on this file since 10094 was 10094, checked in by neise, 12 years ago
initial commit of FSC firmware - use for FSC testing only -
File size: 4.4 KB
Line 
1//-----------------------------------------------------------------------------
2#include "typedefs.h"
3#include "application.h"
4#include "spare_outs.h"
5#include "spi_master.h"
6#include "ad7719_adc.h"
7#include "usart.h"
8#include "macros.h"
9#include "interpol.h"
10#include "w5100_spi_interface.h"
11#include <avr/interrupt.h>
12#include <avr/wdt.h>
13#include <stdlib.h>
14
15#include "tests.h"
16//-----------------------------------------------------------------------------
17
18int main(void)
19{
20// U08 IDN_STR[] = "16ch Pt1000 logger; firmware version of 07.11.10. DN"; // Identity string
21
22 spare_outs_init(); //set spare out pin I/O modes
23 app_init(); // Setup software modules
24 usart_init(); // Initialize serial interface
25 spi_init(); // Initialize SPI interface as master
26 adc_init(); // Initialize AD7719 ADC as SPI slave
27 // usart_write_crlf();
28 // usart_writeln_flash_str(IDN_STR); // Write string to USART interface
29 // usart_write_crlf();
30
31 // Enable interrupts
32 sei();
33
34
35 // temperature muxer pins init:
36 // SA - pins
37 DDRA |= 0x3F; // set all SA-pins as outputs
38
39
40 // voltage, current, humidity - muxer pins:
41 // SB - pins
42 DDRB |= 0x7F; // set all SB - pins as outputs
43
44 // SB - muxer test
45 DDRA |= 1<<PA6 ; // set D0-0 lina as output. for tests only !!!
46 PORTA |= 1<<PA6; // set D0-0 line high. for tests only !!!
47
48
49
50// Main loop
51//float temperature;
52float resistance;
53BOOL heartbeat_enable = TRUE;
54
55U08 SA_mux_val = 0;
56//U08 SB_mx_val = 0;
57while (TRUE)
58 {
59 // this heartbeat shows how long one single run of this while loop takes
60 // measure with a scope.
61 if (heartbeat_enable) PORTB ^= (1<<PB3); // toggle Out2_spare --> heartbeat
62
63 // if USART data arrives. i.e. data via USB
64 // the usart_rx_ready flag is set TRUE
65 // now process the incoming data which is stored in
66 // U08 usart_rx_buffer[USART_RX_BUFFER_SIZE]
67 // and tell the USART interface, it may receive new data
68 // by setting the usart_rx_ready flag FALSE again
69 ++SA_mux_val;
70 PORTA |= (SA_mux_val & 0x3F);
71
72 usart_write_str((pU08)"\tSA:");
73 usart_write_U08(SA_mux_val,2);
74 usart_write_str((pU08)"\t");
75 _delay_us(200);
76
77
78 if(ADC_IS_READY())
79 {
80 startconv(); //Start a new A/D Conversion
81 //temp = readandsendtemp();
82 //adcword = getadc();
83 resistance = getresistance();
84 //temperature = gettemp();
85 usart_write_str((pU08)"R:");
86 usart_write_float(resistance,3,4);
87 usart_write_str((pU08)"\t");
88 }
89 if(ADC_IS_READY())
90 {
91 startconv(); //Start a new A/D Conversion
92 //temp = readandsendtemp();
93 //adcword = getadc();
94 resistance = getresistance();
95 //temperature = gettemp();
96 usart_write_str((pU08)"R:");
97 usart_write_float(resistance,3,4);
98 usart_write_str((pU08)"\n");
99 }
100
101
102 /*
103 if ( usart_rx_ready == TRUE )
104 {
105 //understand what it means and react
106
107 switch (usart_rx_buffer[0])
108 {
109
110 case 'h':
111 {
112 // toggle the heartbeat mode on or off.
113 heartbeat_enable = !heartbeat_enable;
114 break;
115 }
116 case 'a':
117 {
118 // conduct adc - AD7719 SPI interface test
119
120 break;
121 }
122 case 'e':
123 {
124 // conduct ethernet module SPI interface test
125 strtol((char*) usart_rx_buffer+1, NULL, 0);
126 break;
127 }
128
129 default:
130 {
131 usart_write_str((pU08)"? you wrote: ");
132 usart_write_str((pU08)usart_rx_buffer);
133 usart_write_str((pU08)"\n");
134 break;
135 }
136 }
137
138 heartbeat_enable = !heartbeat_enable;
139 usart_rx_ready = FALSE;
140 }
141*/
142// das ist ein paar schritte zu früh.
143// erstmal müssen die interfaces getestet werden.
144/*
145
146 for (U08 i = 0; i<16; i++)
147 {
148
149 if((~PIND) & 0x08) // PD4 is #ADC_RDY input. Inverted logic! if PD4=0 this evaluates to true
150 {
151 PORTA = (PORTA & 0xF0) | ((i) & 0x0F); // switch muxer
152 startconv(); //Start a new A/D Conversion
153 //temp = readandsendtemp();
154 //adcword = getadc();
155 //resistance = getresistance();
156 temperature = gettemp();
157 usart_write_float(temperature,2,4);
158 usart_write_str((pU08)"\t");
159
160 } // end of if adc ready
161 else
162 {
163 i--;
164 }
165 } // end of for loop over 16 channels
166 usart_write_crlf();
167
168*/
169
170 } // end of infinite while loop
171} // end of main()
172
173
174
Note: See TracBrowser for help on using the repository browser.