Test program running on MAX32625MBED. Control through USB Serial commands using a terminal emulator such as teraterm or putty.

Dependencies:   MaximTinyTester CmdLine MAX541 USBDevice

Revision:
62:8223a7253c90
Parent:
61:b4f3051578ef
Child:
63:8f39d21d6157
--- a/MAX11043/MAX11043.cpp	Tue Feb 18 00:49:19 2020 +0000
+++ b/MAX11043/MAX11043.cpp	Tue Feb 18 06:30:34 2020 +0000
@@ -203,7 +203,7 @@
 // Assert SPI Chip Select
 // SPI chip-select for MAX11043
 //
-void MAX11043::SPIoutputCS(int isLogicHigh)
+inline void MAX11043::SPIoutputCS(int isLogicHigh)
 {
     // CODE GENERATOR: extern function definition for function SPIoutputCS
     // CODE GENERATOR: extern function definition for standard SPI interface function SPIoutputCS(int isLogicHigh)
@@ -478,6 +478,40 @@
     return misoData32;
 }
 
+// CODE GENERATOR: extern function requirement MAX11043::SPIreadWriteWithLowCS
+// SPI read and write arbitrary number of 8-bit bytes
+// SPI interface to MAX11043 shift mosiData into MAX11043 DIN
+// while simultaneously capturing miso data from MAX11043 DOUT
+//
+int MAX11043::SPIreadWriteWithLowCS(size_t byteCount, uint8_t mosiData[], uint8_t misoData[])
+{
+    // CODE GENERATOR: extern function definition for function SPIreadWriteWithLowCS
+    // 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];
+    //
+    // Arduino: begin critical section: noInterrupts() masks all interrupt sources; end critical section with interrupts()
+    //~ noInterrupts();
+    //
+    //~ digitalWrite(Scope_Trigger_Pin, LOW); // diagnostic Scope_Trigger_Pin
+    //
+    m_cs_pin = 0;
+    unsigned int numBytesTransferred = m_spi.write((char*)mosiData, byteCount, (char*)misoData, byteCount);
+    m_cs_pin = m_SPI_cs_state;
+    //
+    //~ digitalWrite(Scope_Trigger_Pin, HIGH); // diagnostic Scope_Trigger_Pin
+    //
+    // Arduino: begin critical section: noInterrupts() masks all interrupt sources; end critical section with interrupts()
+    //~ interrupts();
+    // Optional Diagnostic function to print SPI transactions
+    if (onSPIprint)
+    {
+        onSPIprint(byteCount, (uint8_t*)mosiData, (uint8_t*)misoData);
+    }
+    return numBytesTransferred;
+}
+
 // TODO1: CODE GENERATOR: extern function GPIOoutputSHDN alias SHDNoutputValue
 // CODE GENERATOR: extern function requirement MAX11043::SHDNoutputValue
 // Assert MAX11043 SHDN pin : High = Shut Down, Low = Normal Operation.
