Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
pt100.cpp
00001 #include "mbed.h" 00002 #include "uart.h" 00003 #include "interpret.h" 00004 #include "pt100.h" 00005 #include "MCP23017.h" 00006 00007 00008 00009 //--------------------------------------- 00010 // Hardware recources 00011 //--------------------------------------- 00012 MCP23017 *PT100_I2C; 00013 00014 00015 00016 //--------------------------------------- 00017 // Prototypes 00018 //--------------------------------------- 00019 unsigned char PT100_mirrowBits( unsigned char input); 00020 00021 00022 00023 //--------------------------------------- 00024 // Internal variables 00025 //--------------------------------------- 00026 00027 00028 00029 00030 //--------------------------------------- 00031 // External variables 00032 //--------------------------------------- 00033 00034 00035 00036 //--------------------------------------- 00037 // Global Functions 00038 //--------------------------------------- 00039 void PT100_init( void ) 00040 { 00041 PT100_I2C = new MCP23017( p9, p10, PT100_I2C_ADD); 00042 PT100_I2C->config(0,0,0); // set to outputs, no pull-ups, not-inverted 00043 PT100_I2C->write_mask(0, 0xFFFF); // set outputs low 00044 } 00045 00046 00047 00048 // process commands 00049 void PT100_deviceID_process( void ) 00050 { 00051 unsigned short temp16U; 00052 00053 switch( uartBuffer[ INT_BUF_COMMAND ] ) 00054 { 00055 //----------------- 00056 case PT100_COM_SET: 00057 //----------------- 00058 { 00059 // Get byte 00060 temp16U = (unsigned short)PT100_mirrowBits( uartBuffer[ INT_BUF_1DATA ]); 00061 // Write to PT100 HW 00062 PT100_I2C->write_mask(temp16U, 0x00FF); 00063 // Generate acknowledge 00064 INT_generateACKFrame(INT_ID_PT100, INT_COM_ACK); 00065 00066 break; 00067 } 00068 00069 //----------------- 00070 case PT100_COM_GET: 00071 //----------------- 00072 { 00073 temp16U = (unsigned short)PT100_mirrowBits( (unsigned char)(PT100_I2C->read_mask(0x00FF))); 00074 00075 // Generate acknowledge 00076 uartBuffer[INT_BUF_DEVICEID] = INT_ID_PT100; 00077 uartBuffer[INT_BUF_COMMAND] = INT_COM_ACK; 00078 uartBuffer[INT_BUF_NUM] = 1; 00079 uartBuffer[INT_BUF_1DATA] = (char)(0x00FF & temp16U); 00080 UART_handler.bytesToWrite = 4; 00081 00082 break; 00083 } 00084 00085 //----------------- 00086 default: 00087 //----------------- 00088 { 00089 // Command not supported 00090 INT_generateACKFrame(INT_ID_PT100, INT_COM_COM_NOTSUPP); 00091 } 00092 }//switch 00093 00094 } 00095 00096 //--------------------------------------- 00097 // Internal Functions 00098 //--------------------------------------- 00099 00100 unsigned char PT100_mirrowBits( unsigned char input) 00101 { 00102 char i; 00103 unsigned char tempChar = 0; 00104 00105 for( i = 0; i < 8; i++) 00106 { 00107 if( input & (1 << i) ) 00108 { 00109 tempChar |= (1 << 7 - i); 00110 } 00111 00112 } 00113 00114 return tempChar; 00115 }
Generated on Sat Jul 16 2022 03:23:51 by
