Rev 156 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 156 | Rev 167 | ||
|---|---|---|---|
| Line 25... | Line 25... | ||
| 25 | 25 | ||
| 26 | #include <onewire.h> |
26 | #include <onewire.h> |
| 27 | #include <ds18x20.h> |
27 | #include <ds18x20.h> |
| 28 | 28 | ||
| 29 | #include <delay.h> |
29 | #include <delay.h> |
| - | 30 | #include <inttypes.h> |
|
| 30 | 31 | ||
| 31 | - | ||
| - | 32 | #include <eqlazer_funcdefs.h> |
|
| 32 | 33 | ||
| 33 | #define MAXSENSORS 4 |
34 | #define MAXSENSORS 4 |
| 34 | 35 | ||
| 35 | uint8_t gSensorIDs[MAXSENSORS][OW_ROMCODE_SIZE]; |
36 | uint8_t gSensorIDs[MAXSENSORS][OW_ROMCODE_SIZE]; |
| 36 | 37 | ||
| Line 65... | Line 66... | ||
| 65 | nSensors++; |
66 | nSensors++; |
| 66 | } |
67 | } |
| 67 | 68 | ||
| 68 | return nSensors; |
69 | return nSensors; |
| 69 | } |
70 | } |
| 70 | - | ||
| 71 | 71 | ||
| 72 | 72 | ||
| 73 | /*----------------------------------------------------------------------------- |
73 | /*----------------------------------------------------------------------------- |
| 74 | * Main Program |
74 | * Main Program |
| 75 | *---------------------------------------------------------------------------*/ |
75 | *---------------------------------------------------------------------------*/ |
| 76 | int main(void) { |
76 | int main(void) { |
| 77 | uint8_t nSensors, i; |
77 | uint8_t nSensors, i; |
| 78 | uint8_t subzero, cel, cel_frac_bits; |
78 | uint8_t subzero, cel, cel_frac_bits; |
| 79 | 79 | ||
| 80 | Timebase_Init(); |
80 | Timebase_Init(); |
| 81 | Serial_Init(); |
81 | Serial_Init(); |
| 82 | sei(); |
82 | sei(); |
| 83 | 83 | ||
| 84 | printf( "\nDS18X20 1-Wire-Reader\n" ); |
84 | printf( "\nDS18X20 1-Wire-Reader\n" ); |
| Line 103... | Line 103... | ||
| 103 | if (Can_Init() != CAN_OK) { |
103 | if (Can_Init() != CAN_OK) { |
| 104 | printf("FAILED!\n"); |
104 | printf("FAILED!\n"); |
| 105 | } |
105 | } |
| 106 | else { |
106 | else { |
| 107 | printf("OK!\n"); |
107 | printf("OK!\n"); |
| 108 | } |
108 | } |
| 109 | 109 | ||
| 110 | uint32_t timeStamp = 0; |
110 | uint32_t timeStamp = 0; |
| 111 | 111 | ||
| 112 | Can_Message_t txMsg; |
112 | Can_Message_t txMsg; |
| 113 | Can_Message_t rxMsg; |
113 | Can_Message_t rxMsg; |
| 114 | 114 | ||
| 115 | txMsg.DataLength = 2; |
115 | txMsg.DataLength = 2; |
| 116 | txMsg.Id = |
116 | txMsg.Id = 0; |
| 117 | txMsg.RemoteFlag = 0; |
117 | txMsg.RemoteFlag = 0; |
| 118 | txMsg.ExtendedFlag = 1; |
118 | txMsg.ExtendedFlag = 1; |
| - | 119 | ||
| - | 120 | // txMsg.Id = txMsg.Id | NODE_SENSOR_1 | (NID << 9) | (FUNCC_SENSORS_TEMPERATURE_INSIDE << 15) | (FUNCT_SENSORS << 25); |
|
| - | 121 | // txMsg.Id = 0x02010A0F; |
|
| 119 | 122 | ||
| 120 | /* main loop */ |
123 | /* main loop */ |
| 121 | while (1) { |
124 | while (1) { |
| 122 | /* service the CAN routines */ |
125 | /* service the CAN routines */ |
| 123 | Can_Service(); |
126 | Can_Service(); |
| 124 | 127 | ||
| 125 | /* check if any messages have been received */ |
128 | /* check if any messages have been received */ |
| 126 | while (Can_Receive(&rxMsg) == CAN_OK) { |
129 | while (Can_Receive(&rxMsg) == CAN_OK) { |
| 127 |
|
130 | /* printf("MSG Received: ID=%lx, DLC=%u, EXT=%u, RTR=%u, ", rxMsg.Id, (uint16_t)(rxMsg.DataLength), (uint16_t)(rxMsg.ExtendedFlag), (uint16_t)(rxMsg.RemoteFlag)); |
| 128 | printf("data={ "); |
131 | printf("data={ "); |
| 129 | for (uint8_t i=0; i<rxMsg.DataLength; i++) { |
132 | for (uint8_t i=0; i<rxMsg.DataLength; i++) { |
| 130 | printf("%x ", rxMsg.Data.bytes[i]); |
133 | printf("%x ", rxMsg.Data.bytes[i]); |
| 131 | } |
134 | } |
| 132 | printf("}\n"); |
135 | printf("}\n"); |
| 133 |
|
136 | */ } |
| 134 | 137 | ||
| 135 | /* check temperature and send on CAN once every other second */ |
138 | /* check temperature and send on CAN once every other second */ |
| 136 | if (Timebase_PassedTimeMillis(timeStamp) >= 2000) { |
139 | if (Timebase_PassedTimeMillis(timeStamp) >= 2000) { |
| 137 | timeStamp = Timebase_CurrentTime(); |
140 | timeStamp = Timebase_CurrentTime(); |
| 138 | 141 | ||
| 139 | if ( DS18X20_start_meas( DS18X20_POWER_PARASITE, NULL ) == DS18X20_OK) { |
142 | if ( DS18X20_start_meas( DS18X20_POWER_PARASITE, NULL ) == DS18X20_OK) { |
| 140 | printf("Measuring temperature... "); |
143 | printf("Measuring temperature... \n"); |
| 141 | delay_ms(DS18B20_TCONV_12BIT); |
144 | delay_ms(DS18B20_TCONV_12BIT); |
| 142 | for ( i=0; i<nSensors; i++ ) { |
145 | for ( i=0; i<nSensors; i++ ) { |
| 143 | if ( DS18X20_read_meas( &gSensorIDs[i][0], &subzero, |
146 | if ( DS18X20_read_meas( &gSensorIDs[i][0], &subzero, |
| 144 | &cel, &cel_frac_bits) == DS18X20_OK ) { |
147 | &cel, &cel_frac_bits) == DS18X20_OK ) { |
| 145 | 148 | ||
| 146 | //txMsg.Data.bytes[0] = subzero; |
149 | //txMsg.Data.bytes[0] = subzero; |
| 147 | if (subzero) { |
150 | if (subzero) { |
| - | 151 | txMsg.Data.bytes[0] = -cel; |
|
| - | 152 | } else { |
|
| - | 153 | txMsg.Data.bytes[0] = cel; |
|
| - | 154 | } |
|
| - | 155 | /* if (subzero) { |
|
| 148 | txMsg.Data.bytes[i*2] = -cel; |
156 | txMsg.Data.bytes[i*2] = -cel; |
| 149 | } else { |
157 | } else { |
| 150 | txMsg.Data.bytes[i*2] = cel; |
158 | txMsg.Data.bytes[i*2] = cel; |
| 151 | } |
159 | } |
| 152 |
|
160 | */ //hur göra med decimaldelen??? |
| - | 161 | txMsg.Data.bytes[1] = (cel_frac_bits<<4); |
|
| 153 |
|
162 | // txMsg.Data.bytes[i*2+1] = (cel_frac_bits<<4); |
| 154 | 163 | if(i==0){ // freezer |
|
| - | 164 | txMsg.Id = 0x02020A0F; |
|
| - | 165 | // printf("freezer\n"); |
|
| - | 166 | }else if(i==1){ // outside |
|
| - | 167 | txMsg.Id = 0x0201FA0F; |
|
| - | 168 | // printf("outside\n"); |
|
| - | 169 | }else if(i==2){ // inside |
|
| - | 170 | txMsg.Id = 0x02010A0F; |
|
| - | 171 | // printf("inside\n"); |
|
| - | 172 | }else{ |
|
| - | 173 | txMsg.Id = 0x00000003; |
|
| - | 174 | } |
|
| - | 175 | ||
| - | 176 | printf("sending...\n"); |
|
| - | 177 | Can_Send(&txMsg); |
|
| 155 | } |
178 | } |
| 156 | else printf("CRC Error (lost connection?)\n"); |
179 | else printf("CRC Error (lost connection?)\n"); |
| 157 | } |
180 | } |
| 158 | } |
181 | } |
| 159 | else printf("Start meas. failed (short circuit?)\n"); |
182 | else printf("Start meas. failed (short circuit?)\n"); |
| 160 | 183 | ||
| 161 |
|
184 | // txMsg.DataLength = nSensors*2; |
| 162 |
|
185 | // printf("sending...\n"); |
| 163 | /* send txMsg */ |
186 | /* send txMsg */ |
| 164 |
|
187 | // Can_Send(&txMsg); |
| 165 | } |
188 | } |
| 166 | } |
189 | } |
| 167 | 190 | ||
| 168 | return 0; |
191 | return 0; |
| 169 | } |
192 | } |