Thanks Peter_n for your insight and assistance, I know its overdue, but just recently got everything working together :o
I have shortened the interrupt routines as much as possible as you have advised and did away with the string in the I2C code.
Even if its late, thought I would post where I am at now, that its all working together.
Below is the code as it stands now;
The Interrupt code of the Arduino Slave for the two interrupts and an additional interrupt with the I2C code:
//===========================================================
//========= Direction Pin Chg interrupt routine =========
//===========================================================
ISR (PCINT0_vect) {
dir_pin_stat = digitalRead (dir_pin);
if (dir_pin_stat == dir_XYZ) dir_pin_val = +1; else dir_pin_val = -1;
}
//===========================================================
//========= Pulpresses_cntr interrupt routine ========
//===========================================================
void Pul_void() {
Pul_count_net = Pul_count_net + (long) dir_pin_val;
pul_total = pul_total + (long) dir_pin_val;
pul_odo++;
if (pul_odo > 16000L) { pul_odo=0L; pul_odo_cm++;}
}
//===========================================================
//========= H21A_total interrupt routine ========
//===========================================================
void H21A_void() {
if ( dir_pin_prev != dir_pin_val) {
Pul_counter_error = Pul_counter_error + Pul_count_net; } // end if
else {
Pul_counter_error = Pul_counter_error + Pul_count_net + (long)((dir_pin_val) * (-1L) * H21A_pul_width);
} // end else ..........
Pul_count_net = 0L;
dir_pin_prev = dir_pin_val;
H21A_total = H21A_total + (long) (dir_pin_val); }
//===========================================================
//========= I2C subroutine to send to Master ============
//===========================================================
void send_i2c_data() {
st_timer3 = micros();
uint8_t buffer[16]; //uint8_t is a byte declaration
int iij = 0;
for (int ii = 0; ii < 8; ii++) {
buffer[iij] = val_arr [ii] >> 8; //shifts the higer bits 8 places to right
iij++;
buffer[iij] = val_arr [ii] & 0xff; //removes the left most 8 bits
iij++; }
Wire.write(buffer,16);
st_timer3 = micros()-st_timer3;
} // end void send_i2c_data()...............
Also the Master Teensy I2C code:
uint16_t buffers ;
uint16_t buffers_inv ;
int available = Wire.requestFrom (5, (uint8_t)16);
while(Wire.available()) {
for (vl_cnt =0; vl_cnt < no_val-2; vl_cnt ++) { //no_val=10 in declaration part
buffers = Wire.read() << 8 | Wire.read();
if (buffers >= 32767) {
buffers_inv = (~ buffers + 1);
val_mstr [vl_cnt] = -1 * buffers_inv; }
else val_mstr [vl_cnt] = buffers;
}
} //....end... while(Wire.available())
Just getting the diy encoder cut on the CNC, and up and running soon, hopefully less crashes now