Test program running on MAX32625MBED. Control through USB Serial commands using a terminal emulator such as teraterm or putty.
Dependencies: MaximTinyTester CmdLine MAX541 USBDevice
Diff: MAX11043/MAX11043.cpp
- Revision:
- 91:9e78c6194d6e
- Parent:
- 90:d6ed8a8c5f26
- Child:
- 93:6b22269935a6
diff -r d6ed8a8c5f26 -r 9e78c6194d6e MAX11043/MAX11043.cpp --- a/MAX11043/MAX11043.cpp Fri Feb 28 23:46:49 2020 +0000 +++ b/MAX11043/MAX11043.cpp Mon Mar 02 11:47:44 2020 +0000 @@ -946,6 +946,7 @@ // @return 1 on success; 0 on failure uint8_t MAX11043::RegRead(MAX11043_CMD_enum_t commandByte, uint32_t* ptrRegData) { +#define SIGN_EXTEND_INT16_VALUE(x) (((x)&(0x8000))?((x)-65536):(x)) //---------------------------------------- // switch based on register address szie RegSize(regAddress) @@ -994,19 +995,35 @@ } if (commandByte == CMD_0000_0010_d16o8_Rd00_ADCa) { // TODO1: update adca - adca = (misoData[1] << 8) | misoData[2]; + // adca = (misoData[1] << 8) | misoData[2]; + // TODO1: update adca as 2's complement + // int raw_code = (misoData[1] << 8) | misoData[2]; + // if (raw_code & 0x8000) { adca = raw_code - 65536; } else { adca = raw_code; } + adca = SIGN_EXTEND_INT16_VALUE((int)(misoData[1] << 8) | misoData[2]); } if (commandByte == CMD_0000_0110_d16o8_Rd01_ADCb) { // TODO1: update adcb - adcb = (misoData[1] << 8) | misoData[2]; + // adcb = (misoData[1] << 8) | misoData[2]; + // TODO1: update adca as 2's complement + // int raw_code = (misoData[1] << 8) | misoData[2]; + // if (raw_code & 0x8000) { adca = raw_code - 65536; } else { adca = raw_code; } + adcb = SIGN_EXTEND_INT16_VALUE((int)(misoData[1] << 8) | misoData[2]); } if (commandByte == CMD_0000_1010_d16o8_Rd02_ADCc) { // TODO1: update adcc - adcc = (misoData[1] << 8) | misoData[2]; + // adcc = (misoData[1] << 8) | misoData[2]; + // TODO1: update adca as 2's complement + // int raw_code = (misoData[1] << 8) | misoData[2]; + // if (raw_code & 0x8000) { adca = raw_code - 65536; } else { adca = raw_code; } + adcc = SIGN_EXTEND_INT16_VALUE((int)(misoData[1] << 8) | misoData[2]); } if (commandByte == CMD_0000_1110_d16o8_Rd03_ADCd) { // TODO1: update adcd - adcd = (misoData[1] << 8) | misoData[2]; + // adcd = (misoData[1] << 8) | misoData[2]; + // TODO1: update adca as 2's complement + // int raw_code = (misoData[1] << 8) | misoData[2]; + // if (raw_code & 0x8000) { adca = raw_code - 65536; } else { adca = raw_code; } + adcd = SIGN_EXTEND_INT16_VALUE((int)(misoData[1] << 8) | misoData[2]); } } break; @@ -1073,15 +1090,31 @@ if (ptrRegData) { (*ptrRegData) = (misoData[1] << 8) | misoData[2]; } if (commandByte == CMD_0001_0010_d16o8_d16o8_Rd04_ADCab) { // TODO1: update adca - adca = (misoData[1] << 8) | misoData[2]; + // adca = (misoData[1] << 8) | misoData[2]; + // TODO1: update adca as 2's complement + // int raw_code = (misoData[1] << 8) | misoData[2]; + // if (raw_code & 0x8000) { adca = raw_code - 65536; } else { adca = raw_code; } + adca = SIGN_EXTEND_INT16_VALUE((int)(misoData[1] << 8) | misoData[2]); // TODO1: update adcb - adcb = (misoData[3] << 8) | misoData[4]; + // adcb = (misoData[3] << 8) | misoData[4]; + // TODO1: update adca as 2's complement + // int raw_code = (misoData[1] << 8) | misoData[2]; + // if (raw_code & 0x8000) { adca = raw_code - 65536; } else { adca = raw_code; } + adcb = SIGN_EXTEND_INT16_VALUE((int)(misoData[3] << 8) | misoData[4]); } if (commandByte == CMD_0001_0110_d16o8_d16o8_Rd05_ADCcd) { // TODO1: update adcc adcc = (misoData[1] << 8) | misoData[2]; + // TODO1: update adca as 2's complement + // int raw_code = (misoData[1] << 8) | misoData[2]; + // if (raw_code & 0x8000) { adca = raw_code - 65536; } else { adca = raw_code; } + adcc = SIGN_EXTEND_INT16_VALUE((int)(misoData[1] << 8) | misoData[2]); // TODO1: update adcd - adcd = (misoData[3] << 8) | misoData[4]; + // adcd = (misoData[3] << 8) | misoData[4]; + // TODO1: update adca as 2's complement + // int raw_code = (misoData[1] << 8) | misoData[2]; + // if (raw_code & 0x8000) { adca = raw_code - 65536; } else { adca = raw_code; } + adcd = SIGN_EXTEND_INT16_VALUE((int)(misoData[3] << 8) | misoData[4]); } } break; @@ -1157,13 +1190,33 @@ if (ptrRegData) { (*ptrRegData) = (misoData[1] << 8) | misoData[2]; } if (commandByte == CMD_0001_1010_d16o8_d16o8_d16o8_d16o8_Rd06_ADCabcd) { // TODO1: update adca - adca = (misoData[1] << 8) | misoData[2]; + // adca = (misoData[1] << 8) | misoData[2]; + // TODO1: update adca as 2's complement + // int raw_code = (misoData[1] << 8) | misoData[2]; + // if (raw_code & 0x8000) { adca = raw_code - 65536; } else { adca = raw_code; } + adca = SIGN_EXTEND_INT16_VALUE((int)(misoData[1] << 8) | misoData[2]); + // // TODO1: update adcb - adcb = (misoData[3] << 8) | misoData[4]; + // adcb = (misoData[3] << 8) | misoData[4]; + // TODO1: update adcb as 2's complement + // raw_code = (misoData[3] << 8) | misoData[4]; + // if (raw_code & 0x8000) { adcb = raw_code - 65536; } else { adcb = raw_code; } + adcb = SIGN_EXTEND_INT16_VALUE((int)(misoData[3] << 8) | misoData[4]); + // // TODO1: update adcc - adcc = (misoData[5] << 8) | misoData[6]; + // adcc = (misoData[5] << 8) | misoData[6]; + // TODO1: update adcc as 2's complement + // raw_code = (misoData[5] << 8) | misoData[6]; + // if (raw_code & 0x8000) { adcc = raw_code - 65536; } else { adcc = raw_code; } + adcc = SIGN_EXTEND_INT16_VALUE((int)(misoData[5] << 8) | misoData[6]); + // // TODO1: update adcd - adcd = (misoData[7] << 8) | misoData[8]; + // adcd = (misoData[7] << 8) | misoData[8]; + // TODO1: update adcd as 2's complement + // raw_code = (misoData[7] << 8) | misoData[8]; + // if (raw_code & 0x8000) { adcd = raw_code - 65536; } else { adcd = raw_code; } + adcd = SIGN_EXTEND_INT16_VALUE((int)(misoData[7] << 8) | misoData[8]); + // } } break;