Subversion Repositories HomeAutomation

Rev

Details | Last modification | View Log | SVN | RSS feed

Rev Author Line No. Line
161 eqlazer 1
/**
2
 * CAN Test. This program sends a CAN message once every second. The ID of the
3
 * message is increased each time for testing purposes.
4
 * Added LCD output
5
 *
6
 * @date    2006-11-21, LCD addition 2006-12-11
7
 * @author  Jimmy Myhrman, Erik Larsson
8
 *  
9
 */
10
 
11
/*-----------------------------------------------------------------------------
12
 * Includes
13
 *---------------------------------------------------------------------------*/
14
/* system files */
15
#include <avr/io.h>
16
#include <avr/interrupt.h>
17
#include <avr/wdt.h>
18
#include <stdio.h>
19
/* lib files */
20
#include <can.h>
21
#include <serial.h>
22
#include <timebase.h>
23
#include <lcd.h>
24
 
25
/*-----------------------------------------------------------------------------
26
 * Main Program
27
 *---------------------------------------------------------------------------*/
28
int main(void) {
29
    Timebase_Init();
30
    Serial_Init();
31
    sei();
32
    lcd_init( LCD_DISP_ON );
33
 
34
    printf("\n------------------------------------------------------------\n");
35
    printf(  "   CAN Test: Periodic Transmission\n");
36
    printf(  "------------------------------------------------------------\n");
37
 
38
    lcd_clrscr();
39
    lcd_puts("CAN LCD test\n");
40
 
41
    printf("CanInit...");
42
    lcd_puts("CanInit... ");
43
    if (Can_Init() != CAN_OK) {
44
        printf("FAILED!\n");
45
        lcd_puts("FAILED!\n");
46
    }
47
    else {
48
        printf("OK!\n");
49
        lcd_puts("OK!\n");
50
    }
51
 
52
    uint32_t timeStamp = 0;
53
 
54
    Can_Message_t txMsg;
55
    Can_Message_t rxMsg;
56
    txMsg.Id = 0;
57
    txMsg.RemoteFlag = 0;
58
    txMsg.ExtendedFlag = 1; //DataLength and the databytes are just what happens to be in the memory. They are never set.
59
 
60
    /* main loop */
61
    while (1) {
62
        /* service the CAN routines */
63
        Can_Service();
64
 
65
        /* send CAN message and check for CAN errors once every second */
66
        if (Timebase_PassedTimeMillis(timeStamp) >= 1000) {
67
            timeStamp = Timebase_CurrentTime();
68
            /* send txMsg */
69
            txMsg.Id++;
70
            Can_Send(&txMsg);
71
        }
72
 
73
        /* check if any messages have been received */
74
        while (Can_Receive(&rxMsg) == CAN_OK) {
75
            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));
76
            printf("data={ ");
77
            for (uint8_t i=0; i<rxMsg.DataLength; i++) {
78
                printf("%x ", rxMsg.Data.bytes[i]);
79
            }
80
            printf("}\n");
81
        }
82
    }
83
 
84
    return 0;
85
}