This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

LPC2138 timer1 match register int setting without ISR code

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

 }
}

Parents
  • You are at gmt+1, me +2 :)

    I will follow your recommendation concerning unsigned integers. Most probably this issue caused me problems.

    "// Wait this long" comment is not mine. I found a delay function on the net and modified a bit. Comment comes from that paste :) Function was something like:

    void delay_ms(unsigned int msec)
    {
     T1TCR = 0x02; // Reset
     T1MCR = 0x07; // stop, reset and Interrupt
     T1PR  = 15000;
     T1MR0 = msec; // Wait this long
     T1TCR = 0x01; // Go
     while(!(T1IR & 1)); // Wait for int flag
     T1IR = 0x01; // Clear interrupt
    }
    


    Comments are very important. I sometimes forgot to modify or update. Due to its little code size, I thougt I understant the lines and functions (I have red also ds18b20 datasheet and grasped most parts) and left modification after finishing the code. You are right, if I request help from others, first I have to give descriptions, comments etc.

    For the version control, sometimes I did it in very primitive way (daily or after some succes I get compressed back up and name it in a descriptive way). For an hobbyist like me, I think it is acceptable :)

Reply
  • You are at gmt+1, me +2 :)

    I will follow your recommendation concerning unsigned integers. Most probably this issue caused me problems.

    "// Wait this long" comment is not mine. I found a delay function on the net and modified a bit. Comment comes from that paste :) Function was something like:

    void delay_ms(unsigned int msec)
    {
     T1TCR = 0x02; // Reset
     T1MCR = 0x07; // stop, reset and Interrupt
     T1PR  = 15000;
     T1MR0 = msec; // Wait this long
     T1TCR = 0x01; // Go
     while(!(T1IR & 1)); // Wait for int flag
     T1IR = 0x01; // Clear interrupt
    }
    


    Comments are very important. I sometimes forgot to modify or update. Due to its little code size, I thougt I understant the lines and functions (I have red also ds18b20 datasheet and grasped most parts) and left modification after finishing the code. You are right, if I request help from others, first I have to give descriptions, comments etc.

    For the version control, sometimes I did it in very primitive way (daily or after some succes I get compressed back up and name it in a descriptive way). For an hobbyist like me, I think it is acceptable :)

Children
  • Yes, I'm at GMT+1 (Sweden).

    Don't do zip files. Hobbyist or professional doesn't much matter. The problems to solve is the same. Basically - what code constitutes a specific version? What was changed between two versions? What may be the reason that two versions behaves differently?

    There are many free solutions available. Why not try a CVSNT repository? Works fine on a Windows machine, and since the repository is just text files, a bad disk accident still makes it possible to extract information from whatever files or disk sectors that did survive.

  • Dear Westermark,
    I have no previous CVS experience. I have just downloaded a free version, not yet installed. I will try. Thanks ... (PS:I am from Turkiye.)