966 views|1 replies

3

Posts

0

Resources
The OP
 

Test of Zhongke Haoxin DSP (280025C) development board based on RISCV instruction set (I) - GPIO interrupt [Copy link]

 This post was last edited by zhaoxiawanqiu on 2024-7-27 14:08

Haoxin Getting Started Learning Record-GPIO Interrupt

Task objective:
Use an external interrupt to trigger a GPIO to control the status flip of two LEDs on the development board

1. As shown in the figure below, we know that GPIO31 and 34 are connected to the cathode of LED6 and LED7 respectively through a buffer, so the low level of the IO port is valid in this experiment.

2. Create a new project according to the guidance of Haawking IDE, select the model of 280025C, and burn the program into Flash.

slightly

3. Analysis of resources used by the main function to achieve the task objectives

1. Clock and peripheral configuration function: Device_Init(); Create a project and automatically generate (160Mhz, this experiment does not take into account power consumption and computing power, so no adjustment is required)
The system default clock comes from the internal OSC1, 10MHZ, which is multiplied by 16 times by the PLL module to 160Mhz. The default LSPCLK division number is 2, the division coefficient is 4, which is 40Mhz.

The following is the function, which is in Device.c. The main function will call it by itself, so you don’t need to worry about it.

2. Interrupt module initialization and vector table initialization functions; called in interrupt.h, Interrupt_initModule(); Interrupt_initVectorTable(); The above two functions are written in the interrupt.c file in the driver library to implement the interrupt initialization function. They need to be called in the main function.


3. GPIO initialization, configure GPIO9 to input mode (external interrupt trigger pin), GPIO31 and 34 to output mode, and call the relevant configuration function in gpio.c

GPIO_setPinConfig(uint32_t pinConfig);

This function is used when configuring the IO port. The macro-defined IO address is passed in. For example, GPIO_9_GPIO9 is the macro of the address of GPIO9. There is no return value.
GPIO_setPadConfig(uint32_t pin, uint32_t pinType)

This function is used to configure the type of the IO port. Parameter 1 is the port number (you can directly give a number), and parameter 2 is the port type. You can pass in the macro-defined type name, such as GPIO_PIN_TYPE_PULLUP for push-pull mode. There is no return value.
GPIO_setQualificationMode(uint32_t pin, GPIO_QualificationMode qualification);

This function configures the clock of the IO port. Parameter 1 is the port number (you can directly give a number), and parameter 2 is the clock configuration. You can pass in the macro-defined clock settings, such as GPIO_QUAL_SYNC for synchronous SYSCLK clock. There is no return value.
GPIO_setDirectionMode(uint32_t pin, GPIO_Direction pinIO);

This function is used to configure the input and output direction of the IO port. Parameter 1 is the port number (you can directly give a number), and parameter 2 is the direction configuration. You can pass in the macro-defined parameters, such as GPIO_DIR_MODE_IN for input mode. There is no return value.

Write a GPIO initialization function in main.c, call the above four configuration functions, then call the initialization function in the main function, and write 1 and 0 to pins 31 and 34 respectively. As shown below:


4. GPIO9 interrupt configuration, call gpio.h related functions, you can see the detailed information of related functions in gpio.h, which is given here with pictures.

Call these three functions in the main function and give appropriate parameters to realize the interrupt configuration of gpio9

GPIO_setInterruptType(GPIO_INT_XINT1, GPIO_INT_TYPE_RISING_EDGE); //Give the interrupt entry number, configure it as rising edge trigger
GPIO_setInterruptPin(9, GPIO_INT_XINT1); //Set port 9 as interrupt pin, give the entry number
GPIO_enableInterrupt(GPIO_INT_XINT1); //Enable the interrupt IO entry number


5. Interrupt enable register, enable port address, global enable, call related functions in interrupt.h

Call these three functions in the main function to implement interrupt configuration

