This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

microsecond delay

Other Parts Discussed in Thread: ENERGIA

Hi friends,

I trying to build library for DHT11 sensor for this I written API for 1 microsecond delay with help of energia

void delayMicroseconds(unsigned int us)
{
int i=0;
// Systick timer rolls over every 1000000/SYSTICKHZ microseconds
if (us > (1000000UL / SYSTICKHZ - 1)) {
delay(us / 1000); // delay milliseconds
us = us % 1000; // handle remainder of delay
};

// 24 bit timer - mask off undefined bits
unsigned long startTime = HWREG(NVIC_ST_CURRENT) & NVIC_ST_CURRENT_M;

unsigned long ticks = (unsigned long)us * (F_CPU/1000000L);
volatile unsigned long elapsedTime;

if (ticks > startTime) {
ticks = (ticks + (NVIC_ST_CURRENT_M - (unsigned long)F_CPU / SYSTICKHZ)) & NVIC_ST_CURRENT_M;
}

do {
elapsedTime = (startTime-(HWREG(NVIC_ST_CURRENT) & NVIC_ST_CURRENT_M )) & NVIC_ST_CURRENT_M;
} while(elapsedTime <= ticks);


}

it is working in enegia, but I want same in Code Composer Studio. but I am getting infine loop at above line mention in RED color.

I  always getting the value of elapsedTime is always zero.

Regards,

Arvind