-
Notifications
You must be signed in to change notification settings - Fork 1
/
can_mcp2515.dox
81 lines (81 loc) · 2.14 KB
/
can_mcp2515.dox
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/**
* \page page_can_bus CAN Bus
*
* \section sec_can_ack Acknowledgements
*
* Most functions and sequences are based on CAN tutorial by Fabian Greif
* (http://www.kreatives-chaos.com) and his CAN library. I took the freedom
* to adapt and re-write, so I could learn and not only take it as is. You
* may have still the feeling, that I did not understand some things fully.
* You could be right ;-)
*
* Nevertheless, without Fabians work, this little project would have taken
* much, much longer or may never even be finished.
*
* Thanks!
*
* \section sec_can_usage Usage of CAN Module
* \sa page_spi
* \sa can_config_mcp2515.c, can_config_mcp2515.h
*
* After initialization of the CAN module, the usage is straight forward.
* Use the values given by configuration (e.g. chip to use) and the
* definitions within the CAN module itself (e.g. mode of operation).
*
* Example:
* \code
* #include "modules/can/can_mcp2515.h"
* #include "modules/spi/spi.h"
*
* int main(void)
* {
* bool canInitRetVal = true;
* can_t canMsg;
*
* // initialize the hardware SPI
* spi_pin_init();
* spi_master_init();
*
* // initialize CAN bus
* canInitRetVal = can_init_mcp2515(CAN_CHIP1, // chip
* CAN_BITRATE_100_KBPS, // bitrate
* NORMAL_MODE); // mode
*
* if(false == canInitRetVal)
* {
* // error handling...
* }
*
* // ...do something...
*
* // get message from CAN
* if(can_check_message_received(CAN_CHIP1))
* {
* if(can_get_message(CAN_CHIP1, &canMsg))
* {
* // do something with message...
* if(0x2A0 == canMsg.msgId)
* {
* // ...something more...
* }
* }
* }
*
* // prepare CAN message
* canMsg.msgId = 0x2B0;
* canMsg.header.len = 2;
* canMsg.data[0] = 0x08;
* canMsg.data[1] = 0x15;
*
* // send CAN message
* while(0 == can_send_message(CAN_CHIP1, &canMsg))
* {
* // wait for empty send buffer
* _delay_us(10);
* }
*
* return 0;
* }
* \endcode
*
*/