Interference between i2c bus and serial monitor?

Is it possible or are there known conflicts between the i2c bus and the serial monitor with Arduino?

I’m having trouble setting my DS1307 RTC clock chip consistently. In the course of debugging & trying to track down the problem, I found removing a call to a Read Device routine would prevent the clock from being set. The call should have done nothing, since the Write routine resets the pointer before writing data.

I then changed the routine so that it read and wrote values from the chip, but no Serial.print commands were made until afterwards. This time it worked fine. I tried changing the speed of the serial connection from 9600 to 115200 baud with no effect.

Below is the code I used; the readDevice routine call is at line 139.

#include <Wire.h>
#define	DS1307_ID	0x68	// I2C/TWI device address, coded into the device

// Variables for reading and writing data
uint16_t RTCyyyy; 	// year including the century
byte RTCmm;		// month (1-12)
byte RTCdd;		// date of the month (1-31)
byte RTCh;		// hour of the day (1-12) or (0-23) depending on the mode
byte RTCm;		// minutes past the hour (0-59)
byte RTCs;		// Seconds past the minute (0-59)
byte RTCdow;	// day of the week (1-7). Sequential number; coding depends on the application
byte RTCpm;		// set to non-zero if 12 hour clock and PM indicator
byte bufRTC[20];
int s[10];
int BCD[10];

void setup(){
  Wire.begin();
  Serial.begin(115200);
  delay(1000);
}

void loop(){
//  Serial.print("starting time:  ");
  RTCReadTime();
  int sec1 = RTCs;
  int year1 = RTCyyyy;
//  printTime();  // if this line is active, the write time routine doesn't work
  
//  Serial.print("setting time1:  ");
  time1();
  RTCReadTime();
  int sec2 = RTCs;
  int year2 = RTCyyyy;
//  printTime();
  
  delay(1000);
//  Serial.print("setting time2:  ");
  time2();
  RTCReadTime();
  int sec3 = RTCs;
  int year3 = RTCyyyy;
//  printTime();
  
  Serial.println();
  Serial.print("year at start: ");
  Serial.print(year1);
  Serial.print("  secs at start: ");
  Serial.println(sec1);
  Serial.print("year at t1   : ");
  Serial.print(year2);
  Serial.print("  secs at t1   : ");
  Serial.println(sec2);
  Serial.print("year at t2   : ");
  Serial.print(year3);
  Serial.print("  secs at t2   : ");
  Serial.println(sec3);
  
  delay(10000); 
}

void time1(){
  RTCyyyy = 2001;
  RTCmm = 2;
  RTCdd = 3;
  RTCdow = 4;
  RTCh = 5;
  RTCm = 6;
  RTCs = 7;
  RTCWriteTime();
}
void time2(){
  RTCyyyy = 2010;
  RTCmm = 9;
  RTCdd = 8;
  RTCdow = 7;
  RTCh = 6;
  RTCm = 5;
  RTCs = 4;
  RTCWriteTime();
}

// BCD to binary number packing/unpacking functions
byte BCD2bin(byte v) {  return ((v/16*10) + (v%16));}
byte bin2BCD (byte v) {  return ((v/10*16) + (v%10)); }

// -------------------------------------------------------- 
// Interface functions for the RTC device
void readDevice(byte* buf, byte len){
  Wire.beginTransmission(DS1307_ID);
  Wire.write(0);			// set register address                  
  Wire.endTransmission();
  Wire.requestFrom(DS1307_ID, (int)len);
  while (!Wire.available()) ;	// wait
  for (byte i=0; i<len; i++) {// Read x data from given address upwards...
    buf[i] = Wire.read();       // ... and store it in the buffer
  }  
  return;
}

// -------------------------------------------------------- 
// Read the current time from the RTC and unpack it into the object variables
void RTCReadTime(void){
  readDevice(bufRTC, 7);		// get the data &  unpack it
  RTCs = BCD2bin(bufRTC[0]);// & ~CTL_CH);	// mask off the 'CH' bit
  RTCm = BCD2bin(bufRTC[1]);
  RTCh = BCD2bin(bufRTC[2] & 0x3f);
  RTCpm = 0;
  RTCdow = BCD2bin(bufRTC[3]);
  RTCdd = BCD2bin(bufRTC[4]);
  RTCmm = BCD2bin(bufRTC[5]);
  RTCyyyy = BCD2bin(bufRTC[6]) + 2000;
}

// -------------------------------------------------------- 
void writeDevice(byte* buf, byte len){
  Wire.beginTransmission(DS1307_ID);
  Wire.write(0);				// set register address                  
  for (byte i=0; i<len; i++){ // Send x data from given address upwards...
    Wire.write(buf[i]);         // ... and send it from buffer
  }
  Wire.endTransmission();
  return;
}

// -------------------------------------------------------- 
// Pack up and write the time stored in the object variables to the RTC
// Note: Setting the time will also start the clock of it is halted
void RTCWriteTime(void)
{
  byte	mode12;
  bufRTC[0] = bin2BCD(RTCs);
  bufRTC[1] = bin2BCD(RTCm);
  bufRTC[2] = bin2BCD(RTCh);
  bufRTC[3] = bin2BCD(RTCdow);
  bufRTC[4] = bin2BCD(RTCdd);
  bufRTC[5] = bin2BCD(RTCmm);
  bufRTC[6] = bin2BCD(RTCyyyy - 2000);
//  readDevice(&mode12, 1);       // check what time mode is current
  writeDevice(bufRTC, 7);
}

void newWriteTime(void){
  
}

void printTime(){
  Serial.print(RTCyyyy);
  Serial.print(" - ");
  Serial.print(RTCmm);
  Serial.print("/");
  Serial.print(RTCdd);
  Serial.print(" Day ");
  Serial.print(RTCdow);
  Serial.print("  ");
  Serial.print(RTCh);
  Serial.print(":");
  Serial.print(RTCm);
  Serial.print(":");
  Serial.println(RTCs);
}

So I've played around some more and it doesn't matter if I actually write or read anything from the bus; just calling Wire.endTransmission(); before the write routine will fix it. Wire.requestFrom is supposed to send a stop command after the bytes are received, and I tried putting a WireEndTransmission command at the end of the readDevice routine but that didn't make any difference.

After playing around some more; it appears to be strictly a matter of how long the delay is between Wire.endTransmission() and the Wire.write() command. I re-posted it over in the Networking, protocols and Devices forum as that seemed like it might be a more appropriate forum.

No clue why I have to do that but it appears to be working at least. Just trying to figure out if it's because I'm doing something wrong in the code or if it's a device issue.