Project

General

Profile

Revision 410

Added by Brad Neuman over 12 years ago

works for real this time! I haven't tried actually running a current through the board, but without that it shows proper debug values and Robot Debug/main.c formats them nicely!

View differences:

branches/autonomous_recharging/code/projects/autonomous_recharging/archs/Robot Debug/main.c
1 1
#include <dragonfly_lib.h>
2 2
#include <i2c.h>
3 3

  
4
volatile uint32_t byte;
5
volatile short code, next;
6

  
4 7
void recv(char i2c_byte){
5
	usb_putc(i2c_byte);
8
    static char str[8];
9

  
10
    if(code){
11
        if(next==0){
12
            byte = i2c_byte<<8; //get first byte in int
13
            next = 1;
14
        }
15
        else{
16
            byte |= i2c_byte; //get second byte in int
17
            itoa(byte,str,10);
18
            
19
            usb_puts(str);
20
            usb_putc('\t');
21
            
22
            if(code==2)
23
                usb_puts("\r\n"); //newline for easy to read output
24
            
25
            byte=0;
26
            code=0;
27
            next=0;
28
        }
29
    }
30
    else {
31
    
32
        //if the byte is a debug control then set code to 1, otherwise, print it
33
        switch(i2c_byte){
34
            case 'C':
35
            case 'P':
36
            case 'I':
37
            case 'V':
38
                code = 1;
39
                break;
40
            case 'T':
41
                code = 2; //T is last, put a newline after it
42
                break;
43
                
44
            default:
45
                usb_putc(i2c_byte);
46
                break;
47
        }
48
        
49
    }
6 50
}
7 51

  
8
int main(){
52
int main( void ){
9 53

  
10 54
	dragonfly_init(ALL_ON);
11 55
	sei();
56
    code = 0;
57
    byte = 0;
58
    next = 0;
12 59
	i2c_init(0x01, NULL, recv, NULL);
13 60
	
14 61
	usb_puts("init'd everything.\r\n");
branches/autonomous_recharging/code/projects/autonomous_recharging/archs/ConstantCharging.c
427 427
		tempData[0] = 'C';
428 428
		tempData[1] = abs_time>>8;
429 429
		tempData[2] = abs_time&0xFF;
430
        delay_ms(50);
430 431
		i2c_putpacket(0x01, tempData, 3);
432
        delay_ms(50);
431 433
#endif
432 434
		
433 435
		mod=abs_time%4;
......
485 487
		tempData[0] = 'P';
486 488
		tempData[1] = 0;
487 489
		tempData[2] = OCR1B;
490
        delay_ms(50);
488 491
		i2c_putpacket(0x01, tempData, 3);
492
        delay_ms(50);
489 493
		tempData[0] = 'I';
490 494
		tempData[1] = curr>>8;
491 495
		tempData[2] = curr&0xFF;
496
        delay_ms(50);
492 497
		i2c_putpacket(0x01, tempData, 3);
498
        delay_ms(50);
493 499
#endif
494 500
		curr=6666;
495 501
		
496 502
    /* Absolute Voltage Termination */
497
		if(supply_voltage())
498
		  {
499 503
		mod=abs_time%4;
500 504
		while(abs_time%4==mod)
501 505
		{
......
512 516
		tempData[0] = 'V';
513 517
		tempData[1] = volt>>8;
514 518
		tempData[2] = volt&0xFF;
519
        delay_ms(50);
515 520
		i2c_putpacket(0x01, tempData, 3);
521
        delay_ms(50);
516 522
#endif
517 523
		volt=6666;
518 524
		
......
533 539
		tempData[0] = 'T';
534 540
		tempData[1] = temp>>8;
535 541
		tempData[2] = temp&0xFF;
542
        delay_ms(50);
536 543
		i2c_putpacket(0x01, tempData, 3);
544
        delay_ms(50);
537 545
#endif
538
		  }
539 546

  
540 547
		temp=6666;
541 548
	}

Also available in: Unified diff