MicroForce Sensors, Compensated/Amplified
MicroForce_FMA.cpp@1:4b8a700b3f5c, 2021-06-30 (annotated)
- Committer:
- mcm
- Date:
- Wed Jun 30 13:29:31 2021 +0000
- Revision:
- 1:4b8a700b3f5c
- Parent:
- 0:e4146617a5fc
- Child:
- 2:2f45d928f6e0
The functions file was completed, the driver is ready to be tested.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mcm | 0:e4146617a5fc | 1 | /** |
mcm | 1:4b8a700b3f5c | 2 | * @brief MicroForce_FMA.h |
mcm | 1:4b8a700b3f5c | 3 | * @details MicroForce Sensors, Compensated/Amplified. |
mcm | 1:4b8a700b3f5c | 4 | * Functions file. |
mcm | 0:e4146617a5fc | 5 | * |
mcm | 0:e4146617a5fc | 6 | * |
mcm | 1:4b8a700b3f5c | 7 | * @return N/A |
mcm | 0:e4146617a5fc | 8 | * |
mcm | 0:e4146617a5fc | 9 | * @author Manuel Caballero |
mcm | 1:4b8a700b3f5c | 10 | * @date 29/June/2021 |
mcm | 1:4b8a700b3f5c | 11 | * @version 29/June/2021 The ORIGIN |
mcm | 1:4b8a700b3f5c | 12 | * @pre N/A. |
mcm | 1:4b8a700b3f5c | 13 | * @warning N/A |
mcm | 1:4b8a700b3f5c | 14 | * @pre This code belongs to Nimbus Centre ( https://www.nimbus.cit.ie ). |
mcm | 0:e4146617a5fc | 15 | */ |
mcm | 0:e4146617a5fc | 16 | |
mcm | 1:4b8a700b3f5c | 17 | #include "MicroForce_FMA.h" |
mcm | 0:e4146617a5fc | 18 | |
mcm | 0:e4146617a5fc | 19 | |
mcm | 1:4b8a700b3f5c | 20 | MicroForce_FMA::MicroForce_FMA ( PinName mosi, PinName miso, PinName sclk, PinName cs, uint32_t freq ) |
mcm | 0:e4146617a5fc | 21 | : _spi ( mosi, miso, sclk ) |
mcm | 0:e4146617a5fc | 22 | , _cs ( cs ) |
mcm | 0:e4146617a5fc | 23 | { |
mcm | 0:e4146617a5fc | 24 | _spi.frequency( freq ); |
mcm | 0:e4146617a5fc | 25 | } |
mcm | 0:e4146617a5fc | 26 | |
mcm | 0:e4146617a5fc | 27 | |
mcm | 1:4b8a700b3f5c | 28 | MicroForce_FMA::~MicroForce_FMA() |
mcm | 0:e4146617a5fc | 29 | { |
mcm | 0:e4146617a5fc | 30 | } |
mcm | 0:e4146617a5fc | 31 | |
mcm | 0:e4146617a5fc | 32 | |
mcm | 0:e4146617a5fc | 33 | |
mcm | 0:e4146617a5fc | 34 | /** |
mcm | 1:4b8a700b3f5c | 35 | * @brief MicroForce_FMA_GetRawForce ( MicroForce_FMA_status_bits_data_t* , uint16_t* ) |
mcm | 0:e4146617a5fc | 36 | * |
mcm | 1:4b8a700b3f5c | 37 | * @details It gets the raw force data. |
mcm | 0:e4146617a5fc | 38 | * |
mcm | 1:4b8a700b3f5c | 39 | * @param[in] N/A. |
mcm | 0:e4146617a5fc | 40 | * |
mcm | 1:4b8a700b3f5c | 41 | * @param[out] myStatus: Status bits data. |
mcm | 1:4b8a700b3f5c | 42 | * @param[out] myRawBridgeData: Raw bridge data. |
mcm | 0:e4146617a5fc | 43 | * |
mcm | 0:e4146617a5fc | 44 | * |
mcm | 1:4b8a700b3f5c | 45 | * @return Status of MicroForce_FMA_GetRawForce. |
mcm | 0:e4146617a5fc | 46 | * |
mcm | 0:e4146617a5fc | 47 | * |
mcm | 0:e4146617a5fc | 48 | * @author Manuel Caballero |
mcm | 1:4b8a700b3f5c | 49 | * @date 29/June/2021 |
mcm | 1:4b8a700b3f5c | 50 | * @version 29/June/2021 The ORIGIN |
mcm | 1:4b8a700b3f5c | 51 | * @pre N/A. |
mcm | 1:4b8a700b3f5c | 52 | * @warning N/A. |
mcm | 0:e4146617a5fc | 53 | */ |
mcm | 1:4b8a700b3f5c | 54 | MicroForce_FMA::MicroForce_FMA_status_t MicroForce_FMA::MicroForce_FMA_GetRawForce ( MicroForce_FMA_status_bits_data_t* myStatus, uint16_t* myRawBridgeData ) |
mcm | 0:e4146617a5fc | 55 | { |
mcm | 1:4b8a700b3f5c | 56 | char cmd[] = { 0, 0 }; |
mcm | 1:4b8a700b3f5c | 57 | uint32_t mySPI_status; |
mcm | 0:e4146617a5fc | 58 | |
mcm | 1:4b8a700b3f5c | 59 | /* Get the data */ |
mcm | 0:e4146617a5fc | 60 | _cs = 0; |
mcm | 1:4b8a700b3f5c | 61 | mySPI_status = _spi.write ( &cmd[0], 0U, &cmd[0], sizeof( cmd )/sizeof( cmd[0] ) ); |
mcm | 0:e4146617a5fc | 62 | _cs = 1; |
mcm | 0:e4146617a5fc | 63 | |
mcm | 1:4b8a700b3f5c | 64 | /* Parse the data */ |
mcm | 1:4b8a700b3f5c | 65 | myStatus->status_bits = (MicroForce_FMA_status_bits_t)( cmd[0] & MicroForce_FMA_STATUS_BITS_MASK ); |
mcm | 0:e4146617a5fc | 66 | |
mcm | 1:4b8a700b3f5c | 67 | *myRawBridgeData = ( cmd[0] & 0x3F ); |
mcm | 1:4b8a700b3f5c | 68 | *myRawBridgeData <<= 8U; |
mcm | 1:4b8a700b3f5c | 69 | *myRawBridgeData |= cmd[1]; |
mcm | 1:4b8a700b3f5c | 70 | |
mcm | 1:4b8a700b3f5c | 71 | if ( ( mySPI_status / ( sizeof( cmd )/sizeof( cmd[0] ) ) ) == SPI_SUCCESS ) { |
mcm | 1:4b8a700b3f5c | 72 | return MicroForce_FMA_SUCCESS; |
mcm | 1:4b8a700b3f5c | 73 | } else { |
mcm | 1:4b8a700b3f5c | 74 | return MicroForce_FMA_FAILURE; |
mcm | 1:4b8a700b3f5c | 75 | } |
mcm | 0:e4146617a5fc | 76 | } |
mcm | 0:e4146617a5fc | 77 | |
mcm | 0:e4146617a5fc | 78 | |
mcm | 0:e4146617a5fc | 79 | |
mcm | 0:e4146617a5fc | 80 | /** |
mcm | 1:4b8a700b3f5c | 81 | * @brief MicroForce_FMA_SoftwareShutdown ( MicroForce_FMA_transfer_function_t , char , uint16_t ) |
mcm | 0:e4146617a5fc | 82 | * |
mcm | 1:4b8a700b3f5c | 83 | * @details It calculates the force data in Newton (N). |
mcm | 0:e4146617a5fc | 84 | * |
mcm | 1:4b8a700b3f5c | 85 | * @param[in] myBridgeData: Raw bridge data. |
mcm | 1:4b8a700b3f5c | 86 | * @param[in] myCalibration: Calibration point. |
mcm | 1:4b8a700b3f5c | 87 | * @param[in] myForceRange: Force range. |
mcm | 0:e4146617a5fc | 88 | * |
mcm | 1:4b8a700b3f5c | 89 | * @param[out] N/A |
mcm | 0:e4146617a5fc | 90 | * |
mcm | 0:e4146617a5fc | 91 | * |
mcm | 1:4b8a700b3f5c | 92 | * @return Force value in Newton. |
mcm | 0:e4146617a5fc | 93 | * |
mcm | 0:e4146617a5fc | 94 | * |
mcm | 0:e4146617a5fc | 95 | * @author Manuel Caballero |
mcm | 1:4b8a700b3f5c | 96 | * @date 29/June/2021 |
mcm | 1:4b8a700b3f5c | 97 | * @version 29/June/2021 The ORIGIN |
mcm | 1:4b8a700b3f5c | 98 | * @pre The function: MicroForce_FMA_GetRawForce must be called to update the bridge data values. |
mcm | 1:4b8a700b3f5c | 99 | * @warning N/A. |
mcm | 0:e4146617a5fc | 100 | */ |
mcm | 1:4b8a700b3f5c | 101 | float MicroForce_FMA::MicroForce_FMA_CalculateForce ( MicroForce_FMA_transfer_function_t myCalibration, uint8_t myForceRange, uint16_t myRawBridgeData ) |
mcm | 0:e4146617a5fc | 102 | { |
mcm | 1:4b8a700b3f5c | 103 | uint16_t output_max; |
mcm | 1:4b8a700b3f5c | 104 | uint16_t output_min; |
mcm | 0:e4146617a5fc | 105 | |
mcm | 0:e4146617a5fc | 106 | |
mcm | 1:4b8a700b3f5c | 107 | /* It calculates the calibration point depending on the Transfer Function point of the device selected. ( Datasheet. FIGURE 2. NOMENCLATURE AND ORDER GUIDE 32347833 Issue D ) */ |
mcm | 1:4b8a700b3f5c | 108 | if ( myCalibration == MicroForce_FMA_TRANSFER_FUNCTION_10_TO_90 ) { |
mcm | 1:4b8a700b3f5c | 109 | output_max = 14745U; |
mcm | 1:4b8a700b3f5c | 110 | output_min = 1638U; |
mcm | 1:4b8a700b3f5c | 111 | } else { |
mcm | 1:4b8a700b3f5c | 112 | output_max = 13107U; |
mcm | 1:4b8a700b3f5c | 113 | output_min = 3276U; |
mcm | 1:4b8a700b3f5c | 114 | } |
mcm | 0:e4146617a5fc | 115 | |
mcm | 0:e4146617a5fc | 116 | |
mcm | 1:4b8a700b3f5c | 117 | /* It calculates the force in N */ |
mcm | 1:4b8a700b3f5c | 118 | return (float)( ( myRawBridgeData - output_min ) * myForceRange )/( output_max - output_min ); |
mcm | 0:e4146617a5fc | 119 | } |
mcm | 0:e4146617a5fc | 120 | |
mcm | 0:e4146617a5fc | 121 | |
mcm | 0:e4146617a5fc | 122 | |
mcm | 0:e4146617a5fc | 123 | /** |
mcm | 1:4b8a700b3f5c | 124 | * @brief MicroForce_FMA_GetRaw8bitTemperature ( MicroForce_FMA_status_bits_data_t* , char* ) |
mcm | 0:e4146617a5fc | 125 | * |
mcm | 1:4b8a700b3f5c | 126 | * @details It gets the raw 8-bit temperature. |
mcm | 0:e4146617a5fc | 127 | * |
mcm | 1:4b8a700b3f5c | 128 | * @param[in] N/A |
mcm | 0:e4146617a5fc | 129 | * |
mcm | 1:4b8a700b3f5c | 130 | * @param[out] myStatus: Status bits data. |
mcm | 1:4b8a700b3f5c | 131 | * @param[out] myRaw8bitTemp: Raw 8-bit Temperature data. |
mcm | 0:e4146617a5fc | 132 | * |
mcm | 0:e4146617a5fc | 133 | * |
mcm | 1:4b8a700b3f5c | 134 | * @return Status of MicroForce_FMA_GetRaw8bitTemperature. |
mcm | 0:e4146617a5fc | 135 | * |
mcm | 0:e4146617a5fc | 136 | * |
mcm | 0:e4146617a5fc | 137 | * @author Manuel Caballero |
mcm | 1:4b8a700b3f5c | 138 | * @date 29/June/2021 |
mcm | 1:4b8a700b3f5c | 139 | * @version 29/June/2021 The ORIGIN |
mcm | 1:4b8a700b3f5c | 140 | * @pre N/A. |
mcm | 1:4b8a700b3f5c | 141 | * @warning N/A. |
mcm | 0:e4146617a5fc | 142 | */ |
mcm | 1:4b8a700b3f5c | 143 | MicroForce_FMA::MicroForce_FMA_status_t MicroForce_FMA::MicroForce_FMA_GetRaw8bitTemperature ( MicroForce_FMA_status_bits_data_t* myStatus, uint8_t* myRaw8bitTemp ) |
mcm | 0:e4146617a5fc | 144 | { |
mcm | 1:4b8a700b3f5c | 145 | char cmd[] = { 0, 0, 0 }; |
mcm | 1:4b8a700b3f5c | 146 | uint32_t mySPI_status; |
mcm | 1:4b8a700b3f5c | 147 | |
mcm | 1:4b8a700b3f5c | 148 | /* Get the data */ |
mcm | 1:4b8a700b3f5c | 149 | _cs = 0; |
mcm | 1:4b8a700b3f5c | 150 | mySPI_status = _spi.write ( &cmd[0], 0U, &cmd[0], sizeof( cmd )/sizeof( cmd[0] ) ); |
mcm | 1:4b8a700b3f5c | 151 | _cs = 1; |
mcm | 1:4b8a700b3f5c | 152 | |
mcm | 1:4b8a700b3f5c | 153 | /* Parse the data */ |
mcm | 1:4b8a700b3f5c | 154 | myStatus->status_bits = (MicroForce_FMA_status_bits_t)( cmd[0] & MicroForce_FMA_STATUS_BITS_MASK ); |
mcm | 1:4b8a700b3f5c | 155 | |
mcm | 1:4b8a700b3f5c | 156 | *myRaw8bitTemp = cmd[2]; |
mcm | 0:e4146617a5fc | 157 | |
mcm | 0:e4146617a5fc | 158 | |
mcm | 1:4b8a700b3f5c | 159 | if ( ( mySPI_status / ( sizeof( cmd )/sizeof( cmd[0] ) ) ) == SPI_SUCCESS ) { |
mcm | 1:4b8a700b3f5c | 160 | return MicroForce_FMA_SUCCESS; |
mcm | 1:4b8a700b3f5c | 161 | } else { |
mcm | 1:4b8a700b3f5c | 162 | return MicroForce_FMA_FAILURE; |
mcm | 1:4b8a700b3f5c | 163 | } |
mcm | 0:e4146617a5fc | 164 | } |
mcm | 0:e4146617a5fc | 165 | |
mcm | 0:e4146617a5fc | 166 | |
mcm | 0:e4146617a5fc | 167 | |
mcm | 0:e4146617a5fc | 168 | /** |
mcm | 1:4b8a700b3f5c | 169 | * @brief MicroForce_FMA_GetRaw11bitTemperature ( MicroForce_FMA_status_bits_data_t* , uint16_t* ) |
mcm | 0:e4146617a5fc | 170 | * |
mcm | 1:4b8a700b3f5c | 171 | * @details It gets the raw 11-bit temperature. |
mcm | 0:e4146617a5fc | 172 | * |
mcm | 1:4b8a700b3f5c | 173 | * @param[in] N/A. |
mcm | 0:e4146617a5fc | 174 | * |
mcm | 1:4b8a700b3f5c | 175 | * @param[out] myStatus: Status bits data. |
mcm | 1:4b8a700b3f5c | 176 | * @param[out] myRaw11bitTemp: Raw 11-bit Temperature data. |
mcm | 0:e4146617a5fc | 177 | * |
mcm | 0:e4146617a5fc | 178 | * |
mcm | 1:4b8a700b3f5c | 179 | * @return Status of MicroForce_FMA_GetRaw11bitTemperature. |
mcm | 0:e4146617a5fc | 180 | * |
mcm | 0:e4146617a5fc | 181 | * |
mcm | 0:e4146617a5fc | 182 | * @author Manuel Caballero |
mcm | 1:4b8a700b3f5c | 183 | * @date 29/June/2021 |
mcm | 1:4b8a700b3f5c | 184 | * @version 29/June/2021 The ORIGIN |
mcm | 1:4b8a700b3f5c | 185 | * @pre N/A. |
mcm | 1:4b8a700b3f5c | 186 | * @warning N/A. |
mcm | 0:e4146617a5fc | 187 | */ |
mcm | 1:4b8a700b3f5c | 188 | MicroForce_FMA::MicroForce_FMA_status_t MicroForce_FMA::MicroForce_FMA_GetRaw11bitTemperature ( MicroForce_FMA_status_bits_data_t* myStatus, uint16_t* myRaw11bitTemp ) |
mcm | 0:e4146617a5fc | 189 | { |
mcm | 1:4b8a700b3f5c | 190 | char cmd[] = { 0, 0, 0, 0 }; |
mcm | 1:4b8a700b3f5c | 191 | uint32_t mySPI_status; |
mcm | 1:4b8a700b3f5c | 192 | |
mcm | 1:4b8a700b3f5c | 193 | /* Get the data */ |
mcm | 1:4b8a700b3f5c | 194 | _cs = 0; |
mcm | 1:4b8a700b3f5c | 195 | mySPI_status = _spi.write ( &cmd[0], 0U, &cmd[0], sizeof( cmd )/sizeof( cmd[0] ) ); |
mcm | 1:4b8a700b3f5c | 196 | _cs = 1; |
mcm | 1:4b8a700b3f5c | 197 | |
mcm | 1:4b8a700b3f5c | 198 | /* Parse the data */ |
mcm | 1:4b8a700b3f5c | 199 | myStatus->status_bits = (MicroForce_FMA_status_bits_t)( cmd[0] & MicroForce_FMA_STATUS_BITS_MASK ); |
mcm | 1:4b8a700b3f5c | 200 | |
mcm | 1:4b8a700b3f5c | 201 | *myRaw11bitTemp = cmd[2]; |
mcm | 1:4b8a700b3f5c | 202 | *myRaw11bitTemp <<= 8U; |
mcm | 1:4b8a700b3f5c | 203 | *myRaw11bitTemp |= cmd[3]; |
mcm | 1:4b8a700b3f5c | 204 | |
mcm | 1:4b8a700b3f5c | 205 | *myRaw11bitTemp >>= 5U; |
mcm | 0:e4146617a5fc | 206 | |
mcm | 0:e4146617a5fc | 207 | |
mcm | 1:4b8a700b3f5c | 208 | if ( ( mySPI_status / ( sizeof( cmd )/sizeof( cmd[0] ) ) ) == SPI_SUCCESS ) { |
mcm | 1:4b8a700b3f5c | 209 | return MicroForce_FMA_SUCCESS; |
mcm | 1:4b8a700b3f5c | 210 | } else { |
mcm | 1:4b8a700b3f5c | 211 | return MicroForce_FMA_FAILURE; |
mcm | 1:4b8a700b3f5c | 212 | } |
mcm | 0:e4146617a5fc | 213 | } |
mcm | 0:e4146617a5fc | 214 | |
mcm | 0:e4146617a5fc | 215 | |
mcm | 0:e4146617a5fc | 216 | |
mcm | 0:e4146617a5fc | 217 | /** |
mcm | 1:4b8a700b3f5c | 218 | * @brief MicroForce_FMA_Calculate8bitTemperature ( char ) |
mcm | 0:e4146617a5fc | 219 | * |
mcm | 1:4b8a700b3f5c | 220 | * @details It calculates the 8-bit temperature in Celsius degree. |
mcm | 0:e4146617a5fc | 221 | * |
mcm | 1:4b8a700b3f5c | 222 | * @param[in] myRawTemperature: Raw 8-bit temperature value. |
mcm | 0:e4146617a5fc | 223 | * |
mcm | 1:4b8a700b3f5c | 224 | * @param[out] N/A |
mcm | 0:e4146617a5fc | 225 | * |
mcm | 0:e4146617a5fc | 226 | * |
mcm | 1:4b8a700b3f5c | 227 | * @return Temperature value in Celsius degree. |
mcm | 0:e4146617a5fc | 228 | * |
mcm | 0:e4146617a5fc | 229 | * |
mcm | 0:e4146617a5fc | 230 | * @author Manuel Caballero |
mcm | 1:4b8a700b3f5c | 231 | * @date 29/June/2021 |
mcm | 1:4b8a700b3f5c | 232 | * @version 29/June/2021 The ORIGIN |
mcm | 1:4b8a700b3f5c | 233 | * @pre The function:MicroForce_FMA_GetRaw8bitTemperature must be called to update the temperature value. |
mcm | 1:4b8a700b3f5c | 234 | * @warning N/A. |
mcm | 0:e4146617a5fc | 235 | */ |
mcm | 1:4b8a700b3f5c | 236 | float MicroForce_FMA::MicroForce_FMA_Calculate8bitTemperature ( uint8_t myRawTemperature ) |
mcm | 0:e4146617a5fc | 237 | { |
mcm | 1:4b8a700b3f5c | 238 | uint16_t aux_temp; |
mcm | 0:e4146617a5fc | 239 | |
mcm | 1:4b8a700b3f5c | 240 | /* It processes the data correctly. ( Datasheet. Equation 3: Temperature Conversion Function */ |
mcm | 1:4b8a700b3f5c | 241 | aux_temp = (uint16_t)myRawTemperature; |
mcm | 1:4b8a700b3f5c | 242 | aux_temp <<= 3U; |
mcm | 1:4b8a700b3f5c | 243 | aux_temp &= 0x7F8; |
mcm | 0:e4146617a5fc | 244 | |
mcm | 1:4b8a700b3f5c | 245 | /* It calculates the temperature in C */ |
mcm | 1:4b8a700b3f5c | 246 | return (float)( ( ( aux_temp / 2047.0 ) * 200.0 ) - 50.0 ); |
mcm | 0:e4146617a5fc | 247 | } |
mcm | 0:e4146617a5fc | 248 | |
mcm | 0:e4146617a5fc | 249 | |
mcm | 0:e4146617a5fc | 250 | |
mcm | 0:e4146617a5fc | 251 | /** |
mcm | 1:4b8a700b3f5c | 252 | * @brief MicroForce_FMA_Calculate11bitTemperature ( uint16_t ) |
mcm | 0:e4146617a5fc | 253 | * |
mcm | 1:4b8a700b3f5c | 254 | * @details It calculates the 11-bit temperature in Celsius degree. |
mcm | 0:e4146617a5fc | 255 | * |
mcm | 1:4b8a700b3f5c | 256 | * @param[in] myRawTemperature: Raw 11-bit temperature value. |
mcm | 0:e4146617a5fc | 257 | * |
mcm | 1:4b8a700b3f5c | 258 | * @param[out] N/A |
mcm | 0:e4146617a5fc | 259 | * |
mcm | 0:e4146617a5fc | 260 | * |
mcm | 1:4b8a700b3f5c | 261 | * @return Temperature value in Celsius degree. |
mcm | 0:e4146617a5fc | 262 | * |
mcm | 0:e4146617a5fc | 263 | * |
mcm | 0:e4146617a5fc | 264 | * @author Manuel Caballero |
mcm | 1:4b8a700b3f5c | 265 | * @date 29/June/2021 |
mcm | 1:4b8a700b3f5c | 266 | * @version 29/June/2021 The ORIGIN |
mcm | 1:4b8a700b3f5c | 267 | * @pre The function:MicroForce_FMA_GetRaw11bitTemperature must be called to update the temperature value. |
mcm | 1:4b8a700b3f5c | 268 | * @warning N/A. |
mcm | 0:e4146617a5fc | 269 | */ |
mcm | 1:4b8a700b3f5c | 270 | float MicroForce_FMA::MicroForce_FMA_Calculate11bitTemperature ( uint16_t myRawTemperature ) |
mcm | 0:e4146617a5fc | 271 | { |
mcm | 1:4b8a700b3f5c | 272 | /* It calculates the temperature in C */ |
mcm | 1:4b8a700b3f5c | 273 | return (float)( ( ( myRawTemperature / 2047.0 ) * 200.0 ) - 50.0 ); |
mcm | 1:4b8a700b3f5c | 274 | } |
mcm | 0:e4146617a5fc | 275 | |
mcm | 0:e4146617a5fc | 276 | |
mcm | 0:e4146617a5fc | 277 | |
mcm | 1:4b8a700b3f5c | 278 | /** |
mcm | 1:4b8a700b3f5c | 279 | * @brief MicroForce_FMA_GetAllRawData ( MicroForce_FMA_status_bits_data_t* , uint16_t* , uint16_t* ) |
mcm | 1:4b8a700b3f5c | 280 | * |
mcm | 1:4b8a700b3f5c | 281 | * @details It gets the all raw data ( bridge data and 11-bit temperature ). |
mcm | 1:4b8a700b3f5c | 282 | * |
mcm | 1:4b8a700b3f5c | 283 | * @param[in] N/A. |
mcm | 1:4b8a700b3f5c | 284 | * |
mcm | 1:4b8a700b3f5c | 285 | * @param[out] myStatus: Status bits data. |
mcm | 1:4b8a700b3f5c | 286 | * @param[out] myRawBridgeData: Raw bridge data. |
mcm | 1:4b8a700b3f5c | 287 | * @param[out] myRaw11bitTemp: Raw 11-bit Temperature data. |
mcm | 1:4b8a700b3f5c | 288 | * |
mcm | 1:4b8a700b3f5c | 289 | * |
mcm | 1:4b8a700b3f5c | 290 | * @return Status of MicroForce_FMA_GetAllRawData. |
mcm | 1:4b8a700b3f5c | 291 | * |
mcm | 1:4b8a700b3f5c | 292 | * |
mcm | 1:4b8a700b3f5c | 293 | * @author Manuel Caballero |
mcm | 1:4b8a700b3f5c | 294 | * @date 29/June/2021 |
mcm | 1:4b8a700b3f5c | 295 | * @version 29/June/2021 The ORIGIN |
mcm | 1:4b8a700b3f5c | 296 | * @pre N/A. |
mcm | 1:4b8a700b3f5c | 297 | * @warning N/A. |
mcm | 1:4b8a700b3f5c | 298 | */ |
mcm | 1:4b8a700b3f5c | 299 | MicroForce_FMA::MicroForce_FMA_status_t MicroForce_FMA::MicroForce_FMA_GetAllRawData ( MicroForce_FMA_status_bits_data_t* myStatus, uint16_t* myRawBridgeData, uint16_t* myRaw11bitTemp ) |
mcm | 1:4b8a700b3f5c | 300 | { |
mcm | 1:4b8a700b3f5c | 301 | char cmd[] = { 0, 0, 0, 0 }; |
mcm | 1:4b8a700b3f5c | 302 | uint32_t mySPI_status; |
mcm | 1:4b8a700b3f5c | 303 | |
mcm | 1:4b8a700b3f5c | 304 | /* Get the data */ |
mcm | 1:4b8a700b3f5c | 305 | _cs = 0; |
mcm | 1:4b8a700b3f5c | 306 | mySPI_status = _spi.write ( &cmd[0], 0U, &cmd[0], sizeof( cmd )/sizeof( cmd[0] ) ); |
mcm | 1:4b8a700b3f5c | 307 | _cs = 1; |
mcm | 1:4b8a700b3f5c | 308 | |
mcm | 1:4b8a700b3f5c | 309 | /* Parse the data */ |
mcm | 1:4b8a700b3f5c | 310 | myStatus->status_bits = (MicroForce_FMA_status_bits_t)( cmd[0] & MicroForce_FMA_STATUS_BITS_MASK ); |
mcm | 1:4b8a700b3f5c | 311 | |
mcm | 1:4b8a700b3f5c | 312 | *myRawBridgeData = ( cmd[0] & 0x3F ); |
mcm | 1:4b8a700b3f5c | 313 | *myRawBridgeData <<= 8U; |
mcm | 1:4b8a700b3f5c | 314 | *myRawBridgeData |= cmd[1]; |
mcm | 1:4b8a700b3f5c | 315 | |
mcm | 1:4b8a700b3f5c | 316 | *myRaw11bitTemp = cmd[2]; |
mcm | 1:4b8a700b3f5c | 317 | *myRaw11bitTemp <<= 8U; |
mcm | 1:4b8a700b3f5c | 318 | *myRaw11bitTemp |= cmd[3]; |
mcm | 1:4b8a700b3f5c | 319 | |
mcm | 1:4b8a700b3f5c | 320 | *myRaw11bitTemp >>= 5U; |
mcm | 1:4b8a700b3f5c | 321 | |
mcm | 1:4b8a700b3f5c | 322 | |
mcm | 1:4b8a700b3f5c | 323 | if ( ( mySPI_status / ( sizeof( cmd )/sizeof( cmd[0] ) ) ) == SPI_SUCCESS ) { |
mcm | 1:4b8a700b3f5c | 324 | return MicroForce_FMA_SUCCESS; |
mcm | 1:4b8a700b3f5c | 325 | } else { |
mcm | 1:4b8a700b3f5c | 326 | return MicroForce_FMA_FAILURE; |
mcm | 1:4b8a700b3f5c | 327 | } |
mcm | 0:e4146617a5fc | 328 | } |