Interrupt_register(INT_XINT1,&GPIO9_INT_Handler);//Give the interrupt entry number corresponding address macro definition parameters, give the interrupt service function address.
Interrupt_enable(INT_XINT1);//Enable the corresponding interrupt entry
Interrupt_enableGlobal();//Enable global interrupt
5.1. Write the interrupt service function as follows, flip the two pin levels in it, and then clear the interrupt group number. This function needs to be declared before main.c.

__interrupt void GPIO9_INT_Handler(void)
{

GPIO_togglePin(31);
GPIO_togglePin(34);

Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP1);

}

3. Overall implementation code. This task only requires writing related functions in main.c. The code is as follows;

#include <syscalls.h>
#include "IQmathLib.h"
#include "hx_intrinsics.h"
#include "driverlib.h"
#include "device.h"
#include "hx_fintdiv.h"

void User_GPIO_Init(void);
__interrupt void GPIO9_INT_Handler(void);

int main(void)
{
//
// Intialize device clock and peripherals
//
Device_init();
//init gpio pin
User_GPIO_Init();

GPIO_writePin(31, 1);
GPIO_writePin(34, 0);

Interrupt_initModule();
Interrupt_initVectorTable();

GPIO_setInterruptType(GPIO_INT_XINT1, GPIO_INT_TYPE_RISING_EDGE);
GPIO_setInterruptPin(9, GPIO_INT_XINT1);
GPIO_enableInterrupt(GPIO_INT_XINT1);


Interrupt_register(INT_XINT1,&GPIO9_INT_Handler);
Interrupt_enable(INT_XINT1);
Interrupt_enableGlobal();

while(1);
return 0;
}

__interrupt void GPIO9_INT_Handler(void)
{

GPIO_togglePin(31);
GPIO_togglePin(34);

Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP1);

}

void User_GPIO_Init(void)
{
//Set GPIO9 to input mode and prepare for interrupt
GPIO_setPinConfig(GPIO_9_GPIO9);
GPIO_setPadConfig(9, GPIO_PIN_TYPE_INVERT);
GPIO_setQualificationMode(9, GPIO_QUAL_SYNC);
GPIO_setDirectionMode(9, GPIO_DIR_MODE_IN);

//Set GPIO34 and GPIO31 to output mode to control LED
GPIO_setPinConfig(GPIO_31_GPIO31);
GPIO_setPadConfig(31, GPIO_PIN_TYPE_PULLUP);
GPIO_setQualificationMode(31, GPIO_QUAL_SYNC);
GPIO_setDirectionMode(31, GPIO_DIR_MODE_OUT);

GPIO_setPinConfig(GPIO_34_GPIO34);
GPIO_setPadConfig(34, GPIO_PIN_TYPE_PULLUP);
GPIO_setQualificationMode(34, GPIO_QUAL_SYNC);
GPIO_setDirectionMode(34, GPIO_DIR_MODE_OUT);
}
//
// End of File

4. Experimental Results and Analysis

Power on to download the program. After pressing the reset button, LED6 and LED7 are off and on respectively as shown in the figure below:

Then keep GPIO9 high level intermittently, switching the status of the two lights

81eb90802d9460ce3e23aa0ce4cc2d75

5. Experimental Summary

This experiment tested the function of GPIO interrupt, used the configuration functions related to GPIO and interrupt, understood the system clock configuration, and completed the function verification by flipping the LED state. I also encountered a test problem in the middle, that is, IO9 kept triggering interrupts after plugging in a DuPont line. At this time, the other end of the DuPont line was in a suspended state. It was probably due to noise or the material of the DuPont line I used, which caused the interrupt to be triggered all the time. When I tested it later, I used a multimeter probe to touch GPIO9 continuously, which had the same effect. The normal solution is to add a capacitor and a pull-down resistor to the external interrupt trigger pin, as long as the pin is not left in a floating state.

Latest reply

Come and have a look, thanks to the host for sharing, let’s cheer together, cheer on!!!   Details Published on 2024-7-30 11:44
 
 

409

Posts

0

Resources
2
 

Come and have a look, thanks to the host for sharing, let’s cheer together, cheer on!!!

 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list