can.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  1. #ifndef __MCP2515_H
  2. #define __MCP2515_H
  3. #include "commontypedef.h"
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  7. /* Configuration Registers */
  8. #define CANSTAT 0x0E
  9. #define CANCTRL 0x0F
  10. #define BFPCTRL 0x0C
  11. #define TEC 0x1C
  12. #define REC 0x1D
  13. #define CNF3 0x28
  14. #define CNF2 0x29
  15. #define CNF1 0x2A
  16. #define CANINTE 0x2B
  17. #define CANINTF 0x2C
  18. #define EFLG 0x2D
  19. #define TXRTSCTRL 0x0D
  20. /* Recieve Filters */
  21. #define RXF0SIDH 0x00
  22. #define RXF0SIDL 0x01
  23. #define RXF0EID8 0x02
  24. #define RXF0EID0 0x03
  25. #define RXF1SIDH 0x04
  26. #define RXF1SIDL 0x05
  27. #define RXF1EID8 0x06
  28. #define RXF1EID0 0x07
  29. #define RXF2SIDH 0x08
  30. #define RXF2SIDL 0x09
  31. #define RXF2EID8 0x0A
  32. #define RXF2EID0 0x0B
  33. #define RXF3SIDH 0x10
  34. #define RXF3SIDL 0x11
  35. #define RXF3EID8 0x12
  36. #define RXF3EID0 0x13
  37. #define RXF4SIDH 0x14
  38. #define RXF4SIDL 0x15
  39. #define RXF4EID8 0x16
  40. #define RXF4EID0 0x17
  41. #define RXF5SIDH 0x18
  42. #define RXF5SIDL 0x19
  43. #define RXF5EID8 0x1A
  44. #define RXF5EID0 0x1B
  45. /* Receive Masks */
  46. #define RXM0SIDH 0x20
  47. #define RXM0SIDL 0x21
  48. #define RXM0EID8 0x22
  49. #define RXM0EID0 0x23
  50. #define RXM1SIDH 0x24
  51. #define RXM1SIDL 0x25
  52. #define RXM1EID8 0x26
  53. #define RXM1EID0 0x27
  54. /* Tx Buffer 0 */
  55. #define TXB0CTRL 0x30
  56. #define TXB0SIDH 0x31
  57. #define TXB0SIDL 0x32
  58. #define TXB0EID8 0x33
  59. #define TXB0EID0 0x34
  60. #define TXB0DLC 0x35
  61. #define TXB0D0 0x36
  62. #define TXB0D1 0x37
  63. #define TXB0D2 0x38
  64. #define TXB0D3 0x39
  65. #define TXB0D4 0x3A
  66. #define TXB0D5 0x3B
  67. #define TXB0D6 0x3C
  68. #define TXB0D7 0x3D
  69. /* Tx Buffer 1 */
  70. #define TXB1CTRL 0x40
  71. #define TXB1SIDH 0x41
  72. #define TXB1SIDL 0x42
  73. #define TXB1EID8 0x43
  74. #define TXB1EID0 0x44
  75. #define TXB1DLC 0x45
  76. #define TXB1D0 0x46
  77. #define TXB1D1 0x47
  78. #define TXB1D2 0x48
  79. #define TXB1D3 0x49
  80. #define TXB1D4 0x4A
  81. #define TXB1D5 0x4B
  82. #define TXB1D6 0x4C
  83. #define TXB1D7 0x4D
  84. /* Tx Buffer 2 */
  85. #define TXB2CTRL 0x50
  86. #define TXB2SIDH 0x51
  87. #define TXB2SIDL 0x52
  88. #define TXB2EID8 0x53
  89. #define TXB2EID0 0x54
  90. #define TXB2DLC 0x55
  91. #define TXB2D0 0x56
  92. #define TXB2D1 0x57
  93. #define TXB2D2 0x58
  94. #define TXB2D3 0x59
  95. #define TXB2D4 0x5A
  96. #define TXB2D5 0x5B
  97. #define TXB2D6 0x5C
  98. #define TXB2D7 0x5D
  99. /* Rx Buffer 0 */
  100. #define RXB0CTRL 0x60
  101. #define RXB0SIDH 0x61
  102. #define RXB0SIDL 0x62
  103. #define RXB0EID8 0x63
  104. #define RXB0EID0 0x64
  105. #define RXB0DLC 0x65
  106. #define RXB0D0 0x66
  107. #define RXB0D1 0x67
  108. #define RXB0D2 0x68
  109. #define RXB0D3 0x69
  110. #define RXB0D4 0x6A
  111. #define RXB0D5 0x6B
  112. #define RXB0D6 0x6C
  113. #define RXB0D7 0x6D
  114. /* Rx Buffer 1 */
  115. #define RXB1CTRL 0x70
  116. #define RXB1SIDH 0x71
  117. #define RXB1SIDL 0x72
  118. #define RXB1EID8 0x73
  119. #define RXB1EID0 0x74
  120. #define RXB1DLC 0x75
  121. #define RXB1D0 0x76
  122. #define RXB1D1 0x77
  123. #define RXB1D2 0x78
  124. #define RXB1D3 0x79
  125. #define RXB1D4 0x7A
  126. #define RXB1D5 0x7B
  127. #define RXB1D6 0x7C
  128. #define RXB1D7 0x7D
  129. /*******************************************************************
  130. * Bit register masks *
  131. *******************************************************************/
  132. /* TXBnCTRL */
  133. #define TXREQ 0x08
  134. #define TXP 0x03
  135. /* RXBnCTRL */
  136. #define RXM 0x60
  137. #define BUKT 0x04
  138. /* CANCTRL */
  139. #define REQOP 0xE0
  140. #define ABAT 0x10
  141. #define OSM 0x08
  142. #define CLKEN 0x04
  143. #define CLKPRE 0x03
  144. /* CANSTAT */
  145. #define REQOP 0xE0
  146. #define ICOD 0x0E
  147. /* CANINTE */
  148. #define RX0IE 0x01
  149. #define RX1IE 0x02
  150. #define TX0IE 0x04
  151. #define TX1IE 0x80
  152. #define TX2IE 0x10
  153. #define ERRIE 0x20
  154. #define WAKIE 0x40
  155. #define MERRE 0x80
  156. /* CANINTF */
  157. #define RX0IF 0x01
  158. #define RX1IF 0x02
  159. #define TX0IF 0x04
  160. #define TX1IF 0x80
  161. #define TX2IF 0x10
  162. #define ERRIF 0x20
  163. #define WAKIF 0x40
  164. #define MERRF 0x80
  165. /* BFPCTRL */
  166. #define B1BFS 0x20
  167. #define B0BFS 0x10
  168. #define B1BFE 0x08
  169. #define B0BFE 0x04
  170. #define B1BFM 0x02
  171. #define B0BFM 0x01
  172. /* CNF1 Masks */
  173. #define SJW 0xC0
  174. #define BRP 0x3F
  175. /* CNF2 Masks */
  176. #define BTLMODE 0x80
  177. #define SAM 0x40
  178. #define PHSEG1 0x38
  179. #define PRSEG 0x07
  180. /* CNF3 Masks */
  181. #define WAKFIL 0x40
  182. #define PHSEG2 0x07
  183. /* TXRTSCTRL Masks */
  184. #define TXB2RTS 0x04
  185. #define TXB1RTS 0x02
  186. #define TXB0RTS 0x01
  187. /*******************************************************************
  188. * Bit Timing Configuration *
  189. *******************************************************************/
  190. /* CNF1 */
  191. #define SJW_1TQ 0x40
  192. #define SJW_2TQ 0x80
  193. #define SJW_3TQ 0x90
  194. #define SJW_4TQ 0xC0
  195. /* CNF2 */
  196. #define BTLMODE_CNF3 0x80
  197. #define BTLMODE_PH1_IPT 0x00
  198. #define SMPL_3X 0x40
  199. #define SMPL_1X 0x00
  200. #define PHSEG1_8TQ 0x38
  201. #define PHSEG1_7TQ 0x30
  202. #define PHSEG1_6TQ 0x28
  203. #define PHSEG1_5TQ 0x20
  204. #define PHSEG1_4TQ 0x18
  205. #define PHSEG1_3TQ 0x10
  206. #define PHSEG1_2TQ 0x08
  207. #define PHSEG1_1TQ 0x00
  208. #define PRSEG_8TQ 0x07
  209. #define PRSEG_7TQ 0x06
  210. #define PRSEG_6TQ 0x05
  211. #define PRSEG_5TQ 0x04
  212. #define PRSEG_4TQ 0x03
  213. #define PRSEG_3TQ 0x02
  214. #define PRSEG_2TQ 0x01
  215. #define PRSEG_1TQ 0x00
  216. /* CNF3 */
  217. #define PHSEG2_8TQ 0x07
  218. #define PHSEG2_7TQ 0x06
  219. #define PHSEG2_6TQ 0x05
  220. #define PHSEG2_5TQ 0x04
  221. #define PHSEG2_4TQ 0x03
  222. #define PHSEG2_3TQ 0x02
  223. #define PHSEG2_2TQ 0x01
  224. #define PHSEG2_1TQ 0x00
  225. #define SOF_ENABLED 0x80
  226. #define WAKFIL_ENABLED 0x40
  227. #define WAKFIL_DISABLED 0x00
  228. /*******************************************************************
  229. * Control/Configuration Registers *
  230. *******************************************************************/
  231. /* CANINTE */
  232. #define RX0IE_ENABLED 0x01
  233. #define RX0IE_DISABLED 0x00
  234. #define RX1IE_ENABLED 0x02
  235. #define RX1IE_DISABLED 0x00
  236. #define G_RXIE_ENABLED 0x03
  237. #define G_RXIE_DISABLED 0x00
  238. #define TX0IE_ENABLED 0x04
  239. #define TX0IE_DISABLED 0x00
  240. #define TX1IE_ENABLED 0x08
  241. #define TX2IE_DISABLED 0x00
  242. #define TX2IE_ENABLED 0x10
  243. #define TX2IE_DISABLED 0x00
  244. #define G_TXIE_ENABLED 0x1C
  245. #define G_TXIE_DISABLED 0x00
  246. #define ERRIE_ENABLED 0x20
  247. #define ERRIE_DISABLED 0x00
  248. #define WAKIE_ENABLED 0x40
  249. #define WAKIE_DISABLED 0x00
  250. #define IVRE_ENABLED 0x80
  251. #define IVRE_DISABLED 0x00
  252. /* CANINTF */
  253. #define RX0IF_SET 0x01
  254. #define RX0IF_RESET 0x00
  255. #define RX1IF_SET 0x02
  256. #define RX1IF_RESET 0x00
  257. #define TX0IF_SET 0x04
  258. #define TX0IF_RESET 0x00
  259. #define TX1IF_SET 0x08
  260. #define TX2IF_RESET 0x00
  261. #define TX2IF_SET 0x10
  262. #define TX2IF_RESET 0x00
  263. #define ERRIF_SET 0x20
  264. #define ERRIF_RESET 0x00
  265. #define WAKIF_SET 0x40
  266. #define WAKIF_RESET 0x00
  267. #define IVRF_SET 0x80
  268. #define IVRF_RESET 0x00
  269. /* CANCTRL */
  270. #define REQOP_CONFIG 0x80
  271. #define REQOP_LISTEN 0x60
  272. #define REQOP_LOOPBACK 0x40
  273. #define REQOP_SLEEP 0x20
  274. #define REQOP_NORMAL 0x00
  275. #define ABORT 0x10
  276. #define OSM_ENABLED 0x08
  277. #define CLKOUT_ENABLED 0x04
  278. #define CLKOUT_DISABLED 0x00
  279. #define CLKOUT_PRE_8 0x03
  280. #define CLKOUT_PRE_4 0x02
  281. #define CLKOUT_PRE_2 0x01
  282. #define CLKOUT_PRE_1 0x00
  283. /* CANSTAT */
  284. #define OPMODE_CONFIG 0x80
  285. #define OPMODE_LISTEN 0x60
  286. #define OPMODE_LOOPBACK 0x40
  287. #define OPMODE_SLEEP 0x20
  288. #define OPMODE_NORMAL 0x00
  289. /* RXBnCTRL */
  290. #define RXM_RCV_ALL 0x60
  291. #define RXM_VALID_EXT 0x40
  292. #define RXM_VALID_STD 0x20
  293. #define RXM_VALID_ALL 0x00
  294. #define RXRTR_REMOTE 0x08
  295. #define RXRTR_NO_REMOTE 0x00
  296. #define BUKT_ROLLOVER 0x04
  297. #define BUKT_NO_ROLLOVER 0x00
  298. #define FILHIT0_FLTR_1 0x01
  299. #define FILHIT0_FLTR_0 0x00
  300. #define FILHIT1_FLTR_5 0x05
  301. #define FILHIT1_FLTR_4 0x04
  302. #define FILHIT1_FLTR_3 0x03
  303. #define FILHIT1_FLTR_2 0x02
  304. #define FILHIT1_FLTR_1 0x01
  305. #define FILHIT1_FLTR_0 0x00
  306. /* TXBnCTRL */
  307. #define TXREQ_SET 0x08
  308. #define TXREQ_CLEAR 0x00
  309. #define TXP_HIGHEST 0x03
  310. #define TXP_INTER_HIGH 0x02
  311. #define TXP_INTER_LOW 0x01
  312. #define TXP_LOWEST 0x00
  313. /*******************************************************************
  314. * Register Bit Masks *
  315. *******************************************************************/
  316. #define DLC_0 0x00
  317. #define DLC_1 0x01
  318. #define DLC_2 0x02
  319. #define DLC_3 0x03
  320. #define DLC_4 0x04
  321. #define DLC_5 0x05
  322. #define DLC_6 0x06
  323. #define DLC_7 0x07
  324. #define DLC_8 0x08
  325. /*******************************************************************
  326. * CAN SPI commands *
  327. *******************************************************************/
  328. #define CAN_RESET 0xC0
  329. #define CAN_READ 0x03
  330. #define CAN_WRITE 0x02
  331. #define CAN_RTS 0x80
  332. #define CAN_RTS_TXB0 0x81
  333. #define CAN_RTS_TXB1 0x82
  334. #define CAN_RTS_TXB2 0x84
  335. #define CAN_RD_STATUS 0xA0
  336. #define CAN_BIT_MODIFY 0x05
  337. #define CAN_RX_STATUS 0xB0
  338. #define CAN_RD_RX_BUFF 0x90
  339. #define CAN_LOAD_TX 0X40
  340. /*******************************************************************
  341. * Miscellaneous *
  342. *******************************************************************/
  343. #define DUMMY_BYTE 0x00
  344. #define TXB0 0x31
  345. #define TXB1 0x41
  346. #define TXB2 0x51
  347. #define RXB0 0x61
  348. #define RXB1 0x71
  349. #define EXIDE_SET 0x08
  350. #define EXIDE_RESET 0x00
  351. /*MCP2515²¨ÌØÂÊÔ¤·ÖƵ*/
  352. #define CAN_10Kbps 0x31
  353. #define CAN_25Kbps 0x13
  354. #define CAN_50Kbps 0x09
  355. #define CAN_100Kbps 0x04
  356. #define CAN_125Kbps 0x03
  357. #define CAN_250Kbps 0x01
  358. #define CAN_500Kbps 0x00
  359. #ifdef __cplusplus
  360. }
  361. #endif
  362. #endif