@@ -778,6 +812,7 @@
         case 8:  // 8-bit register size
             {
                 // SPI 8+8 = 16-bit transfer
+                //            1234 5678 ___[1]_16
                 // SPI MOSI = 1aaa_aaaa_0000_0000
                 // SPI MISO = xxxx_xxxx_dddd_dddd
                 int16_t mosiData16 = ((CMDOP_0aaa_aa10_ReadRegister | (int16_t)commandByte) << 8) | ((int16_t)0);
@@ -795,6 +830,7 @@
             #warning "Not Verified Yet: MAX11043::RegRead 16-bit SPIreadWrite32bits"
             {
                 // SPI 8+16 = 24-bit transfer
+                //            1234 5678 ___[1]_16 ___[2]_24
                 // SPI MOSI = 1aaa_aaaa_0000_0000_0000_0000 ... _0000
                 // SPI MISO = xxxx_xxxx_dddd_dddd_dddd_dddd ... _xxxx
                 int32_t mosiData32 = ((CMDOP_0aaa_aa10_ReadRegister | (int32_t)commandByte) << 24);
@@ -827,6 +863,7 @@
         case 24:  // 24-bit register size
             {
                 // SPI 8+24 = 32-bit transfer
+                //            1234 5678 ___[1]_16 ___[2]_24 ___[3]_32
                 // SPI MOSI = 1aaa_aaaa_0000_0000_0000_0000_0000_0000
                 // SPI MISO = xxxx_xxxx_dddd_dddd_dddd_dddd_dddd_dddd
                 int32_t mosiData32 = ((CMDOP_0aaa_aa10_ReadRegister | (int32_t)commandByte) << 24);
@@ -865,22 +902,32 @@
             //
             {
                 // SPI 8+32 = 40-bit transfer
-                //            1234 5678        16        24        32        40
+                //            1234 5678 ___[1]_16 ___[2]_24 ___[3]_32 ___[4]_40
                 // SPI MOSI = 1aaa_aaaa_0000_0000_0000_0000_0000_0000_0000_0000 ... _0000
                 // SPI MISO = xxxx_xxxx_dddd_dddd_dddd_dddd_dddd_dddd_dddd_dddd ... _xxxx
                 int32_t mosiData32 = ((CMDOP_0aaa_aa10_ReadRegister | (int32_t)commandByte) << 24);
-                SPIoutputCS(0);
-                int32_t misoData32 = SPIreadWrite32bits(mosiData32); // TODO
-                SPIoutputCS(1);
-                if (ptrRegData) { (*ptrRegData) = (misoData32 & 0x00FFFFFF); } // TODO
+                size_t byteCount = 1 + (2 * 2);
+                uint8_t mosiData[5];
+                uint8_t misoData[5];
+                mosiData[0] = CMDOP_0aaa_aa10_ReadRegister | commandByte;
+                mosiData[1] = 0; // CMDOP_1111_1111_NoOperationMOSIidleHigh;
+                mosiData[2] = 0; // CMDOP_1111_1111_NoOperationMOSIidleHigh;
+                mosiData[3] = 0; // CMDOP_1111_1111_NoOperationMOSIidleHigh;
+                mosiData[4] = 0; // CMDOP_1111_1111_NoOperationMOSIidleHigh;
+                // SPIreadWriteWithLowCS(size_t byteCount, uint8_t mosiData[], uint8_t misoData[]);
+                SPIreadWriteWithLowCS(byteCount, mosiData, misoData);
+                if (ptrRegData) { (*ptrRegData) = (misoData[1] << 8) | misoData[2]; }
                 if (commandByte == CMD_0001_0010_d24_d24_Rd04_ADCab) {
                     // TODO1: update adca
-                    adca = ((misoData32 >> 8) & 0x00FFFF);
+                    adca = (misoData[1] << 8) | misoData[2];
                     // TODO1: update adcb
+                    adcb = (misoData[3] << 8) | misoData[4];
                 }
                 if (commandByte == CMD_0001_0110_d24_d24_Rd05_ADCcd) {
                     // TODO1: update adcc
+                    adcc = (misoData[1] << 8) | misoData[2];
                     // TODO1: update adcd
+                    adcd = (misoData[3] << 8) | misoData[4];
                 }
             }
             break;
@@ -897,21 +944,33 @@
             //
             {
                 // SPI 8+48 = 56-bit transfer
-                //            1234 5678        16        24        32        40        48        56
+                //            1234 5678 ___[1]_16 ___[2]_24 ___[3]_32 ___[4]_40 ___[5]_48 ___[6]_56
                 // SPI MOSI = 1aaa_aaaa_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000 ... _0000
                 // SPI MISO = xxxx_xxxx_dddd_dddd_dddd_dddd_dddd_dddd_dddd_dddd_dddd_dddd_dddd_dddd ... _xxxx
-                int32_t mosiData32 = ((CMDOP_0aaa_aa10_ReadRegister | (int32_t)commandByte) << 24);
-                SPIoutputCS(0);
-                int32_t misoData32 = SPIreadWrite32bits(mosiData32); // TODO
-                SPIoutputCS(1);
-                if (ptrRegData) { (*ptrRegData) = (misoData32 & 0x00FFFFFF); } // TODO
+                size_t byteCount = 1 + (3 * 2);
+                uint8_t mosiData[7];
+                uint8_t misoData[7];
+                mosiData[0] = CMDOP_0aaa_aa10_ReadRegister | commandByte;
+                mosiData[1] = 0; // CMDOP_1111_1111_NoOperationMOSIidleHigh;
+                mosiData[2] = 0; // CMDOP_1111_1111_NoOperationMOSIidleHigh;
+                mosiData[3] = 0; // CMDOP_1111_1111_NoOperationMOSIidleHigh;
+                mosiData[4] = 0; // CMDOP_1111_1111_NoOperationMOSIidleHigh;
+                mosiData[5] = 0; // CMDOP_1111_1111_NoOperationMOSIidleHigh;
+                mosiData[6] = 0; // CMDOP_1111_1111_NoOperationMOSIidleHigh;
+                // SPIreadWriteWithLowCS(size_t byteCount, uint8_t mosiData[], uint8_t misoData[]);
+                SPIreadWriteWithLowCS(byteCount, mosiData, misoData);
+                if (ptrRegData) { (*ptrRegData) = (misoData[1] << 16) | (misoData[2] << 8) | misoData[3]; }
                 if (commandByte == CMD_0001_0010_d24_d24_Rd04_ADCab) {
                     // TODO1: update adca
+                    adca = (misoData[1] << 16) | (misoData[2] << 8) | misoData[3];
                     // TODO1: update adcb
+                    adcb = (misoData[4] << 16) | (misoData[5] << 8) | misoData[6];
                 }
                 if (commandByte == CMD_0001_0110_d24_d24_Rd05_ADCcd) {
                     // TODO1: update adcc
+                    adcc = (misoData[1] << 16) | (misoData[2] << 8) | misoData[3];
                     // TODO1: update adcd
+                    adcd = (misoData[4] << 16) | (misoData[5] << 8) | misoData[6];
                 }
             }
             break;
@@ -924,19 +983,33 @@
             //
             {
                 // SPI 8+64 = 72-bit transfer
-                //            1234 5678        16        24        32        40        48        56        64        72
+                //            1234 5678 ___[1]_16 ___[2]_24 ___[3]_32 ___[4]_40 ___[5]_48 ___[6]_56 ___[7]_64 ___[8]_72
                 // SPI MOSI = 1aaa_aaaa_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000 ... _0000
                 // SPI MISO = xxxx_xxxx_dddd_dddd_dddd_dddd_dddd_dddd_dddd_dddd_dddd_dddd_dddd_dddd_dddd_dddd_dddd_dddd ... _xxxx
-                int32_t mosiData32 = ((CMDOP_0aaa_aa10_ReadRegister | (int32_t)commandByte) << 24);
-                SPIoutputCS(0);
-                int32_t misoData32 = SPIreadWrite32bits(mosiData32); // TODO
-                SPIoutputCS(1);
-                if (ptrRegData) { (*ptrRegData) = (misoData32 & 0x00FFFFFF); } // TODO
+                size_t byteCount = 1 + (2 * 4);
+                uint8_t mosiData[9];
+                uint8_t misoData[9];
+                mosiData[0] = CMDOP_0aaa_aa10_ReadRegister | commandByte;
+                mosiData[1] = 0; // CMDOP_1111_1111_NoOperationMOSIidleHigh;
+                mosiData[2] = 0; // CMDOP_1111_1111_NoOperationMOSIidleHigh;
+                mosiData[3] = 0; // CMDOP_1111_1111_NoOperationMOSIidleHigh;
+                mosiData[4] = 0; // CMDOP_1111_1111_NoOperationMOSIidleHigh;
+                mosiData[5] = 0; // CMDOP_1111_1111_NoOperationMOSIidleHigh;
+                mosiData[6] = 0; // CMDOP_1111_1111_NoOperationMOSIidleHigh;
+                mosiData[7] = 0; // CMDOP_1111_1111_NoOperationMOSIidleHigh;
+                mosiData[8] = 0; // CMDOP_1111_1111_NoOperationMOSIidleHigh;
+                // SPIreadWriteWithLowCS(size_t byteCount, uint8_t mosiData[], uint8_t misoData[]);
+                SPIreadWriteWithLowCS(byteCount, mosiData, misoData);
+                if (ptrRegData) { (*ptrRegData) = (misoData[1] << 8) | misoData[2]; }
                 if (commandByte == CMD_0001_1010_d24_d24_d24_d24_Rd06_ADCabcd) {
                     // TODO1: update adca
+                    adca = (misoData[1] << 8) | misoData[2];
                     // TODO1: update adcb
+                    adcb = (misoData[3] << 8) | misoData[4];
                     // TODO1: update adcc
+                    adcc = (misoData[5] << 8) | misoData[6];
                     // TODO1: update adcd
+                    adcd = (misoData[7] << 8) | misoData[8];
                 }
             }
             break;
@@ -949,19 +1022,37 @@
             //
             {
                 // SPI 8+96 = 104-bit transfer
-                //            1234 5678        16        24        32        40        48        56        64        72        80        88        96       104
+                //            1234 5678 ___[1]_16 ___[2]_24 ___[3]_32 ___[4]_40 ___[5]_48 ___[6]_56 ___[7]_64 ___[8]_72 ___[9]_80 __[10]_88 __[11]_96 __[12]104
                 // SPI MOSI = 1aaa_aaaa_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000 ... _0000
                 // SPI MISO = xxxx_xxxx_dddd_dddd_dddd_dddd_dddd_dddd_dddd_dddd_dddd_dddd_dddd_dddd_dddd_dddd_dddd_dddd_dddd_dddd_dddd_dddd_dddd_dddd_dddd_dddd ... _xxxx
-                int32_t mosiData32 = ((CMDOP_0aaa_aa10_ReadRegister | (int32_t)commandByte) << 24);
-                SPIoutputCS(0);
-                int32_t misoData32 = SPIreadWrite32bits(mosiData32); // TODO
-                SPIoutputCS(1);
-                if (ptrRegData) { (*ptrRegData) = (misoData32 & 0x00FFFFFF); } // TODO
+                size_t byteCount = 1 + (3 * 4);
+                uint8_t mosiData[13];
+                uint8_t misoData[13];
+                mosiData[0] = CMDOP_0aaa_aa10_ReadRegister | commandByte;
+                mosiData[1] = 0; // CMDOP_1111_1111_NoOperationMOSIidleHigh;
+                mosiData[2] = 0; // CMDOP_1111_1111_NoOperationMOSIidleHigh;
+                mosiData[3] = 0; // CMDOP_1111_1111_NoOperationMOSIidleHigh;
+                mosiData[4] = 0; // CMDOP_1111_1111_NoOperationMOSIidleHigh;
+                mosiData[5] = 0; // CMDOP_1111_1111_NoOperationMOSIidleHigh;
+                mosiData[6] = 0; // CMDOP_1111_1111_NoOperationMOSIidleHigh;
+                mosiData[7] = 0; // CMDOP_1111_1111_NoOperationMOSIidleHigh;
+                mosiData[8] = 0; // CMDOP_1111_1111_NoOperationMOSIidleHigh;
+                mosiData[9] = 0; // CMDOP_1111_1111_NoOperationMOSIidleHigh;
+                mosiData[10] = 0; // CMDOP_1111_1111_NoOperationMOSIidleHigh;
+                mosiData[11] = 0; // CMDOP_1111_1111_NoOperationMOSIidleHigh;
+                mosiData[12] = 0; // CMDOP_1111_1111_NoOperationMOSIidleHigh;
+                // SPIreadWriteWithLowCS(size_t byteCount, uint8_t mosiData[], uint8_t misoData[]);
+                SPIreadWriteWithLowCS(byteCount, mosiData, misoData);
+                if (ptrRegData) { (*ptrRegData) = (misoData[1] << 16) | (misoData[2] << 8) | misoData[3]; }
                 if (commandByte == CMD_0001_1010_d24_d24_d24_d24_Rd06_ADCabcd) {
                     // TODO1: update adca
+                    adca = (misoData[1] << 16) | (misoData[2] << 8) | misoData[3];
                     // TODO1: update adcb
+                    adcb = (misoData[4] << 16) | (misoData[5] << 8) | misoData[6];
                     // TODO1: update adcc
+                    adcc = (misoData[7] << 16) | (misoData[8] << 8) | misoData[9];
                     // TODO1: update adcd
+                    adcd = (misoData[10] << 16) | (misoData[11] << 8) | misoData[12];
                 }
             }
             break;