Test program running on MAX32625MBED. Control through USB Serial commands using a terminal emulator such as teraterm or putty.
Dependencies: MaximTinyTester MAX11410 CmdLine USBDevice
Revision 25:a2afb91c605a, committed 2019-07-25
- Comitter:
- whismanoid
- Date:
- Thu Jul 25 16:22:53 2019 -0700
- Parent:
- 24:c03e67c9a1e7
- Child:
- 26:89e860decd94
- Commit message:
- MAX11410 WIP buildable, need test
Changed in this revision
--- a/MAX11410.cpp Thu Jul 25 03:56:51 2019 -0700 +++ b/MAX11410.cpp Thu Jul 25 16:22:53 2019 -0700 @@ -207,6 +207,176 @@ // return misoData16; } +// CODE GENERATOR: extern function requirement MAX11410::SPIreadWrite16bits +// SPI read and write 16 bits +// SPI interface to MAX11410 shift 16 bits mosiData16 into MAX11410 DIN +// while simultaneously capturing 16 bits miso data from MAX11410 DOUT +// +int16_t MAX11410::SPIreadWrite16bits(int16_t mosiData16) +{ + // CODE GENERATOR: extern function definition for function SPIreadWrite16bits + // TODO1: CODE GENERATOR: extern function definition for standard SPI interface function SPIreadWrite16bits(int16_t mosiData16) + size_t byteCount = 2; + static char mosiData[2]; + static char misoData[2]; + mosiData[0] = (char)((mosiData16 >> 8) & 0xFF); // MSByte + mosiData[1] = (char)((mosiData16 >> 0) & 0xFF); // LSByte + // + // Arduino: begin critical section: noInterrupts() masks all interrupt sources; end critical section with interrupts() + //~ noInterrupts(); + // + //~ digitalWrite(Scope_Trigger_Pin, LOW); // diagnostic Scope_Trigger_Pin + // + unsigned int numBytesTransferred = m_spi.write(mosiData, byteCount, misoData, byteCount); + //~ m_spi.transfer(mosiData8_FF0000); + //~ m_spi.transfer(mosiData16_00FF00); + //~ m_spi.transfer(mosiData16_0000FF); + // + //~ digitalWrite(Scope_Trigger_Pin, HIGH); // diagnostic Scope_Trigger_Pin + // + // Arduino: begin critical section: noInterrupts() masks all interrupt sources; end critical section with interrupts() + //~ interrupts(); + // + // VERIFY: SPIwrite24bits print diagnostic information + //cmdLine.serial().printf(" MOSI->")); + //cmdLine.serial().printf(" 0x")); + //Serial.print( (mosiData8_FF0000 & 0xFF), HEX); + //cmdLine.serial().printf(" 0x")); + //Serial.print( (mosiData16_00FF00 & 0xFF), HEX); + //cmdLine.serial().printf(" 0x")); + //Serial.print( (mosiData16_0000FF & 0xFF), HEX); + // hex dump mosiData[0..byteCount-1] +#if 0 // HAS_MICROUSBSERIAL + cmdLine_microUSBserial.serial().printf("\r\nSPI"); + if (byteCount > 7) { + cmdLine_microUSBserial.serial().printf(" byteCount:%d", byteCount); + } + cmdLine_microUSBserial.serial().printf(" MOSI->"); + for (unsigned int byteIndex = 0; byteIndex < byteCount; byteIndex++) + { + cmdLine_microUSBserial.serial().printf(" 0x%2.2X", mosiData[byteIndex]); + } + // hex dump misoData[0..byteCount-1] + cmdLine_microUSBserial.serial().printf(" MISO<-"); + for (unsigned int byteIndex = 0; byteIndex < numBytesTransferred; byteIndex++) + { + cmdLine_microUSBserial.serial().printf(" 0x%2.2X", misoData[byteIndex]); + } + cmdLine_microUSBserial.serial().printf(" "); +#endif +#if 0 // HAS_DAPLINK_SERIAL + cmdLine_DAPLINKserial.serial().printf("\r\nSPI"); + if (byteCount > 7) { + cmdLine_DAPLINKserial.serial().printf(" byteCount:%d", byteCount); + } + cmdLine_DAPLINKserial.serial().printf(" MOSI->"); + for (unsigned int byteIndex = 0; byteIndex < byteCount; byteIndex++) + { + cmdLine_DAPLINKserial.serial().printf(" 0x%2.2X", mosiData[byteIndex]); + } + // hex dump misoData[0..byteCount-1] + cmdLine_DAPLINKserial.serial().printf(" MISO<-"); + for (unsigned int byteIndex = 0; byteIndex < numBytesTransferred; byteIndex++) + { + cmdLine_DAPLINKserial.serial().printf(" 0x%2.2X", misoData[byteIndex]); + } + cmdLine_DAPLINKserial.serial().printf(" "); +#endif + // VERIFY: DIAGNOSTIC: print MAX5715 device register write + // TODO: MAX5715_print_register_verbose(mosiData8_FF0000, mosiData16_00FFFF); + // TODO: print_verbose_SPI_diagnostic(mosiData16_FF00, mosiData16_00FF, misoData16_FF00, misoData16_00FF); + // + //int misoData16 = (misoData16_FF00 << 8) | misoData16_00FF; + int misoData16 = (misoData[0] << 8) | misoData[1]; + return misoData16; +} + +// CODE GENERATOR: extern function requirement MAX11410::SPIreadWrite32bits +// SPI read and write 32 bits +// SPI interface to MAX11410 shift 32 bits mosiData into MAX11410 DIN +// while simultaneously capturing 32 bits miso data from MAX11410 DOUT +// +int32_t MAX11410::SPIreadWrite32bits(int32_t mosiData32) +{ + // CODE GENERATOR: extern function definition for function SPIreadWrite32bits + // TODO1: CODE GENERATOR: extern function definition for standard SPI interface function SPIreadWrite32bits(int32_t mosiData32) + size_t byteCount = 4; + static char mosiData[4]; + static char misoData[4]; + mosiData[0] = (char)((mosiData32 >> 24) & 0xFF); // MSByte + mosiData[1] = (char)((mosiData32 >> 16) & 0xFF); + mosiData[2] = (char)((mosiData32 >> 8) & 0xFF); + mosiData[3] = (char)((mosiData32 >> 0) & 0xFF); // LSByte + // + // Arduino: begin critical section: noInterrupts() masks all interrupt sources; end critical section with interrupts() + //~ noInterrupts(); + // + //~ digitalWrite(Scope_Trigger_Pin, LOW); // diagnostic Scope_Trigger_Pin + // + unsigned int numBytesTransferred = m_spi.write(mosiData, byteCount, misoData, byteCount); + //~ m_spi.transfer(mosiData8_FF0000); + //~ m_spi.transfer(mosiData16_00FF00); + //~ m_spi.transfer(mosiData16_0000FF); + // + //~ digitalWrite(Scope_Trigger_Pin, HIGH); // diagnostic Scope_Trigger_Pin + // + // Arduino: begin critical section: noInterrupts() masks all interrupt sources; end critical section with interrupts() + //~ interrupts(); + // + // VERIFY: SPIwrite24bits print diagnostic information + //cmdLine.serial().printf(" MOSI->")); + //cmdLine.serial().printf(" 0x")); + //Serial.print( (mosiData8_FF0000 & 0xFF), HEX); + //cmdLine.serial().printf(" 0x")); + //Serial.print( (mosiData16_00FF00 & 0xFF), HEX); + //cmdLine.serial().printf(" 0x")); + //Serial.print( (mosiData16_0000FF & 0xFF), HEX); + // hex dump mosiData[0..byteCount-1] +#if 0 // HAS_MICROUSBSERIAL + cmdLine_microUSBserial.serial().printf("\r\nSPI"); + if (byteCount > 7) { + cmdLine_microUSBserial.serial().printf(" byteCount:%d", byteCount); + } + cmdLine_microUSBserial.serial().printf(" MOSI->"); + for (unsigned int byteIndex = 0; byteIndex < byteCount; byteIndex++) + { + cmdLine_microUSBserial.serial().printf(" 0x%2.2X", mosiData[byteIndex]); + } + // hex dump misoData[0..byteCount-1] + cmdLine_microUSBserial.serial().printf(" MISO<-"); + for (unsigned int byteIndex = 0; byteIndex < numBytesTransferred; byteIndex++) + { + cmdLine_microUSBserial.serial().printf(" 0x%2.2X", misoData[byteIndex]); + } + cmdLine_microUSBserial.serial().printf(" "); +#endif +#if 0 // HAS_DAPLINK_SERIAL + cmdLine_DAPLINKserial.serial().printf("\r\nSPI"); + if (byteCount > 7) { + cmdLine_DAPLINKserial.serial().printf(" byteCount:%d", byteCount); + } + cmdLine_DAPLINKserial.serial().printf(" MOSI->"); + for (unsigned int byteIndex = 0; byteIndex < byteCount; byteIndex++) + { + cmdLine_DAPLINKserial.serial().printf(" 0x%2.2X", mosiData[byteIndex]); + } + // hex dump misoData[0..byteCount-1] + cmdLine_DAPLINKserial.serial().printf(" MISO<-"); + for (unsigned int byteIndex = 0; byteIndex < numBytesTransferred; byteIndex++) + { + cmdLine_DAPLINKserial.serial().printf(" 0x%2.2X", misoData[byteIndex]); + } + cmdLine_DAPLINKserial.serial().printf(" "); +#endif + // VERIFY: DIAGNOSTIC: print MAX5715 device register write + // TODO: MAX5715_print_register_verbose(mosiData8_FF0000, mosiData16_00FFFF); + // TODO: print_verbose_SPI_diagnostic(mosiData16_FF00, mosiData16_00FF, misoData16_FF00, misoData16_00FF); + // + //int misoData32 = (misoData32_FF000000 << 24) | (misoData32_FF0000 << 16) | (misoData32_0000FF00 << 8) | misoData32_000000FF; + int misoData32 = (misoData[0] << 24) | (misoData[1] << 16) | (misoData[2] << 8) | misoData[3]; + return misoData32; +} + // CODE GENERATOR: class member function definitions //---------------------------------------- // Initialize device @@ -258,9 +428,9 @@ // @return 1 on success; 0 on failure uint8_t MAX11410::Write_8bit(MAX11410_CMD_enum_t regAddress, uint8_t regData) { - - //---------------------------------------- - // warning -- WIP work in progress + + //---------------------------------------- + // warning -- WIP work in progress #warning "Not Implemented Yet: MAX11410::Write_8bit..." //---------------------------------------- @@ -289,9 +459,9 @@ // @return 1 on success; 0 on failure uint8_t MAX11410::Read_8bit(MAX11410_CMD_enum_t regAddress, uint8_t* ptrRegData) { - - //---------------------------------------- - // warning -- WIP work in progress + + //---------------------------------------- + // warning -- WIP work in progress #warning "Not Implemented Yet: MAX11410::Read_8bit..." //---------------------------------------- @@ -301,7 +471,7 @@ int16_t misoData16 = SPIreadWrite16bits(mosiData16); SPIoutputCS(1); (*ptrRegData) = (misoData16 & 0x00FF); - + //---------------------------------------- // success return 1; @@ -321,13 +491,13 @@ // @return 1 on success; 0 on failure uint8_t MAX11410::Write_16bit(MAX11410_CMD_enum_t regAddress, uint16_t regData) { - - //---------------------------------------- - // warning -- WIP work in progress + + //---------------------------------------- + // warning -- WIP work in progress #warning "Not Implemented Yet: MAX11410::Write_16bit..." //---------------------------------------- - // SPI write 32-bit (24-bit) mosiData32 and read misoData32 + // SPI write 32-bit (24-bit) mosiData32 and read misoData32 int32_t mosiData32 = ((int32_t)regAddress << 8) | ((int32_t)regData); SPIoutputCS(0); int32_t misoData32 = SPIreadWrite32bits(mosiData32); @@ -352,19 +522,19 @@ // @return 1 on success; 0 on failure uint8_t MAX11410::Read_16bit(MAX11410_CMD_enum_t regAddress, uint16_t* ptrRegData) { - - //---------------------------------------- - // warning -- WIP work in progress + + //---------------------------------------- + // warning -- WIP work in progress #warning "Not Implemented Yet: MAX11410::Read_16bit..." //---------------------------------------- - // SPI write 32-bit (24-bit) mosiData32 and read misoData32 + // SPI write 32-bit (24-bit) mosiData32 and read misoData32 int32_t mosiData32 = ((CMD_1aaa_aaaa_REGISTER_READ | (int32_t)regAddress) << 16); SPIoutputCS(0); int32_t misoData32 = SPIreadWrite32bits(mosiData32); SPIoutputCS(1); (*ptrRegData) = (misoData32 & 0x00FFFF); - + //---------------------------------------- // success return 1; @@ -384,9 +554,9 @@ // @return 1 on success; 0 on failure uint8_t MAX11410::Write_24bit(MAX11410_CMD_enum_t regAddress, uint32_t regData) { - - //---------------------------------------- - // warning -- WIP work in progress + + //---------------------------------------- + // warning -- WIP work in progress #warning "Not Implemented Yet: MAX11410::Write_24bit..." //---------------------------------------- @@ -415,9 +585,9 @@ // @return 1 on success; 0 on failure uint8_t MAX11410::Read_24bit(MAX11410_CMD_enum_t regAddress, uint32_t* ptrRegData) { - - //---------------------------------------- - // warning -- WIP work in progress + + //---------------------------------------- + // warning -- WIP work in progress #warning "Not Implemented Yet: MAX11410::Read_24bit..." //---------------------------------------- @@ -427,7 +597,7 @@ int32_t misoData32 = SPIreadWrite32bits(mosiData32); SPIoutputCS(1); (*ptrRegData) = (misoData32 & 0x00FFFFFF); - + //---------------------------------------- // success return 1; @@ -455,9 +625,9 @@ // @return 1 on success; 0 on failure uint8_t MAX11410::Configure_Voltage(MAX11410_AINP_SEL_enum_t channel_hi, MAX11410_AINN_SEL_enum_t channel_lo) { - - //---------------------------------------- - // warning -- WIP work in progress + + //---------------------------------------- + // warning -- WIP work in progress #warning "Not Tested Yet: MAX11410::Configure_Voltage..." //---------------------------------------- @@ -495,10 +665,10 @@ //---------------------------------------- // read24 0x80|0x30 DATA0 (%SW 0xB0 0 0 0) Read_24bit(CMD_r011_0000_dddd_dddd_dddd_dddd_dddd_dddd_DATA0, &data0); - - //---------------------------------------- - // success - return 1; + + //---------------------------------------- + // success + return 1; } //---------------------------------------- @@ -513,20 +683,20 @@ // @return 1 on success; 0 on failure uint8_t MAX11410::Measure_Voltage(MAX11410_AINP_SEL_enum_t channel_hi, MAX11410_AINN_SEL_enum_t channel_lo) { - - //---------------------------------------- - // warning -- WIP work in progress + + //---------------------------------------- + // warning -- WIP work in progress #warning "Not Tested Yet: MAX11410::Measure_Voltage..." //---------------------------------------- - // read24 0x80|0x38 STATUS (%SW 0xB8 0 0 0) - Read_24bit(CMD_r011_1000_dddd_dddd_dddd_dddd_dxxx_dddd_STATUS, &status); - - //---------------------------------------- - // read24 0x80|0x30 DATA0 (%SW 0xB0 0 0 0) - Read_24bit(CMD_r011_0000_dddd_dddd_dddd_dddd_dddd_dddd_DATA0, &data0); - - //---------------------------------------- + // read24 0x80|0x38 STATUS (%SW 0xB8 0 0 0) + Read_24bit(CMD_r011_1000_dddd_dddd_dddd_dddd_dxxx_dddd_STATUS, &status); + + //---------------------------------------- + // read24 0x80|0x30 DATA0 (%SW 0xB0 0 0 0) + Read_24bit(CMD_r011_0000_dddd_dddd_dddd_dddd_dddd_dddd_DATA0, &data0); + + //---------------------------------------- // success return 1; } @@ -543,20 +713,20 @@ // @return 1 on success; 0 on failure uint8_t MAX11410::Configure_RTD(MAX11410_AINP_SEL_enum_t channel_RTD_Force, MAX11410_AINP_SEL_enum_t channel_RTD_Hi, MAX11410_AINN_SEL_enum_t channel_RTD_Lo) { - - //---------------------------------------- - // warning -- WIP work in progress + + //---------------------------------------- + // warning -- WIP work in progress #warning "Not Implemented Yet: MAX11410::Configure_RTD..." //---------------------------------------- - // read24 0x80|0x38 STATUS (%SW 0xB8 0 0 0) - Read_24bit(CMD_r011_1000_dddd_dddd_dddd_dddd_dxxx_dddd_STATUS, &status); - - //---------------------------------------- - // read24 0x80|0x30 DATA0 (%SW 0xB0 0 0 0) - Read_24bit(CMD_r011_0000_dddd_dddd_dddd_dddd_dddd_dddd_DATA0, &data0); - - //---------------------------------------- + // read24 0x80|0x38 STATUS (%SW 0xB8 0 0 0) + Read_24bit(CMD_r011_1000_dddd_dddd_dddd_dddd_dxxx_dddd_STATUS, &status); + + //---------------------------------------- + // read24 0x80|0x30 DATA0 (%SW 0xB0 0 0 0) + Read_24bit(CMD_r011_0000_dddd_dddd_dddd_dddd_dddd_dddd_DATA0, &data0); + + //---------------------------------------- // success return 1; } @@ -574,20 +744,20 @@ // @return 1 on success; 0 on failure uint8_t MAX11410::Measure_RTD(MAX11410_AINP_SEL_enum_t channel_RTD_Force, MAX11410_AINP_SEL_enum_t channel_RTD_Hi, MAX11410_AINN_SEL_enum_t channel_RTD_Lo) { - - //---------------------------------------- - // warning -- WIP work in progress + + //---------------------------------------- + // warning -- WIP work in progress #warning "Not Implemented Yet: MAX11410::Measure_RTD..." //---------------------------------------- - // read24 0x80|0x38 STATUS (%SW 0xB8 0 0 0) - Read_24bit(CMD_r011_1000_dddd_dddd_dddd_dddd_dxxx_dddd_STATUS, &status); - - //---------------------------------------- - // read24 0x80|0x30 DATA0 (%SW 0xB0 0 0 0) - Read_24bit(CMD_r011_0000_dddd_dddd_dddd_dddd_dddd_dddd_DATA0, &data0); - - //---------------------------------------- + // read24 0x80|0x38 STATUS (%SW 0xB8 0 0 0) + Read_24bit(CMD_r011_1000_dddd_dddd_dddd_dddd_dxxx_dddd_STATUS, &status); + + //---------------------------------------- + // read24 0x80|0x30 DATA0 (%SW 0xB0 0 0 0) + Read_24bit(CMD_r011_0000_dddd_dddd_dddd_dddd_dddd_dddd_DATA0, &data0); + + //---------------------------------------- // success return 1; } @@ -605,20 +775,20 @@ // @return 1 on success; 0 on failure uint8_t MAX11410::Configure_Thermocouple(MAX11410_AINP_SEL_enum_t channel_TC_Hi, MAX11410_AINN_SEL_enum_t channel_TC_Lo, MAX11410_AINP_SEL_enum_t channel_RTD_Hi, MAX11410_AINP_SEL_enum_t channel_RTD_Lo) { - - //---------------------------------------- - // warning -- WIP work in progress + + //---------------------------------------- + // warning -- WIP work in progress #warning "Not Implemented Yet: MAX11410::Configure_Thermocouple..." //---------------------------------------- - // read24 0x80|0x38 STATUS (%SW 0xB8 0 0 0) - Read_24bit(CMD_r011_1000_dddd_dddd_dddd_dddd_dxxx_dddd_STATUS, &status); - - //---------------------------------------- - // read24 0x80|0x30 DATA0 (%SW 0xB0 0 0 0) - Read_24bit(CMD_r011_0000_dddd_dddd_dddd_dddd_dddd_dddd_DATA0, &data0); - - //---------------------------------------- + // read24 0x80|0x38 STATUS (%SW 0xB8 0 0 0) + Read_24bit(CMD_r011_1000_dddd_dddd_dddd_dddd_dxxx_dddd_STATUS, &status); + + //---------------------------------------- + // read24 0x80|0x30 DATA0 (%SW 0xB0 0 0 0) + Read_24bit(CMD_r011_0000_dddd_dddd_dddd_dddd_dddd_dddd_DATA0, &data0); + + //---------------------------------------- // success return 1; } @@ -637,20 +807,20 @@ // @return 1 on success; 0 on failure uint8_t MAX11410::Measure_Thermocouple(MAX11410_AINP_SEL_enum_t channel_TC_Hi, MAX11410_AINN_SEL_enum_t channel_TC_Lo, MAX11410_AINP_SEL_enum_t channel_RTD_Hi, MAX11410_AINP_SEL_enum_t channel_RTD_Lo) { - - //---------------------------------------- - // warning -- WIP work in progress + + //---------------------------------------- + // warning -- WIP work in progress #warning "Not Implemented Yet: MAX11410::Measure_Thermocouple..." //---------------------------------------- - // read24 0x80|0x38 STATUS (%SW 0xB8 0 0 0) - Read_24bit(CMD_r011_1000_dddd_dddd_dddd_dddd_dxxx_dddd_STATUS, &status); - - //---------------------------------------- - // read24 0x80|0x30 DATA0 (%SW 0xB0 0 0 0) - Read_24bit(CMD_r011_0000_dddd_dddd_dddd_dddd_dddd_dddd_DATA0, &data0); - - //---------------------------------------- + // read24 0x80|0x38 STATUS (%SW 0xB8 0 0 0) + Read_24bit(CMD_r011_1000_dddd_dddd_dddd_dddd_dxxx_dddd_STATUS, &status); + + //---------------------------------------- + // read24 0x80|0x30 DATA0 (%SW 0xB0 0 0 0) + Read_24bit(CMD_r011_0000_dddd_dddd_dddd_dddd_dddd_dddd_DATA0, &data0); + + //---------------------------------------- // success return 1; }
--- a/MAX11410.h Thu Jul 25 03:56:51 2019 -0700 +++ b/MAX11410.h Thu Jul 25 16:22:53 2019 -0700 @@ -1033,12 +1033,12 @@ /// reference voltage, in Volts double VRef; - /// shadow of register CMD_r011_1000_dddd_dddd_dddd_dddd_dxxx_dddd_STATUS - uint32_t status; - - /// shadow of register CMD_r011_0000_dddd_dddd_dddd_dddd_dddd_dddd_DATA0 - uint32_t data0; - + /// shadow of register CMD_r011_1000_dddd_dddd_dddd_dddd_dxxx_dddd_STATUS + uint32_t status; + + /// shadow of register CMD_r011_0000_dddd_dddd_dddd_dddd_dddd_dddd_DATA0 + uint32_t data0; + // CODE GENERATOR: omit global g_MAX11410_device // CODE GENERATOR: extern function declarations @@ -1056,6 +1056,22 @@ // void SPIwrite16bits(int16_t mosiData16); +// CODE GENERATOR: extern function declaration SPIreadWrite16bits +//---------------------------------------- +// SPI read and write 16 bits +// SPI interface to MAX11410 shift 16 bits mosiData16 into MAX11410 DIN +// while simultaneously capturing 16 bits miso data from MAX11410 DOUT +// + int16_t SPIreadWrite16bits(int16_t mosiData16); + +// CODE GENERATOR: extern function declaration SPIreadWrite32bits +//---------------------------------------- +// SPI read and write 32 bits +// SPI interface to MAX11410 shift 32 bits mosiData into MAX11410 DIN +// while simultaneously capturing 32 bits miso data from MAX11410 DOUT +// + int32_t SPIreadWrite32bits(int32_t mosiData32); + // CODE GENERATOR: class member data private: // CODE GENERATOR: class member data for SPI interface
--- a/main.cpp Thu Jul 25 03:56:51 2019 -0700 +++ b/main.cpp Thu Jul 25 16:22:53 2019 -0700 @@ -2974,7 +2974,8 @@ g_MAX5171_device.CODE(code); #elif APPLICATION_MAX11410 // onButton2FallingEdge BUTTON2 demo configuration MAX11410BOB // TODO: demo - g_MAX11410_device.CODEnLOADn(ch, code); + #warning "MAX11410 onButton2FallingEdge demo not defined" + //g_MAX11410_device.CODEnLOADn(ch, code); #elif APPLICATION_MAX12345 // onButton2FallingEdge BUTTON2 demo configuration MAX12345BOB // TODO: demo g_MAX12345_device.CODEnLOADn(ch, code);