ms5192t.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. #ifndef __MS5192T_H__
  2. #define __MS5192T_H__
  3. /* MS5192T GPIO */
  4. #define MS5192T_RDY_STATE GPIO1_STATE
  5. /*MS5192T Registers*/
  6. #define MS5192T_REG_COMM 0 /* Communications Register(WO, 8-bit) */
  7. #define MS5192T_REG_STAT 0 /* Status Register (RO, 8-bit) */
  8. #define MS5192T_REG_MODE 1 /* Mode Register (RW, 16-bit */
  9. #define MS5192T_REG_CONF 2 /* Configuration Register (RW, 16-bit)*/
  10. #define MS5192T_REG_DATA 3 /* Data Register (RO, 16-/24-bit) */
  11. #define MS5192T_REG_ID 4 /* ID Register (RO, 8-bit) */
  12. #define MS5192T_REG_IO 5 /* IO Register (RO, 8-bit) */
  13. #define MS5192T_REG_OFFSET 6 /* Offset Register (RW, 24-bit */
  14. #define MS5192T_REG_FULLSALE 7 /* Full-Scale Register (RW, 24-bit */
  15. /* Communications Register Bit Designations (AD7793_REG_COMM) */
  16. #define MS5192T_COMM_WEN (1 << 7) /* Write Enable */
  17. #define MS5192T_COMM_WRITE (0 << 6) /* Write Operation */
  18. #define MS5192T_COMM_READ (1 << 6) /* Read Operation */
  19. #define MS5192T_COMM_ADDR(x) (((x) & 0x7) << 3) /* Register Address */
  20. #define MS5192T_COMM_CREAD (1 << 2) /* Continuous Read of Data Register */
  21. /* Status Register Bit Designations (AD7793_REG_STAT) */
  22. #define MS5192T_STAT_RDY (1 << 7) /* Ready */
  23. #define MS5192T_STAT_ERR (1 << 6) /* Error (Overrange, Underrange) */
  24. #define MS5192T_STAT_CH3 (1 << 2) /* Channel 3 */
  25. #define MS5192T_STAT_CH2 (1 << 1) /* Channel 2 */
  26. #define MS5192T_STAT_CH1 (1 << 0) /* Channel 1 */
  27. /* Mode Register Bit Designations (MS5192T_REG_MODE) */
  28. #define MS5192T_MODE_SEL(x) (((x) & 0x7) << 13) /* Operation Mode Select */
  29. #define MS5192T_MODE_CLKSRC(x) (((x) & 0x3) << 6) /* ADC Clock Source Select */
  30. #define MS5192T_MODE_RATE(x) ((x) & 0xF) /* Filter Update Rate Select */
  31. /* AD7793_MODE_SEL(x) options */
  32. #define MS5192T_MODE_CONT 0 /* Continuous Conversion Mode */
  33. #define MS5192T_MODE_SINGLE 1 /* Single Conversion Mode */
  34. #define MS5192T_MODE_IDLE 2 /* Idle Mode */
  35. #define MS5192T_MODE_PWRDN 3 /* Power-Down Mode */
  36. #define MS5192T_MODE_CAL_INT_ZERO 4 /* Internal Zero-Scale Calibration */
  37. #define MS5192T_MODE_CAL_INT_FULL 5 /* Internal Full-Scale Calibration */
  38. #define MS5192T_MODE_CAL_SYS_ZERO 6 /* System Zero-Scale Calibration */
  39. #define MS5192T_MODE_CAL_SYS_FULL 7 /* System Full-Scale Calibration */
  40. /* MS5192T_MODE_CLKSRC(x) options */
  41. #define MS5192T_CLK_INT 0 /* Internal 64 kHz Clk not available at the CLK pin */
  42. #define MS5192T_CLK_INT_CO 1 /* Internal 64 kHz Clk available at the CLK pin */
  43. #define MS5192T_CLK_EXT 2 /* External 64 kHz Clock */
  44. #define MS5192T_CLK_EXT_DIV2 3 /* External Clock divided by 2 */
  45. /* MS5192T update rate */
  46. #define MS5192T_UP_RATE_500 1 /* 500 Hz */
  47. #define MS5192T_UP_RATE_250 2 /* 250 Hz */
  48. #define MS5192T_UP_RATE_125 3 /* 125 Hz */
  49. #define MS5192T_UP_RATE_62 4 /* 62.5 Hz */
  50. #define MS5192T_UP_RATE_50 5 /* 50 Hz */
  51. #define MS5192T_UP_RATE_39 6 /* 39.2 Hz */
  52. #define MS5192T_UP_RATE_33 7 /* 33.3 Hz */
  53. #define MS5192T_UP_RATE_19 8 /* 19.2 Hz */
  54. #define MS5192T_UP_RATE_16 9 /* 16.7 Hz */
  55. #define MS5192T_UP_RATE_14 10 /* 14 Hz */
  56. #define MS5192T_UP_RATE_12 11 /* 12.5 Hz */
  57. #define MS5192T_UP_RATE_10 12 /* 500 Hz */
  58. #define MS5192T_UP_RATE_8 13 /* 8.33 Hz */
  59. #define MS5192T_UP_RATE_6 14 /* 6.25 Hz */
  60. #define MS5192T_UP_RATE_4 15 /* 4.17 Hz */
  61. /* Configuration Register Bit Designations (MS5192T_REG_CONF) */
  62. #define MS5192T_CONF_VBIAS(x) (((x) & 0x3) << 14) /* Bias Voltage Generator Enable */
  63. #define MS5192T_CONF_BO_EN (1 << 13) /* Burnout Current Enable */
  64. #define MS5192T_CONF_UNIPOLAR (1 << 12) /* Unipolar/Bipolar Enable */
  65. #define MS5192T_CONF_BOOST (1 << 11) /* Boost Enable */
  66. #define MS5192T_CONF_GAIN(x) (((x) & 0x7) << 8) /* Gain Select */
  67. #define MS5192T_CONF_REFSEL(x) (((x) & 0x1) << 7) /* INT/EXT Reference Select */
  68. #define MS5192T_CONF_BUF (1 << 4) /* Buffered Mode Enable */
  69. #define MS5192T_CONF_CHAN(x) ((x) & 0x7) /* Channel select */
  70. /* MS5192T_CONF_GAIN(x) options */
  71. #define MS5192T_GAIN_1 0
  72. #define MS5192T_GAIN_2 1
  73. #define MS5192T_GAIN_4 2
  74. #define MS5192T_GAIN_8 3
  75. #define MS5192T_GAIN_16 4
  76. #define MS5192T_GAIN_32 5
  77. #define MS5192T_GAIN_64 6
  78. #define MS5192T_GAIN_128 7
  79. /* MS5192T_CONF_REFSEL(x) options */
  80. #define MS5192T_REFSEL_INT 1 /* Internal Reference Selected. */
  81. #define MS5192T_REFSEL_EXT 0 /* External Reference Applied between REFIN(+) and REFIN(–). */
  82. /* MS5192T_CONF_CHAN(x) options */
  83. #define MS5192T_CH_AIN1P_AIN1M 0 /* AIN1(+) - AIN1(-) */
  84. #define MS5192T_CH_AIN2P_AIN2M 1 /* AIN2(+) - AIN2(-) */
  85. #define MS5192T_CH_AIN3P_AIN3M 2 /* AIN3(+) - AIN3(-) */
  86. #define MS5192T_CH_AIN1M_AIN1M 3 /* AIN1(-) - AIN1(-) */
  87. #define MS5192T_CH_TEMP 6 /* Temp Sensor */
  88. #define MS5192T_CH_AVDD_MONITOR 7 /* AVDD Monitor */
  89. /* ID Register Bit Designations (AD7793_REG_ID) */
  90. #define MS5192T_ID 0xA
  91. #define MS5192T_ID_MASK 0xF
  92. /* IO (Excitation Current Sources) Register Bit Designations (MS5192T_REG_IO) */
  93. #define MS5192T_IEXCDIR(x) (((x) & 0x3) << 2)
  94. #define MS5192T_IEXCEN(x) (((x) & 0x3) << 0)
  95. /* MS5192T_IEXCDIR(x) options*/
  96. #define MS5192T_DIR_IEXC1_IOUT1_IEXC2_IOUT2 0 /* IEXC1 connect to IOUT1, IEXC2 connect to IOUT2 */
  97. #define MS5192T_DIR_IEXC1_IOUT2_IEXC2_IOUT1 1 /* IEXC1 connect to IOUT2, IEXC2 connect to IOUT1 */
  98. #define MS5192T_DIR_IEXC1_IEXC2_IOUT1 2 /* Both current sources IEXC1,2 connect to IOUT1 */
  99. #define MS5192T_DIR_IEXC1_IEXC2_IOUT2 3 /* Both current sources IEXC1,2 connect to IOUT2 */
  100. /* MS5192T_IEXCEN(x) options*/
  101. #define MS5192T_EN_IXCEN_10uA 1 /* Excitation Current 10uA */
  102. #define MS5192T_EN_IXCEN_210uA 2 /* Excitation Current 210uA */
  103. #define MS5192T_EN_IXCEN_1mA 3 /* Excitation Current 1mA */
  104. /******************************************************************************/
  105. /* Functions Prototypes */
  106. /******************************************************************************/
  107. /* Initialize MS5192T and check if the device is present*/
  108. unsigned char MS5192T_Init(void);
  109. /* Sends 32 consecutive 1's on SPI in order to reset the part. */
  110. void MS5192T_Reset(void);
  111. /* Reads the value of the selected register. */
  112. unsigned long MS5192T_GetRegisterValue(unsigned char regAddress,
  113. unsigned char size,
  114. unsigned char modifyCS);
  115. /* Writes a value to the register. */
  116. void MS5192T_SetRegisterValue(unsigned char regAddress,
  117. unsigned long regValue,
  118. unsigned char size,
  119. unsigned char modifyCS);
  120. /* Waits for RDY pin to go low. */
  121. void MS5192T_WaitRdyGoLow(void);
  122. /* Sets the operating mode of MS5192T. */
  123. void MS5192T_SetMode(unsigned long mode);
  124. /* Sets update rate */
  125. void MS5192T_SetUpdateRate(unsigned long rate);
  126. /* Selects the channel of MS5192T. */
  127. void MS5192T_SetChannel(unsigned long channel);
  128. /* Sets the gain of the In-Amp. */
  129. void MS5192T_SetGain(unsigned long gain);
  130. /* Unipolar/Bipolar Enable */
  131. void MS5192T_SetPolar(unsigned long polar);
  132. /* Sets the reference source for the ADC. */
  133. void MS5192T_SetIntReference(unsigned char type);
  134. /* Performs the given calibration to the specified channel. */
  135. void MS5192T_Calibrate(unsigned char mode, unsigned char channel);
  136. /* Returns the result of a single conversion. */
  137. unsigned long MS5192T_SingleConversion(void);
  138. /* Returns the average of several conversion results. */
  139. unsigned long MS5192T_ContinuousReadAvg(unsigned char sampleNumber);
  140. #endif // _AD7793_H_