你好
我正在使用 TM4C1294XL 评估板。 我要将波形发生器连接到电路板的 PD0。 因此、基本而言、我的任务是计算接收到的占空比的开通时间。 为此、PD0配置如下
void GPIOInit()
{
//
// Enable the GPIOD peripheral
//
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
//
// Wait for the GPIOD module to be ready.
//
while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOD))
{
}
//
// Register the port-level interrupt handler. This handler is the first
// level interrupt handler for all the pin interrupts.
//
GPIOIntRegister(GPIO_PORTD_BASE, GPIOD_Handler);
//
// Initialize the GPIO pin configuration.
//
// Set pins 0 as input, SW controlled.
//
GPIOPinTypeGPIOInput(GPIO_PORTD_BASE, GPIO_PIN_0);
//
// Make pins 0 rising edge triggered interrupts.
//
GPIOIntTypeSet(GPIO_PORTD_BASE, GPIO_PIN_0, GPIO_BOTH_EDGES);
GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_0,0);
i32Val = GPIOPinRead(GPIO_PORTD_BASE, GPIO_PIN_0);
UARTprintf("\n\nInitial value of PD0 = '%d'",i32Val);
//
// Enable the pin interrupts.
//
GPIOIntEnable(GPIO_PORTD_BASE, GPIO_INT_PIN_0);
}
现在、重点是、在 ISR 中、我想要检测上升沿或下降沿何时到达、以便能够准确地在下降沿到达时捕获计时器计数器值。 最初、我以为如果在引脚 PD0上接收到零、则接收到下降沿、如果接收到一个下降沿、则应该是上升沿、但我不确定这一点。我所写的内容如下、
void GPIOD_Handler(void)
{
uint32_t status;
status = GPIOIntStatus(GPIO_PORTD_BASE,true);
//
// Clear the interrupt.
//
GPIOIntClear(GPIO_PORTD_BASE, status);
check_edge = GPIOPinRead(GPIO_PORTD_BASE, GPIO_PIN_0);
if(check_edge == 0) //positive edge detected
{
UARTprintf("\n\nPositive edge DETECTED!!");
i32Val = GPIOPinRead(GPIO_PORTD_BASE, GPIO_PIN_0);
UARTprintf("\nPositive Edge value of PD0 = '%d'",i32Val);
}
else if(check_edge == 1) //negative edge detected
{
flag = true;
UARTprintf("\n\nNegative edge DETECTED!!");
i32Val = GPIOPinRead(GPIO_PORTD_BASE, GPIO_PIN_0);
UARTprintf("\nNegative Edge value of PD0 = '%d'",i32Val);
}
GPIOIntDisable(GPIO_PORTD_BASE, GPIO_INT_PIN_0);
}
此外、我要连接接收随机0 snd 1的输出!
因此、我想在 ISR 中确保接收到下降沿还是上升沿。
我们非常感谢您的任何帮助或建议!
此致、
Omkar Dixit
