at91rm9200_i2c.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. // ----------------------------------------------------------------------------
  2. // ATMEL Microcontroller Software Support - ROUSSET -
  3. // ----------------------------------------------------------------------------
  4. // The software is delivered "AS IS" without warranty or condition of any
  5. // kind, either express, implied or statutory. This includes without
  6. // limitation any warranty or condition with respect to merchantability or
  7. // fitness for any particular purpose, or against the infringements of
  8. // intellectual property rights of others.
  9. // ----------------------------------------------------------------------------
  10. // File Name : at91rm9200_i2c.h
  11. // Object : AT91RM9200 / TWI definitions
  12. // Generated : AT91 SW Application Group 12/03/2002 (10:48:02)
  13. //
  14. // ----------------------------------------------------------------------------
  15. #ifndef AT91RM9200_TWI_H
  16. #define AT91RM9200_TWI_H
  17. // *****************************************************************************
  18. // SOFTWARE API DEFINITION FOR Two-wire Interface
  19. // *****************************************************************************
  20. #ifndef __ASSEMBLY__
  21. typedef struct _AT91S_TWI {
  22. AT91_REG TWI_CR; // Control Register
  23. AT91_REG TWI_MMR; // Master Mode Register
  24. AT91_REG TWI_SMR; // Slave Mode Register
  25. AT91_REG TWI_IADR; // Internal Address Register
  26. AT91_REG TWI_CWGR; // Clock Waveform Generator Register
  27. AT91_REG Reserved0[3]; //
  28. AT91_REG TWI_SR; // Status Register
  29. AT91_REG TWI_IER; // Interrupt Enable Register
  30. AT91_REG TWI_IDR; // Interrupt Disable Register
  31. AT91_REG TWI_IMR; // Interrupt Mask Register
  32. AT91_REG TWI_RHR; // Receive Holding Register
  33. AT91_REG TWI_THR; // Transmit Holding Register
  34. AT91_REG Reserved1[50]; //
  35. AT91_REG TWI_RPR; // Receive Pointer Register
  36. AT91_REG TWI_RCR; // Receive Counter Register
  37. AT91_REG TWI_TPR; // Transmit Pointer Register
  38. AT91_REG TWI_TCR; // Transmit Counter Register
  39. AT91_REG TWI_RNPR; // Receive Next Pointer Register
  40. AT91_REG TWI_RNCR; // Receive Next Counter Register
  41. AT91_REG TWI_TNPR; // Transmit Next Pointer Register
  42. AT91_REG TWI_TNCR; // Transmit Next Counter Register
  43. AT91_REG TWI_PTCR; // PDC Transfer Control Register
  44. AT91_REG TWI_PTSR; // PDC Transfer Status Register
  45. } AT91S_TWI, *AT91PS_TWI;
  46. #endif
  47. // -------- TWI_CR : (TWI Offset: 0x0) TWI Control Register --------
  48. #define AT91C_TWI_START ( 0x1 << 0) // (TWI) Send a START Condition
  49. #define AT91C_TWI_STOP ( 0x1 << 1) // (TWI) Send a STOP Condition
  50. #define AT91C_TWI_MSEN ( 0x1 << 2) // (TWI) TWI Master Transfer Enabled
  51. #define AT91C_TWI_MSDIS ( 0x1 << 3) // (TWI) TWI Master Transfer Disabled
  52. #define AT91C_TWI_SVEN ( 0x1 << 4) // (TWI) TWI Slave Transfer Enabled
  53. #define AT91C_TWI_SVDIS ( 0x1 << 5) // (TWI) TWI Slave Transfer Disabled
  54. #define AT91C_TWI_SWRST ( 0x1 << 7) // (TWI) Software Reset
  55. // -------- TWI_MMR : (TWI Offset: 0x4) TWI Master Mode Register --------
  56. #define AT91C_TWI_IADRSZ ( 0x3 << 8) // (TWI) Internal Device Address Size
  57. #define AT91C_TWI_IADRSZ_NO ( 0x0 << 8) // (TWI) No internal device address
  58. #define AT91C_TWI_IADRSZ_1_BYTE ( 0x1 << 8) // (TWI) One-byte internal device address
  59. #define AT91C_TWI_IADRSZ_2_BYTE ( 0x2 << 8) // (TWI) Two-byte internal device address
  60. #define AT91C_TWI_IADRSZ_3_BYTE ( 0x3 << 8) // (TWI) Three-byte internal device address
  61. #define AT91C_TWI_MREAD ( 0x1 << 12) // (TWI) Master Read Direction
  62. #define AT91C_TWI_DADR ( 0x7F << 6) // (TWI) Device Address
  63. // -------- TWI_SMR : (TWI Offset: 0x8) TWI Slave Mode Register --------
  64. #define AT91C_TWI_SADR ( 0x7F << 16) // (TWI) Slave Device Address
  65. // -------- TWI_CWGR : (TWI Offset: 0x10) TWI Clock Waveform Generator Register --------
  66. #define AT91C_TWI_CLDIV ( 0xFF << 0) // (TWI) Clock Low Divider
  67. #define AT91C_TWI_CHDIV ( 0xFF << 8) // (TWI) Clock High Divider
  68. #define AT91C_TWI_CKDIV ( 0x7 << 16) // (TWI) Clock Divider
  69. // -------- TWI_SR : (TWI Offset: 0x20) TWI Status Register --------
  70. #define AT91C_TWI_TXCOMP ( 0x1 << 0) // (TWI) Transmission Completed
  71. #define AT91C_TWI_RXRDY ( 0x1 << 1) // (TWI) Receive holding register ReaDY
  72. #define AT91C_TWI_TXRDY ( 0x1 << 2) // (TWI) Transmit holding register ReaDY
  73. #define AT91C_TWI_SVREAD ( 0x1 << 3) // (TWI) Slave Read
  74. #define AT91C_TWI_SVACC ( 0x1 << 4) // (TWI) Slave Access
  75. #define AT91C_TWI_GCACC ( 0x1 << 5) // (TWI) General Call Access
  76. #define AT91C_TWI_OVRE ( 0x1 << 6) // (TWI) Overrun Error
  77. #define AT91C_TWI_UNRE ( 0x1 << 7) // (TWI) Underrun Error
  78. #define AT91C_TWI_NACK ( 0x1 << 8) // (TWI) Not Acknowledged
  79. #define AT91C_TWI_ARBLST ( 0x1 << 9) // (TWI) Arbitration Lost
  80. // -------- TWI_IER : (TWI Offset: 0x24) TWI Interrupt Enable Register --------
  81. // -------- TWI_IDR : (TWI Offset: 0x28) TWI Interrupt Disable Register --------
  82. // -------- TWI_IMR : (TWI Offset: 0x2c) TWI Interrupt Mask Register --------
  83. /*
  84. i2c Support for Atmel's AT91RM9200 Two-Wire Interface
  85. (c) Rick Bronson
  86. This program is free software; you can redistribute it and/or modify
  87. it under the terms of the GNU General Public License as published by
  88. the Free Software Foundation; either version 2 of the License, or
  89. (at your option) any later version.
  90. This program is distributed in the hope that it will be useful,
  91. but WITHOUT ANY WARRANTY; without even the implied warranty of
  92. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  93. GNU General Public License for more details.
  94. You should have received a copy of the GNU General Public License
  95. along with this program; if not, write to the Free Software
  96. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  97. */
  98. #ifndef AT91_I2C_H
  99. #define AT91_I2C_H
  100. #define AT91C_TWI_CLOCK 100000
  101. #define AT91C_TWI_SCLOCK (10 * AT91C_MASTER_CLOCK / AT91C_TWI_CLOCK)
  102. #define AT91C_TWI_CKDIV1 (2 << 16) /* TWI clock divider. NOTE: see Errata #22 */
  103. #if (AT91C_TWI_SCLOCK % 10) >= 5
  104. #define AT91C_TWI_CLDIV2 ((AT91C_TWI_SCLOCK / 10) - 5)
  105. #else
  106. #define AT91C_TWI_CLDIV2 ((AT91C_TWI_SCLOCK / 10) - 6)
  107. #endif
  108. #define AT91C_TWI_CLDIV3 ((AT91C_TWI_CLDIV2 + (4 - AT91C_TWI_CLDIV2 % 4)) >> 2)
  109. #define AT91C_EEPROM_I2C_ADDRESS (0x50 << 16)
  110. #endif
  111. #endif