Gas Pressure Display Updated Power control for Pressure sensor added

Dependencies:   UniGraphic mbed vt100

Committer:
Rhyme
Date:
Fri Feb 16 08:27:50 2018 +0000
Revision:
0:37c8ecde13c2
control PSE530 power via PTC5 (pse530_en)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Rhyme 0:37c8ecde13c2 1 #include "mbed.h"
Rhyme 0:37c8ecde13c2 2 #include "LM75B.h"
Rhyme 0:37c8ecde13c2 3 #include "af_mgr.h"
Rhyme 0:37c8ecde13c2 4
Rhyme 0:37c8ecde13c2 5 /* Register list */
Rhyme 0:37c8ecde13c2 6 #define PTR_CONF 0x01
Rhyme 0:37c8ecde13c2 7 #define PTR_TEMP 0x00
Rhyme 0:37c8ecde13c2 8 #define PTR_TOS 0x03
Rhyme 0:37c8ecde13c2 9 #define PTR_THYST 0x02
Rhyme 0:37c8ecde13c2 10
Rhyme 0:37c8ecde13c2 11 /* Configuration register */
Rhyme 0:37c8ecde13c2 12 /* B[7:5] : Reserved */
Rhyme 0:37c8ecde13c2 13 /* B[4:3] : OS_F_QUE[1:0] OS fault queue value */
Rhyme 0:37c8ecde13c2 14 #define CONFIG_QUE_1 0x00
Rhyme 0:37c8ecde13c2 15 #define CONFIG_QUE_2 (0x01 << 3)
Rhyme 0:37c8ecde13c2 16 #define CONFIG_QUE_4 (0x10 << 3)
Rhyme 0:37c8ecde13c2 17 #define CONFIG_QUE_6 (0x11 << 3)
Rhyme 0:37c8ecde13c2 18 /* B[2] : OS_POL 0 = OS active LOW, 1 = OS active HIGH */
Rhyme 0:37c8ecde13c2 19 #define CONFIG_OS_POL_L 0x00
Rhyme 0:37c8ecde13c2 20 #define CONFIG_OS_POL_H (0x01 << 2)
Rhyme 0:37c8ecde13c2 21 /* B[1] : OS_COMP_INT 0 = OS comparator, 1 = OS interrupt */
Rhyme 0:37c8ecde13c2 22 #define CONFIG_OS_COMP 0x00
Rhyme 0:37c8ecde13c2 23 #define CONFIG_OS_INT (0x01 << 1)
Rhyme 0:37c8ecde13c2 24 /* B[0] : SHUTDOWN 0 = normal, 1 = shutdown */
Rhyme 0:37c8ecde13c2 25 #define CONFIG_NORMARL 0x00
Rhyme 0:37c8ecde13c2 26 #define CONFIG_SHUTDOWN 0x01
Rhyme 0:37c8ecde13c2 27
Rhyme 0:37c8ecde13c2 28 /* Temperature register */
Rhyme 0:37c8ecde13c2 29 /* D[15:5] = 11 bit data 0.125 * temp data */
Rhyme 0:37c8ecde13c2 30 /* D[4:0] : reserved */
Rhyme 0:37c8ecde13c2 31
Rhyme 0:37c8ecde13c2 32 /* Tos register */
Rhyme 0:37c8ecde13c2 33 /* D[15:7] = 9 bit data */
Rhyme 0:37c8ecde13c2 34 /* D[6:0] : reserved */
Rhyme 0:37c8ecde13c2 35
Rhyme 0:37c8ecde13c2 36 /* Thyst register */
Rhyme 0:37c8ecde13c2 37 /* D[15:7] = 9 ibt data */
Rhyme 0:37c8ecde13c2 38 /* D[6:0] : reserved */
Rhyme 0:37c8ecde13c2 39
Rhyme 0:37c8ecde13c2 40 LM75B::LM75B(I2C *i2c, int addr) : m_addr(addr<<1) {
Rhyme 0:37c8ecde13c2 41 p_i2c = i2c ;
Rhyme 0:37c8ecde13c2 42 p_i2c->frequency(100000); /* 100kHz */
Rhyme 0:37c8ecde13c2 43 // activate the peripheral
Rhyme 0:37c8ecde13c2 44 }
Rhyme 0:37c8ecde13c2 45
Rhyme 0:37c8ecde13c2 46 LM75B::~LM75B() { }
Rhyme 0:37c8ecde13c2 47
Rhyme 0:37c8ecde13c2 48 int LM75B::temp(int8_t *temp)
Rhyme 0:37c8ecde13c2 49 {
Rhyme 0:37c8ecde13c2 50 int result ;
Rhyme 0:37c8ecde13c2 51 char t[1] = { 0x00 } ;
Rhyme 0:37c8ecde13c2 52 result = p_i2c->write(m_addr, t, 1, true) ;
Rhyme 0:37c8ecde13c2 53 if (result == 0) {
Rhyme 0:37c8ecde13c2 54 result = p_i2c->read(m_addr, t, 1) ;
Rhyme 0:37c8ecde13c2 55 }
Rhyme 0:37c8ecde13c2 56 if (result == 0) {
Rhyme 0:37c8ecde13c2 57 *temp = (int8_t)t[0] ;
Rhyme 0:37c8ecde13c2 58 }
Rhyme 0:37c8ecde13c2 59 return( result ) ;
Rhyme 0:37c8ecde13c2 60 }
Rhyme 0:37c8ecde13c2 61
Rhyme 0:37c8ecde13c2 62 int LM75B::getTemp(float *temp)
Rhyme 0:37c8ecde13c2 63 {
Rhyme 0:37c8ecde13c2 64 int result ;
Rhyme 0:37c8ecde13c2 65 char t[2] = { 0, 0 } ;
Rhyme 0:37c8ecde13c2 66 int16_t iTemp = 0 ;
Rhyme 0:37c8ecde13c2 67 result = p_i2c->write(m_addr, t, 1) ; /* write pointer byte 0x00 */
Rhyme 0:37c8ecde13c2 68 if (result == 0) {
Rhyme 0:37c8ecde13c2 69 result = p_i2c->read(m_addr, t, 2) ; /* read MSB, LSB */
Rhyme 0:37c8ecde13c2 70 }
Rhyme 0:37c8ecde13c2 71 if (result == 0) {
Rhyme 0:37c8ecde13c2 72 iTemp = (t[0] << 8) | t[1] ;
Rhyme 0:37c8ecde13c2 73 iTemp >>= 5 ;
Rhyme 0:37c8ecde13c2 74 *temp = 0.125 * iTemp ;
Rhyme 0:37c8ecde13c2 75 }
Rhyme 0:37c8ecde13c2 76 return( result ) ;
Rhyme 0:37c8ecde13c2 77 }
Rhyme 0:37c8ecde13c2 78
Rhyme 0:37c8ecde13c2 79 int LM75B::getConfig(uint8_t ptr_byte, uint8_t *config_data)
Rhyme 0:37c8ecde13c2 80 {
Rhyme 0:37c8ecde13c2 81 int result ;
Rhyme 0:37c8ecde13c2 82 char config = 0x00 ; /* default value */
Rhyme 0:37c8ecde13c2 83 result = p_i2c->write(m_addr, (char*)(&ptr_byte), 1, true) ;
Rhyme 0:37c8ecde13c2 84 if (result == 0) {
Rhyme 0:37c8ecde13c2 85 result = p_i2c->read(m_addr, &config, 1) ;
Rhyme 0:37c8ecde13c2 86 }
Rhyme 0:37c8ecde13c2 87 if (result == 0) {
Rhyme 0:37c8ecde13c2 88 *config_data = config ;
Rhyme 0:37c8ecde13c2 89 }
Rhyme 0:37c8ecde13c2 90 return( result ) ;
Rhyme 0:37c8ecde13c2 91 }
Rhyme 0:37c8ecde13c2 92
Rhyme 0:37c8ecde13c2 93 int LM75B::setConfig(uint8_t ptr_byte, uint8_t config_data)
Rhyme 0:37c8ecde13c2 94 {
Rhyme 0:37c8ecde13c2 95 int result ;
Rhyme 0:37c8ecde13c2 96 char t[2] ;
Rhyme 0:37c8ecde13c2 97 t[0] = ptr_byte ;
Rhyme 0:37c8ecde13c2 98 t[1] = config_data ;
Rhyme 0:37c8ecde13c2 99 result = p_i2c->write(m_addr, t, 2, true) ;
Rhyme 0:37c8ecde13c2 100 return( result ) ;
Rhyme 0:37c8ecde13c2 101 }
Rhyme 0:37c8ecde13c2 102
Rhyme 0:37c8ecde13c2 103 int LM75B::readRegs(int addr, uint8_t * data, int len)
Rhyme 0:37c8ecde13c2 104 {
Rhyme 0:37c8ecde13c2 105 int result ;
Rhyme 0:37c8ecde13c2 106 char t[1] = {addr};
Rhyme 0:37c8ecde13c2 107 __disable_irq() ; // Disable Interrupts
Rhyme 0:37c8ecde13c2 108 result = p_i2c->write(m_addr, t, 1, true);
Rhyme 0:37c8ecde13c2 109 if (result == 0) {
Rhyme 0:37c8ecde13c2 110 result = p_i2c->read(m_addr, (char *)data, len);
Rhyme 0:37c8ecde13c2 111 }
Rhyme 0:37c8ecde13c2 112 __enable_irq() ; // Enable Interrupts
Rhyme 0:37c8ecde13c2 113 return( result ) ;
Rhyme 0:37c8ecde13c2 114 }
Rhyme 0:37c8ecde13c2 115
Rhyme 0:37c8ecde13c2 116 int LM75B::writeRegs(uint8_t * data, int len) {
Rhyme 0:37c8ecde13c2 117 int result ;
Rhyme 0:37c8ecde13c2 118 __disable_irq() ; // Disable Interrupts
Rhyme 0:37c8ecde13c2 119 result = p_i2c->write(m_addr, (char *)data, len);
Rhyme 0:37c8ecde13c2 120 __enable_irq() ; // Enable Interrupts
Rhyme 0:37c8ecde13c2 121 return( result ) ;
Rhyme 0:37c8ecde13c2 122 }