hw_i2c.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  1. //*****************************************************************************
  2. //
  3. // hw_i2c.h - Macros used when accessing the I2C master and slave hardware.
  4. //
  5. // Copyright (c) 2005-2011 Texas Instruments Incorporated. All rights reserved.
  6. // Software License Agreement
  7. //
  8. // Texas Instruments (TI) is supplying this software for use solely and
  9. // exclusively on TI's microcontroller products. The software is owned by
  10. // TI and/or its suppliers, and is protected under applicable copyright
  11. // laws. You may not combine this software with "viral" open-source
  12. // software in order to form a larger program.
  13. //
  14. // THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.
  15. // NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT
  16. // NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  17. // A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY
  18. // CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
  19. // DAMAGES, FOR ANY REASON WHATSOEVER.
  20. //
  21. // This is part of revision 8264 of the Stellaris Firmware Development Package.
  22. //
  23. //*****************************************************************************
  24. #ifndef __HW_I2C_H__
  25. #define __HW_I2C_H__
  26. //*****************************************************************************
  27. //
  28. // The following are defines for the I2C register offsets.
  29. //
  30. //*****************************************************************************
  31. #define I2C_O_MSA 0x00000000 // I2C Master Slave Address
  32. #define I2C_O_SOAR 0x00000000 // I2C Slave Own Address
  33. #define I2C_O_SCSR 0x00000004 // I2C Slave Control/Status
  34. #define I2C_O_MCS 0x00000004 // I2C Master Control/Status
  35. #define I2C_O_SDR 0x00000008 // I2C Slave Data
  36. #define I2C_O_MDR 0x00000008 // I2C Master Data
  37. #define I2C_O_MTPR 0x0000000C // I2C Master Timer Period
  38. #define I2C_O_SIMR 0x0000000C // I2C Slave Interrupt Mask
  39. #define I2C_O_SRIS 0x00000010 // I2C Slave Raw Interrupt Status
  40. #define I2C_O_MIMR 0x00000010 // I2C Master Interrupt Mask
  41. #define I2C_O_MRIS 0x00000014 // I2C Master Raw Interrupt Status
  42. #define I2C_O_SMIS 0x00000014 // I2C Slave Masked Interrupt
  43. // Status
  44. #define I2C_O_SICR 0x00000018 // I2C Slave Interrupt Clear
  45. #define I2C_O_MMIS 0x00000018 // I2C Master Masked Interrupt
  46. // Status
  47. #define I2C_O_MICR 0x0000001C // I2C Master Interrupt Clear
  48. #define I2C_O_SOAR2 0x0000001C // I2C Slave Own Address 2
  49. #define I2C_O_MCR 0x00000020 // I2C Master Configuration
  50. #define I2C_O_SACKCTL 0x00000020 // I2C ACK Control
  51. #define I2C_O_MCLKOCNT 0x00000024 // I2C Master Clock Low Timeout
  52. // Count
  53. #define I2C_O_MBMON 0x0000002C // I2C Master Bus Monitor
  54. #define I2C_O_PP 0x00000FC0 // I2C Peripheral Properties
  55. //*****************************************************************************
  56. //
  57. // The following are defines for the bit fields in the I2C_O_MSA register.
  58. //
  59. //*****************************************************************************
  60. #define I2C_MSA_SA_M 0x000000FE // I2C Slave Address
  61. #define I2C_MSA_RS 0x00000001 // Receive not send
  62. #define I2C_MSA_SA_S 1
  63. //*****************************************************************************
  64. //
  65. // The following are defines for the bit fields in the I2C_O_SOAR register.
  66. //
  67. //*****************************************************************************
  68. #define I2C_SOAR_OAR_M 0x0000007F // I2C Slave Own Address
  69. #define I2C_SOAR_OAR_S 0
  70. //*****************************************************************************
  71. //
  72. // The following are defines for the bit fields in the I2C_O_SCSR register.
  73. //
  74. //*****************************************************************************
  75. #define I2C_SCSR_QCMDRW 0x00000020 // Quick Command Read / Write
  76. #define I2C_SCSR_QCMDST 0x00000010 // Quick Command Status
  77. #define I2C_SCSR_OAR2SEL 0x00000008 // OAR2 Address Matched
  78. #define I2C_SCSR_FBR 0x00000004 // First Byte Received
  79. #define I2C_SCSR_TREQ 0x00000002 // Transmit Request
  80. #define I2C_SCSR_DA 0x00000001 // Device Active
  81. #define I2C_SCSR_RREQ 0x00000001 // Receive Request
  82. //*****************************************************************************
  83. //
  84. // The following are defines for the bit fields in the I2C_O_MCS register.
  85. //
  86. //*****************************************************************************
  87. #define I2C_MCS_CLKTO 0x00000080 // Clock Timeout Error
  88. #define I2C_MCS_BUSBSY 0x00000040 // Bus Busy
  89. #define I2C_MCS_IDLE 0x00000020 // I2C Idle
  90. #define I2C_MCS_QCMD 0x00000020 // Quick Command
  91. #define I2C_MCS_ARBLST 0x00000010 // Arbitration Lost
  92. #define I2C_MCS_HS 0x00000010 // High-Speed Enable
  93. #define I2C_MCS_ACK 0x00000008 // Data Acknowledge Enable
  94. #define I2C_MCS_DATACK 0x00000008 // Acknowledge Data
  95. #define I2C_MCS_ADRACK 0x00000004 // Acknowledge Address
  96. #define I2C_MCS_STOP 0x00000004 // Generate STOP
  97. #define I2C_MCS_START 0x00000002 // Generate START
  98. #define I2C_MCS_ERROR 0x00000002 // Error
  99. #define I2C_MCS_RUN 0x00000001 // I2C Master Enable
  100. #define I2C_MCS_BUSY 0x00000001 // I2C Busy
  101. //*****************************************************************************
  102. //
  103. // The following are defines for the bit fields in the I2C_O_SDR register.
  104. //
  105. //*****************************************************************************
  106. #define I2C_SDR_DATA_M 0x000000FF // Data for Transfer
  107. #define I2C_SDR_DATA_S 0
  108. //*****************************************************************************
  109. //
  110. // The following are defines for the bit fields in the I2C_O_MDR register.
  111. //
  112. //*****************************************************************************
  113. #define I2C_MDR_DATA_M 0x000000FF // Data Transferred
  114. #define I2C_MDR_DATA_S 0
  115. //*****************************************************************************
  116. //
  117. // The following are defines for the bit fields in the I2C_O_MTPR register.
  118. //
  119. //*****************************************************************************
  120. #define I2C_MTPR_TPR_M 0x0000007F // SCL Clock Period
  121. #define I2C_MTPR_TPR_S 0
  122. //*****************************************************************************
  123. //
  124. // The following are defines for the bit fields in the I2C_O_SIMR register.
  125. //
  126. //*****************************************************************************
  127. #define I2C_SIMR_STOPIM 0x00000004 // Stop Condition Interrupt Mask
  128. #define I2C_SIMR_STARTIM 0x00000002 // Start Condition Interrupt Mask
  129. #define I2C_SIMR_DATAIM 0x00000001 // Data Interrupt Mask
  130. //*****************************************************************************
  131. //
  132. // The following are defines for the bit fields in the I2C_O_SRIS register.
  133. //
  134. //*****************************************************************************
  135. #define I2C_SRIS_STOPRIS 0x00000004 // Stop Condition Raw Interrupt
  136. // Status
  137. #define I2C_SRIS_STARTRIS 0x00000002 // Start Condition Raw Interrupt
  138. // Status
  139. #define I2C_SRIS_DATARIS 0x00000001 // Data Raw Interrupt Status
  140. //*****************************************************************************
  141. //
  142. // The following are defines for the bit fields in the I2C_O_MIMR register.
  143. //
  144. //*****************************************************************************
  145. #define I2C_MIMR_CLKIM 0x00000002 // Clock Timeout Interrupt Mask
  146. #define I2C_MIMR_IM 0x00000001 // Interrupt Mask
  147. //*****************************************************************************
  148. //
  149. // The following are defines for the bit fields in the I2C_O_MRIS register.
  150. //
  151. //*****************************************************************************
  152. #define I2C_MRIS_CLKRIS 0x00000002 // Clock Timeout Raw Interrupt
  153. // Status
  154. #define I2C_MRIS_RIS 0x00000001 // Raw Interrupt Status
  155. //*****************************************************************************
  156. //
  157. // The following are defines for the bit fields in the I2C_O_SMIS register.
  158. //
  159. //*****************************************************************************
  160. #define I2C_SMIS_STOPMIS 0x00000004 // Stop Condition Masked Interrupt
  161. // Status
  162. #define I2C_SMIS_STARTMIS 0x00000002 // Start Condition Masked Interrupt
  163. // Status
  164. #define I2C_SMIS_DATAMIS 0x00000001 // Data Masked Interrupt Status
  165. //*****************************************************************************
  166. //
  167. // The following are defines for the bit fields in the I2C_O_SICR register.
  168. //
  169. //*****************************************************************************
  170. #define I2C_SICR_STOPIC 0x00000004 // Stop Condition Interrupt Clear
  171. #define I2C_SICR_STARTIC 0x00000002 // Start Condition Interrupt Clear
  172. #define I2C_SICR_DATAIC 0x00000001 // Data Interrupt Clear
  173. //*****************************************************************************
  174. //
  175. // The following are defines for the bit fields in the I2C_O_MMIS register.
  176. //
  177. //*****************************************************************************
  178. #define I2C_MMIS_CLKMIS 0x00000002 // Clock Timeout Masked Interrupt
  179. // Status
  180. #define I2C_MMIS_MIS 0x00000001 // Masked Interrupt Status
  181. //*****************************************************************************
  182. //
  183. // The following are defines for the bit fields in the I2C_O_MICR register.
  184. //
  185. //*****************************************************************************
  186. #define I2C_MICR_CLKIC 0x00000002 // Clock Timeout Interrupt Clear
  187. #define I2C_MICR_IC 0x00000001 // Interrupt Clear
  188. //*****************************************************************************
  189. //
  190. // The following are defines for the bit fields in the I2C_O_SOAR2 register.
  191. //
  192. //*****************************************************************************
  193. #define I2C_SOAR2_OAR2EN 0x00000080 // I2C Slave Own Address 2 Enable
  194. #define I2C_SOAR2_OAR2_M 0x0000007F // I2C Slave Own Address 2
  195. #define I2C_SOAR2_OAR2_S 0
  196. //*****************************************************************************
  197. //
  198. // The following are defines for the bit fields in the I2C_O_MCR register.
  199. //
  200. //*****************************************************************************
  201. #define I2C_MCR_SFE 0x00000020 // I2C Slave Function Enable
  202. #define I2C_MCR_MFE 0x00000010 // I2C Master Function Enable
  203. #define I2C_MCR_LPBK 0x00000001 // I2C Loopback
  204. //*****************************************************************************
  205. //
  206. // The following are defines for the bit fields in the I2C_O_SACKCTL register.
  207. //
  208. //*****************************************************************************
  209. #define I2C_SACKCTL_ACKOVAL 0x00000002 // I2C Slave ACK Override Value
  210. #define I2C_SACKCTL_ACKOEN 0x00000001 // I2C Slave ACK Override Enable
  211. //*****************************************************************************
  212. //
  213. // The following are defines for the bit fields in the I2C_O_MCLKOCNT register.
  214. //
  215. //*****************************************************************************
  216. #define I2C_MCLKOCNT_CNTL_M 0x000000FF // I2C Master Count
  217. #define I2C_MCLKOCNT_CNTL_S 0
  218. //*****************************************************************************
  219. //
  220. // The following are defines for the bit fields in the I2C_O_MBMON register.
  221. //
  222. //*****************************************************************************
  223. #define I2C_MBMON_SDA 0x00000002 // I2C SDA Status
  224. #define I2C_MBMON_SCL 0x00000001 // I2C SCL Status
  225. //*****************************************************************************
  226. //
  227. // The following are defines for the bit fields in the I2C_O_PP register.
  228. //
  229. //*****************************************************************************
  230. #define I2C_PP_HS 0x00000001 // High-Speed Capable
  231. //*****************************************************************************
  232. //
  233. // The following definitions are deprecated.
  234. //
  235. //*****************************************************************************
  236. #ifndef DEPRECATED
  237. //*****************************************************************************
  238. //
  239. // The following are deprecated defines for the I2C register offsets.
  240. //
  241. //*****************************************************************************
  242. #define I2C_O_SLAVE 0x00000800 // Offset from master to slave
  243. //*****************************************************************************
  244. //
  245. // The following are deprecated defines for the bit fields in the I2C_O_SIMR
  246. // register.
  247. //
  248. //*****************************************************************************
  249. #define I2C_SIMR_IM 0x00000001 // Interrupt Mask
  250. //*****************************************************************************
  251. //
  252. // The following are deprecated defines for the bit fields in the I2C_O_SRIS
  253. // register.
  254. //
  255. //*****************************************************************************
  256. #define I2C_SRIS_RIS 0x00000001 // Raw Interrupt Status
  257. //*****************************************************************************
  258. //
  259. // The following are deprecated defines for the bit fields in the I2C_O_SMIS
  260. // register.
  261. //
  262. //*****************************************************************************
  263. #define I2C_SMIS_MIS 0x00000001 // Masked Interrupt Status
  264. //*****************************************************************************
  265. //
  266. // The following are deprecated defines for the bit fields in the I2C_O_SICR
  267. // register.
  268. //
  269. //*****************************************************************************
  270. #define I2C_SICR_IC 0x00000001 // Clear Interrupt
  271. //*****************************************************************************
  272. //
  273. // The following are deprecated defines for the I2C master register offsets.
  274. //
  275. //*****************************************************************************
  276. #define I2C_MASTER_O_SA 0x00000000 // Slave address register
  277. #define I2C_MASTER_O_CS 0x00000004 // Control and Status register
  278. #define I2C_MASTER_O_DR 0x00000008 // Data register
  279. #define I2C_MASTER_O_TPR 0x0000000C // Timer period register
  280. #define I2C_MASTER_O_IMR 0x00000010 // Interrupt mask register
  281. #define I2C_MASTER_O_RIS 0x00000014 // Raw interrupt status register
  282. #define I2C_MASTER_O_MIS 0x00000018 // Masked interrupt status reg
  283. #define I2C_MASTER_O_MICR 0x0000001C // Interrupt clear register
  284. #define I2C_MASTER_O_CR 0x00000020 // Configuration register
  285. //*****************************************************************************
  286. //
  287. // The following are deprecated defines for the I2C slave register offsets.
  288. //
  289. //*****************************************************************************
  290. #define I2C_SLAVE_O_SICR 0x00000018 // Interrupt clear register
  291. #define I2C_SLAVE_O_MIS 0x00000014 // Masked interrupt status reg
  292. #define I2C_SLAVE_O_RIS 0x00000010 // Raw interrupt status register
  293. #define I2C_SLAVE_O_IM 0x0000000C // Interrupt mask register
  294. #define I2C_SLAVE_O_DR 0x00000008 // Data register
  295. #define I2C_SLAVE_O_CSR 0x00000004 // Control/Status register
  296. #define I2C_SLAVE_O_OAR 0x00000000 // Own address register
  297. //*****************************************************************************
  298. //
  299. // The following are deprecated defines for the bit fields in the I2C master
  300. // slave address register.
  301. //
  302. //*****************************************************************************
  303. #define I2C_MASTER_SA_SA_MASK 0x000000FE // Slave address
  304. #define I2C_MASTER_SA_RS 0x00000001 // Receive/send
  305. #define I2C_MASTER_SA_SA_SHIFT 1
  306. //*****************************************************************************
  307. //
  308. // The following are deprecated defines for the bit fields in the I2C Master
  309. // Control and Status register.
  310. //
  311. //*****************************************************************************
  312. #define I2C_MASTER_CS_BUS_BUSY 0x00000040 // Bus busy
  313. #define I2C_MASTER_CS_IDLE 0x00000020 // Idle
  314. #define I2C_MASTER_CS_ERR_MASK 0x0000001C
  315. #define I2C_MASTER_CS_BUSY 0x00000001 // Controller is TX/RX data
  316. #define I2C_MASTER_CS_ERROR 0x00000002 // Error occurred
  317. #define I2C_MASTER_CS_ADDR_ACK 0x00000004 // Address byte not acknowledged
  318. #define I2C_MASTER_CS_DATA_ACK 0x00000008 // Data byte not acknowledged
  319. #define I2C_MASTER_CS_ARB_LOST 0x00000010 // Lost arbitration
  320. #define I2C_MASTER_CS_ACK 0x00000008 // Acknowlegde
  321. #define I2C_MASTER_CS_STOP 0x00000004 // Stop
  322. #define I2C_MASTER_CS_START 0x00000002 // Start
  323. #define I2C_MASTER_CS_RUN 0x00000001 // Run
  324. //*****************************************************************************
  325. //
  326. // The following are deprecated defines for the values used in determining the
  327. // contents of the I2C Master Timer Period register.
  328. //
  329. //*****************************************************************************
  330. #define I2C_SCL_FAST 400000 // SCL fast frequency
  331. #define I2C_SCL_STANDARD 100000 // SCL standard frequency
  332. #define I2C_MASTER_TPR_SCL_LP 0x00000006 // SCL low period
  333. #define I2C_MASTER_TPR_SCL_HP 0x00000004 // SCL high period
  334. #define I2C_MASTER_TPR_SCL (I2C_MASTER_TPR_SCL_HP + I2C_MASTER_TPR_SCL_LP)
  335. //*****************************************************************************
  336. //
  337. // The following are deprecated defines for the bit fields in the I2C Master
  338. // Interrupt Mask register.
  339. //
  340. //*****************************************************************************
  341. #define I2C_MASTER_IMR_IM 0x00000001 // Master interrupt mask
  342. //*****************************************************************************
  343. //
  344. // The following are deprecated defines for the bit fields in the I2C Master
  345. // Raw Interrupt Status register.
  346. //
  347. //*****************************************************************************
  348. #define I2C_MASTER_RIS_RIS 0x00000001 // Master raw interrupt status
  349. //*****************************************************************************
  350. //
  351. // The following are deprecated defines for the bit fields in the I2C Master
  352. // Masked Interrupt Status register.
  353. //
  354. //*****************************************************************************
  355. #define I2C_MASTER_MIS_MIS 0x00000001 // Master masked interrupt status
  356. //*****************************************************************************
  357. //
  358. // The following are deprecated defines for the bit fields in the I2C Master
  359. // Interrupt Clear register.
  360. //
  361. //*****************************************************************************
  362. #define I2C_MASTER_MICR_IC 0x00000001 // Master interrupt clear
  363. //*****************************************************************************
  364. //
  365. // The following are deprecated defines for the bit fields in the I2C Master
  366. // Configuration register.
  367. //
  368. //*****************************************************************************
  369. #define I2C_MASTER_CR_SFE 0x00000020 // Slave function enable
  370. #define I2C_MASTER_CR_MFE 0x00000010 // Master function enable
  371. #define I2C_MASTER_CR_LPBK 0x00000001 // Loopback enable
  372. //*****************************************************************************
  373. //
  374. // The following are deprecated defines for the bit fields in the I2C Slave Own
  375. // Address register.
  376. //
  377. //*****************************************************************************
  378. #define I2C_SLAVE_SOAR_OAR_MASK 0x0000007F // Slave address
  379. //*****************************************************************************
  380. //
  381. // The following are deprecated defines for the bit fields in the I2C Slave
  382. // Control/Status register.
  383. //
  384. //*****************************************************************************
  385. #define I2C_SLAVE_CSR_FBR 0x00000004 // First byte received from master
  386. #define I2C_SLAVE_CSR_TREQ 0x00000002 // Transmit request received
  387. #define I2C_SLAVE_CSR_DA 0x00000001 // Enable the device
  388. #define I2C_SLAVE_CSR_RREQ 0x00000001 // Receive data from I2C master
  389. //*****************************************************************************
  390. //
  391. // The following are deprecated defines for the bit fields in the I2C Slave
  392. // Interrupt Mask register.
  393. //
  394. //*****************************************************************************
  395. #define I2C_SLAVE_IMR_IM 0x00000001 // Slave interrupt mask
  396. //*****************************************************************************
  397. //
  398. // The following are deprecated defines for the bit fields in the I2C Slave Raw
  399. // Interrupt Status register.
  400. //
  401. //*****************************************************************************
  402. #define I2C_SLAVE_RIS_RIS 0x00000001 // Slave raw interrupt status
  403. //*****************************************************************************
  404. //
  405. // The following are deprecated defines for the bit fields in the I2C Slave
  406. // Masked Interrupt Status register.
  407. //
  408. //*****************************************************************************
  409. #define I2C_SLAVE_MIS_MIS 0x00000001 // Slave masked interrupt status
  410. //*****************************************************************************
  411. //
  412. // The following are deprecated defines for the bit fields in the I2C Slave
  413. // Interrupt Clear register.
  414. //
  415. //*****************************************************************************
  416. #define I2C_SLAVE_SICR_IC 0x00000001 // Slave interrupt clear
  417. #endif
  418. #endif // __HW_I2C_H__