I need three time period for onewire data reading. Without writing any ISR and can I get required time periods by polling M0, M1 and M2 match register interrup flags. Following code is what I am working on and it doesn't work. Is there any missing settings else?
#define Presc 14 //--------------------------16 bit write ---------------------------- void onewire_write(short int bayt, short int data) // 6, 54, 10 { short int count, bits; bits = bayt * 8; #define AB 6 #define BC 60 #define DD 10 #define M0_i 1 // Bit <2:0> <s:r:i> Stop,Reset,Interrupt #define M1_i 1<<3 // Bit <5:3> <s:r:i> " #define M2_irs 7<<6 // Bit <8:6> <s:r:i> " T1PR = Presc; // Prescale 15, 60 MHz CClock, 15 MHz PCLCK T1MR0 = AB; // Wait this long T1MR1 = AB+BC; // Wait this long T1MR2 = AB+BC+DD ; // Wait this long T1MCR = M0_i | M1_i | M2_irs; // Interrupt,stop and reset settings of Match regs T1TCR = 0x02; // Reset timer1 for (count=0; count<bits; ++count) { output_low(); T1TCR = 0x01; // timer1 starts while(!(T1IR & 1)); // Wait for int flag if ( data&1 != 0 ) output_float(); // write 0 or 1 data >>= 1; while(!(T1IR & 2)); // Wait for int flag output_float(); // set 1-wire high again, while(!(T1IR & 4)); // Wait for int flag T1IR = 0x07; // Clear M2, M1, M0 interrupts } }
Dear Westermark, you are absolutely right. So I will transfer the disable and enable interrupts call instruction to bit writing or reading loops of write and read functions.