Changeset 35 for webserver/example/EnergyMeters/Source
- Timestamp:
- 01/03/10 11:19:00 (15 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
webserver/example/EnergyMeters/Source/EnergyMeters/SolarCountUART.c
r34 r35 5 5 // Pin I/O LED Control Maskbit 6 6 #define DIR_RS485 0x00080000 // P1.19(0000 0000 0000 x000 0000 0000 0000 0000) 7 #define RXD_RS485() IOCLR1 = DIR_RS485 // RS485 Direction = 0 (Receive) 8 #define TXD_RS485() IOSET1 = DIR_RS485 // RS485 Direction = 1 (Transmit) 7 9 8 10 9 #define RX_UART3_BUF_SIZE 100 … … 38 37 const unsigned char init1_rsp[] = "\x02\xf0\xb0\x08\x00\x84\x09\x0c\x04\x0a\x26\x86\xcd\x00\x03"; /* exp. init seq response */ 39 38 const unsigned char init1_r_m[] = "\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff"; /* exp. init seq response mask */ 39 /* init1_r_m: response after first init: \x02\xf0\xb0\x08 , later: \x02\xf0\xb0\x09 */ 40 40 41 41 … … 50 50 51 51 const unsigned char init_after_all_chan[] = "\x02\xb0\xf0\x04\x00\x21\x00\xcc\x35\x03"; // send to SC after all channels have been scanned 52 // ^^ equals init1[] 52 53 53 54 const unsigned char init_after_all_chan_rsp[] = "\x02\xf0\xb0\x09\x00\xa1\xfd\x03\x00\x00\x00\x00\x07\x21\x03"; // response from SC to init_after_all_chan[] … … 89 90 90 91 92 void RXD_RS485(void) 93 { 94 IOCLR1 = DIR_RS485; // RS485 Direction = 0 (Receive) 95 } /* RXD_RS485 */ 96 97 void TXD_RS485(void) 98 { 99 delay(500000); 100 IOSET1 = DIR_RS485; // RS485 Direction = 1 (Transmit) 101 } /* TXD_RS485 */ 102 103 91 104 92 105 void testUART3(void) … … 256 269 { 257 270 case SOL_NO_INIT: 271 delay(500000); 258 272 init_serial3(); 259 273 resetUart3RxBuf(); /* init */ … … 261 275 262 276 TXD_RS485(); 277 delay(500000); 263 278 /* send init 1 */ 264 279 send_uart3((unsigned char *)init1, sizeof(init1)); … … 317 332 break; 318 333 case 6: 319 /* we are through with all the channels, send the final init */ 320 send_uart3((unsigned char *)init_after_all_chan, sizeof(init_after_all_chan)); 334 /* we are through with all the channels, ready to send next init for next query round */ 321 335 solarState = SOL_FINISHED; 322 336 break; … … 327 341 if (solarState != SOL_FINISHED) 328 342 { 329 solarState = SOL_CHAN_WAIT_REPLY; 343 solarState = SOL_CHAN_WAIT_REPLY; /* wait for reply if not finished */ 330 344 } /* if */ 331 345 break; … … 373 387 { 374 388 chanVolt[currentChannel] = rxUART3[11]; 375 chanWatt[currentChannel] = (int) rxUART3[7] | (((int)(rxUART3[6])) << 8) /* index 7: LSB, index 6: MSB */;389 chanWatt[currentChannel] = (int)(rxUART3[7]) | (((int)(rxUART3[8])) << 8) /* index 7: LSB, index 8: MSB */; 376 390 } /* if */ 377 /* finally, discard data from buffer */ 378 resetUart3RxBuf(); 379 380 /* switch to next channel */ 381 currentChannel++; 382 /* now ready to query channel data for next channel */ 383 solarState = SOL_CHAN; 391 392 if (currentChannel != 6) 393 { 394 /* we received input from channel 0 to 5 */ 395 396 /* finally, discard data from buffer */ 397 resetUart3RxBuf(); 398 399 /* switch to next channel */ 400 currentChannel++; 401 /* now ready to query channel data for next channel */ 402 solarState = SOL_CHAN; 403 } 404 else 405 { 406 /* we received the finishing sequence */ 407 solarState = SOL_NO_INIT; /* restart the measurement cycle */ 408 } 409 384 410 } 385 411 else … … 495 521 void delay(unsigned long int count1) 496 522 { 497 while(count1 > 0) {count1--;} // Loop Decrease Counter 523 volatile unsigned long int countVol; 524 countVol = count1; 525 while(countVol > 0) {countVol--;} // Loop Decrease Counter 498 526 } 499 527