Show
Ignore:
Timestamp:
01/03/10 11:19:00 (15 years ago)
Author:
phil
Message:

first round now works

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • webserver/example/EnergyMeters/Source/EnergyMeters/SolarCountUART.c

    r34 r35  
    55// Pin I/O LED Control Maskbit 
    66#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 
    98 
    109#define RX_UART3_BUF_SIZE 100 
     
    3837const unsigned char init1_rsp[] = "\x02\xf0\xb0\x08\x00\x84\x09\x0c\x04\x0a\x26\x86\xcd\x00\x03"; /* exp. init seq response */ 
    3938const 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 */ 
    4040 
    4141 
     
    5050 
    5151const 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[] 
    5253 
    5354const 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[] 
     
    8990 
    9091 
     92void RXD_RS485(void) 
     93{ 
     94  IOCLR1 = DIR_RS485;           // RS485 Direction = 0 (Receive) 
     95} /* RXD_RS485 */ 
     96 
     97void TXD_RS485(void)  
     98{ 
     99  delay(500000); 
     100  IOSET1 = DIR_RS485;           // RS485 Direction = 1 (Transmit) 
     101} /* TXD_RS485 */ 
     102 
     103 
    91104 
    92105void testUART3(void) 
     
    256269  { 
    257270    case SOL_NO_INIT: 
     271      delay(500000); 
    258272      init_serial3(); 
    259273      resetUart3RxBuf(); /* init */ 
     
    261275 
    262276      TXD_RS485(); 
     277      delay(500000); 
    263278       /* send init 1 */ 
    264279      send_uart3((unsigned char *)init1, sizeof(init1)); 
     
    317332        break; 
    318333      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 */ 
    321335        solarState = SOL_FINISHED; 
    322336        break; 
     
    327341     if (solarState != SOL_FINISHED) 
    328342     { 
    329       solarState = SOL_CHAN_WAIT_REPLY; 
     343      solarState = SOL_CHAN_WAIT_REPLY; /* wait for reply if not finished */ 
    330344     } /* if */ 
    331345    break; 
     
    373387        { 
    374388          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 */; 
    376390        } /* 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 
    384410      } 
    385411      else 
     
    495521void delay(unsigned long int count1) 
    496522{ 
    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         
    498526} 
    499527