From df6a4c2b5711ba7cda3cadd91d4b625c7a06da9d Mon Sep 17 00:00:00 2001 From: Joshua Drake Date: Thu, 2 May 2024 20:10:00 -0500 Subject: Potentially fixed issues with reading SPI bus, and cleaned up code. --- SPI.c | 40 +++++++++-------- SPI.h | 5 +-- build/default/debug/SPI.o | Bin 15520 -> 15548 bytes build/default/debug/main.o | Bin 9436 -> 8156 bytes .../default/debug/mcc_generated_files/mssp2_i2c.o | Bin 19200 -> 19196 bytes build/default/production/SPI.o | Bin 15596 -> 15592 bytes build/default/production/main.o | Bin 8384 -> 8560 bytes dist/default/production/memoryfile.xml | 8 ++-- main.c | 49 +++------------------ nbproject/Makefile-genesis.properties | 6 +-- nbproject/configurations.xml | 14 +++--- .../private/SuppressibleMessageMemo.properties | 3 +- 12 files changed, 45 insertions(+), 80 deletions(-) diff --git a/SPI.c b/SPI.c index 1a1b8b6..a6590b4 100644 --- a/SPI.c +++ b/SPI.c @@ -31,7 +31,7 @@ if (Ohm_150 > 15) Ohm_150 = 15; if (Ohm_68 > 5) Ohm_68 = 5; //WriteBuffer[0] = WriteBuffer[2] = WriteBuffer[4] = (write << 8) | (!write << 7) | 0b000000; - WriteBuffer[0] = WriteBuffer[2] = WriteBuffer[4] = 0b10000000; + WriteBuffer[0] = WriteBuffer[2] = WriteBuffer[4] = 0x80; //WriteBuffer[1] = 0xFF >> (15-Ohm_150); //WriteBuffer[3] = 0xFE << (7-(Ohm_150-8)) | (Ohm_68 - 4); //2WriteBuffer[1] = 0x0F << (4-(Ohm_68 - 1)) | (testLED << 7); @@ -41,23 +41,28 @@ WriteBuffer[5] = 0xff >> (15-Ohm_150); //WriteBuffer[1] = 0xFF; //if (Ohm_68 == 5) WriteBuffer[3]|= 0b10000000; + SPI_slaveSelect(); readData = MSSP1_SPI_Exchange8bitBuffer(WriteBuffer, 6, ReadBuffer); + SPI_slaveDeselect(); } - int active150() + void active(uint8_t *ohm150, uint8_t *ohm68) { WriteBuffer[0] = WriteBuffer[2] = WriteBuffer[4] = 0x40; WriteBuffer[1] = WriteBuffer[3] = WriteBuffer[5] = 0x02; + SPI_slaveSelect(); readData = MSSP1_SPI_Exchange8bitBuffer(WriteBuffer, 6, ReadBuffer); - return bitcount(ReadBuffer[2]&0x7F) + (bitcount(ReadBuffer[4])); //+ bitcount(ReadBuffer[3] << 1)); - } - int active68() - { - WriteBuffer[0] = WriteBuffer[2] = WriteBuffer[4] = 0x40; - WriteBuffer[1] = WriteBuffer[3] = WriteBuffer[5] = 0x02; + SPI_slaveDeselect(); + WriteBuffer[0] = WriteBuffer[2] = WriteBuffer[4] = 0x00; + WriteBuffer[1] = WriteBuffer[3] = WriteBuffer[5] = 0x00; + SPI_slaveSelect(); readData = MSSP1_SPI_Exchange8bitBuffer(WriteBuffer, 6, ReadBuffer); - return ((ReadBuffer[2] & 0x80) + bitcount(ReadBuffer[0] & 0x0f)); + SPI_slaveDeselect(); + ohm150 = bitcount(ReadBuffer[3]&0x7F) + bitcount(ReadBuffer[5]); //+ bitcount(ReadBuffer[3] << 1)); + //ohm150 = bitcount(ReadBuffer[3]);// + ReadBuffer[5] + ReadBuffer[3] + ReadBuffer[1]; + ohm68 = ((ReadBuffer[3] & 0x80)>>7) + bitcount(ReadBuffer[0] & 0x0f); } + void Message_BIM(uint8_t outputs[3]) { WriteBuffer[0] = WriteBuffer[2] = WriteBuffer[4] = (write << 8) | (!write << 7) | 0b000001; @@ -114,16 +119,13 @@ WriteBuffer[5] = outputs[2]; } - void Message_HWCR(uint8_t outputs[3]) - { - //WriteBuffer[0] = WriteBuffer[2] = WriteBuffer[4] = (write << 8) | (!write << 7) | 0b001100; - //WriteBuffer[1] = outputs[0]; - //WriteBuffer[3] = outputs[1]; - //WriteBuffer[5] = outputs[2]; - - WriteBuffer[0] = 0b10001100; - WriteBuffer[1] = 0b10000000; - readData = MSSP1_SPI_Exchange8bitBuffer(*WriteBuffer, 2, *ReadBuffer); + void Message_HWCR() + { + WriteBuffer[0] = WriteBuffer[2] = WriteBuffer[4] = 0x8C; + WriteBuffer[1] = WriteBuffer[3] = WriteBuffer[5] = 0xC0; + SPI_slaveSelect(); + readData = MSSP1_SPI_Exchange8bitBuffer(WriteBuffer, 6, ReadBuffer); + SPI_slaveDeselect(); } void Message_HWCROCL(uint8_t outputs[3]) diff --git a/SPI.h b/SPI.h index 3988e80..4181835 100644 --- a/SPI.h +++ b/SPI.h @@ -57,8 +57,7 @@ Message_OUT(15, 5, false); //Max Load with testLED turned off. */ - int active150(void); - int active68(void); + void active(uint8_t *ohm150, uint8_t *ohm68); int bitcount(uint8_t); void Message_BIM(uint8_t outputs[3]); /** @@ -275,7 +274,7 @@ bits (DIAG_OLONEN.MUX) (3:0) Message_DAGOLONEN({0b00000000, 0xFF, 0xFF}); //Open Load ON active on channel 0 of the first IC. */ - void Message_HWCR(uint8_t outputs[3]); + void Message_HWCR(void); /** @Summary Hardware Configuration Register Bits diff --git a/build/default/debug/SPI.o b/build/default/debug/SPI.o index 40daf0f..aad8f34 100644 Binary files a/build/default/debug/SPI.o and b/build/default/debug/SPI.o differ diff --git a/build/default/debug/main.o b/build/default/debug/main.o index 46253d4..2e756c0 100644 Binary files a/build/default/debug/main.o and b/build/default/debug/main.o differ diff --git a/build/default/debug/mcc_generated_files/mssp2_i2c.o b/build/default/debug/mcc_generated_files/mssp2_i2c.o index 3837607..4a618a4 100644 Binary files a/build/default/debug/mcc_generated_files/mssp2_i2c.o and b/build/default/debug/mcc_generated_files/mssp2_i2c.o differ diff --git a/build/default/production/SPI.o b/build/default/production/SPI.o index 528ca5c..a1791f2 100644 Binary files a/build/default/production/SPI.o and b/build/default/production/SPI.o differ diff --git a/build/default/production/main.o b/build/default/production/main.o index 8414092..189c9dc 100644 Binary files a/build/default/production/main.o and b/build/default/production/main.o differ diff --git a/dist/default/production/memoryfile.xml b/dist/default/production/memoryfile.xml index 6dda4a3..d64cd8d 100644 --- a/dist/default/production/memoryfile.xml +++ b/dist/default/production/memoryfile.xml @@ -5,14 +5,14 @@ bytes 2048 - 96 - 1952 + 100 + 1948 bytes 16128 - 4161 - 11967 + 4188 + 11940 diff --git a/main.c b/main.c index e99c874..77d9b11 100644 --- a/main.c +++ b/main.c @@ -53,7 +53,6 @@ /* Main application */ -uint8_t nullarray = {0x00, 0x00, 0x00}; uint8_t desired150, desired68, current150, current68 = 0; bool relay_delay = false; @@ -68,9 +67,7 @@ int main(void) _LATA0 = _LATA1 = 0;//_LATA4 = 1; //Activate gate driver chips _LATA4 = 1; - SPI_slaveSelect(); - Message_HWCR(nullarray); - SPI_slaveDeselect(); + Message_HWCR(); _LATB6 = 0; _LATB7 = 1; @@ -78,9 +75,6 @@ int main(void) TMR1_SetInterruptHandler(&TMR1_Process); - //MSSP2_I2C_ReadPointerSet(0b00000011); - // MSSP2_I2C_WritePointerSet(0x00); - while (1) { desired150 = getI2CArray(1) & 0x0F; @@ -89,68 +83,35 @@ int main(void) //if((relay_delay)&&(getTimeoutCounter() < 2)) //{ //relay_delay = false; - SPI_slaveSelect(); - current150 = current150(); - SPI_slaveDeselect(); - /* - SPI_slaveSelect(); - current68 = active68(); - SPI_slaveDeselect(); - + active(¤t150,¤t68); + /* if(desired150 < current150) { - SPI_slaveSelect(); Message_OUT(current150-1, current68, 1); - SPI_slaveDeselect(); } else if(desired150 > current150) { - SPI_slaveSelect(); Message_OUT(current150+1, current68, 1); - SPI_slaveDeselect(); } else if(desired68 < current68) { - SPI_slaveSelect(); Message_OUT(current150, current68-1, 1); - SPI_slaveDeselect(); } else if(desired68 > current68) { - SPI_slaveSelect(); Message_OUT(current150, current68+1, 1); - SPI_slaveDeselect(); } } if(getTimeoutCounter() > 2){ //Open contactors if I2C communication is broken. - SPI_slaveSelect(); Message_OUT(0, 0, 0); - SPI_slaveDeselect(); _LATB8 = 0; _LATB7 = 1; }*/ + Message_OUT(2, 0, relay_delay); - SPI_slaveSelect(); - Message_OUT(desired150, 0, relay_delay); - SPI_slaveDeselect(); - /* - SPI_slaveSelect(); - Message_OUT(15, 5, 0); - SPI_slaveDeselect(); - - SPI_slaveSelect(); - Message_OUT(15, 5, 0); - SPI_slaveDeselect(); - * - * -*/ - //SPI_slaveSelect(); - //Message_OUT(15, i2cArray[1] >> 4, 0); - //SPI_slaveDeselect(); - //if(MSSP2_I2C_WritePointerGet() > 50) {_LATB7 = 0; _LATB6 = 1;} - //else {_LATB6 = 0; _LATB7 = 1;} + if(current150>0){_LATB8=0; _LATB7=0;} } return 1; diff --git a/nbproject/Makefile-genesis.properties b/nbproject/Makefile-genesis.properties index e7e8590..58a5b7d 100644 --- a/nbproject/Makefile-genesis.properties +++ b/nbproject/Makefile-genesis.properties @@ -1,11 +1,11 @@ # -#Fri Apr 26 12:52:12 CDT 2024 +#Thu May 02 18:31:10 CDT 2024 default.languagetoolchain.version=2.10 default.Pack.dfplocation=/opt/microchip/mplabx/v6.15/packs/Microchip/PIC24F-KA-KL-KM_DFP/1.4.83 conf.ids=default default.languagetoolchain.dir=/opt/microchip/xc16/v2.10/bin -host.id=0 -configurations-xml=67675cd84f9b3787f20789de6c2794fb +host.id=17y8-g9hi-6g +configurations-xml=548bce5bcce17c7b8a52ea2b767e1662 com-microchip-mplab-nbide-embedded-makeproject-MakeProject.md5=e62346c0c0ecee2637e613b49cb7b7fa proj.dir=/home/josh/MPLABXProjects/resbox default.com-microchip-mplab-mdbcore-pk4hybrid-Pk4HybridTooImpl.md5=38058ec39ea8224adcc766836376f0d6 diff --git a/nbproject/configurations.xml b/nbproject/configurations.xml index e4b4ca8..8b11231 100644 --- a/nbproject/configurations.xml +++ b/nbproject/configurations.xml @@ -731,7 +731,8 @@ - + @@ -776,7 +777,7 @@ - + @@ -785,7 +786,7 @@ - + @@ -1280,7 +1281,8 @@ - + @@ -1305,7 +1307,7 @@ - + @@ -1314,7 +1316,7 @@ - + diff --git a/nbproject/private/SuppressibleMessageMemo.properties b/nbproject/private/SuppressibleMessageMemo.properties index 3704710..7d0da5c 100644 --- a/nbproject/private/SuppressibleMessageMemo.properties +++ b/nbproject/private/SuppressibleMessageMemo.properties @@ -1,3 +1,4 @@ # -#Wed Jan 31 16:17:43 CST 2024 +#Thu May 02 16:14:15 CDT 2024 PICkit\ 4/CHECK_4_HIGH_VOLTAGE_VPP=true +PICkit\ 4/DEVID_MISMATCH=true -- cgit v1.2.3