Part Number: CC2541
Tool/software: TI C/C++ Compiler
About the delay function, the output unit is microsecond, it could not output the right time. Following is detail code:
/**************************************************************************************************
* @fn HalLcd_HW_WaitUs
*
* @brief wait for x us. @ 32MHz MCU clock it takes 32 "nop"s for 1 us delay.
*
* @param x us. range[0-65536]
*
* @return None
**************************************************************************************************/
void HalLcd_HW_WaitUs(uint16 microSecs)
{
while(microSecs--)
{
/* 32 NOPs == 1 usecs */
asm("nop"); asm("nop"); asm("nop"); asm("nop"); asm("nop");
asm("nop"); asm("nop"); asm("nop"); asm("nop"); asm("nop");
asm("nop"); asm("nop"); asm("nop"); asm("nop"); asm("nop");
asm("nop"); asm("nop"); asm("nop"); asm("nop"); asm("nop");
asm("nop"); asm("nop"); asm("nop"); asm("nop"); asm("nop");
asm("nop"); asm("nop"); asm("nop"); asm("nop"); asm("nop");
asm("nop"); asm("nop");
}
}
The examination method is using Oscilloscope to check the high level duration of P0_1. Following is detail code:
P0_1 = 1; HalLcd_HW_WaitUs(1); P0_1 = 0;
The actual result is around 580us--620us.
Later the duration is around 600us even I did not execute Function HalLcd_HW_WaitUs() and just execute P0_1 = 1; and P0_1 = 0,The clock = 32MHz。
I doubted the BLE Statck affected the execute time, so I try to use the demo in ..CC2541_43_44_45_Peripherals_Software_Examples\software_examples\io to just set time clock and control P0_1, the result is the same, the time cost is above 500us by just operating GPIO!
int main(void)
{
/***************************************************************************
* Setup I/O
*
*/
// Disable the 32 kHz RCOSC calibration
SLEEPCMD |= OSC32K_CALDIS;
// Change the system clock source to HS XOSC and set the clock speed to 32 MHz.
CLKCONCMD = (CLKCONCMD & ~(CLKCON_CLKSPD | CLKCON_OSC)) | CLKCON_CLKSPD_32M;
// Wait until system clock source has changed to HS XOSC (CLKCONSTA.OSC = 0).
while(CLKCONSTA & CLKCON_OSC);
#if(chip==2541 || chip==2543 || chip==2545)
// Initialize P0_1 for SRF05EB S1 button.
P0SEL &= ~BIT1; // Function as General Purpose I/O.
P0DIR |= BIT1; // Input.
//P0INP |= BIT1; // Select input type as 3-state, S1 has external pulldown.
P0_1 = 0; // LED1 on.
#endif
/***************************************************************************
* Main loop
*
*/
while(1)
{
P0_1 = 1;
P0_1 = 0;
}
}
Could someone tell me why?
Compiler Environmen: IAR