Trouble with Timer code for PSOC 4200

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
DaHu_285096
Level 5
Level 5
10 likes received 250 replies posted 100 replies posted

Hi,

   

I need to implement a synchronous receiver that receives 4 Data Bytes. The bytes are clocked by a hardware clock pin. I have written a routine that works well when data is coming in but if the transmitter stops at certain points part way through, my code hangs. My code should be receiving bits based on clock state but have an overall timeout so if data stops then the routine exits after timeout period but it is not working.   If I call the "sampleLF" routine when no data being received, it hangs in the loop and never sees Timer_Flag set.

   

Any help much appreciated, thanks.

   

Here is my code that uses a 32 bit timer component

   

#define LFSAMPLETIME  24000000/1000*80

   

void StartTimer(volatile uint32 tdelay){
    Timer_WritePeriod(tdelay);
    Timer_WriteCounter(tdelay);
    Timer_Enable(); 
    Timer_Flag = 0;    
}

   

void StopTimer(void){
   Timer_Stop();
   Timer_Flag = 0;   
}

   

void SampleLFData(uint8 * buf){
    volatile uint8  Sample;
    volatile uint8  nBytes;
    volatile uint8 SamplePtr;

   

    Sample = 0;
    nBytes = 0;
    SamplePtr = 0;
 
    StartTimer(LFSAMPLETIME);  //12ms Data 4 Bytes should take 8ms to receive
    while ((!Timer_Flag)&&(nBytes < 4)){   //get 4 bytes or timeout
         while(!CL_DAT_Read() & !Timer_Flag){} //wait for clock high
         Sample<<=1;
         if(DAT_Read()) Sample |= 1;   //read data bit
         SamplePtr++;
         if(SamplePtr == 8){            //save every 8 bits as byte
          if(nBytes < 4) buf[nBytes] = Sample;
          Sample= 0;
          nBytes++;
          SamplePtr = 0;
         }
         while(CL_DAT_Read() & !Timer_Flag){}  //wait for clock low
         CyDelayUs(50);  //clock settle time
    }
    StopTimer();
 }

0 Likes
1 Solution
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Your Timer does not run in deep sleep mode, so no interrupt fired. Better use another source for interrupt.

   

 

   

Bob

View solution in original post

0 Likes
10 Replies