From 3ee1a69c65589a744b67f770001022a884fe32ba Mon Sep 17 00:00:00 2001 From: Joshua Drake Date: Sat, 4 May 2024 11:11:46 -0500 Subject: Code is fully functional with delay timer at uC level. --- mcc_generated_files/mssp2_i2c.c | 15 ++++++++++----- mcc_generated_files/mssp2_i2c.h | 3 ++- 2 files changed, 12 insertions(+), 6 deletions(-) (limited to 'mcc_generated_files') diff --git a/mcc_generated_files/mssp2_i2c.c b/mcc_generated_files/mssp2_i2c.c index dabd9a9..580366b 100644 --- a/mcc_generated_files/mssp2_i2c.c +++ b/mcc_generated_files/mssp2_i2c.c @@ -128,7 +128,7 @@ uint8_t yeah; #define ARRAY_CNT 6 // Number of bytes in array uint8_t slaveAddress = 0x30; // 7-bit slave address uint8_t index = 0; // Array pointer -uint8_t I2C_timeout = 10; //Number of timer iterations since clear +static uint8_t I2C_timeout = 0; //Number of timer iterations since clear uint8_t temp = 0; // Temp register uint8_t regAdd = 1; // First data byte was reg add uint8_t i2cArray[ARRAY_CNT] = @@ -188,10 +188,10 @@ void __attribute__((interrupt, no_auto_psv)) _MSSP2Interrupt(void) { } if (SSP2STATbits.R_NOT_W == 0) // Master write (slave receive) { - + resetTimeoutCounter(); //Reset our counter when a message is received. if (SSP2STATbits.D_NOT_A == 0) // Last byte was an address { - I2C_timeout = 0; //Reset our counter when a message is received. + //resetTimeoutCounter(); //Reset our counter when a message is received. _LATB7 = !_LATB7; regAdd = 1; // Next byte register address temp = SSP2BUF; // Clear BF @@ -199,6 +199,7 @@ void __attribute__((interrupt, no_auto_psv)) _MSSP2Interrupt(void) { } if (SSP2STATbits.D_NOT_A == 1) // Last byte was data { + //resetTimeoutCounter(); //Reset our counter when a message is received. if (regAdd == 1) // Last byte was register add { index = SSP2BUF; // Load register address @@ -225,15 +226,19 @@ void __attribute__((interrupt, no_auto_psv)) _MSSP2Interrupt(void) { _LATB8 = !SSP2CON1bits.SSPOV; } -uint8_t getTimeoutCounter() +uint8_t* getTimeoutCounter() { - return I2C_timeout; + return &I2C_timeout; } void incrementTimeoutCounter() { I2C_timeout++; } +void resetTimeoutCounter() +{ + I2C_timeout = 0x00; +} uint8_t getI2CArray(int index) { if(index < 5)return i2cArray[index]; diff --git a/mcc_generated_files/mssp2_i2c.h b/mcc_generated_files/mssp2_i2c.h index f76d48c..329983a 100644 --- a/mcc_generated_files/mssp2_i2c.h +++ b/mcc_generated_files/mssp2_i2c.h @@ -149,7 +149,8 @@ typedef enum */ -uint8_t getTimeoutCounter(void); +uint8_t* getTimeoutCounter(void); +void resetTimeoutCounter(void); void incrementTimeoutCounter(void); void MSSP2_I2C_Initialize(void); -- cgit v1.2.3