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.

how to access the NVIC registers

Other Parts Discussed in Thread: TM4C123GH6PM

How to access the NVIC registers to activate the GPIO interrupts 

#include<stdint.h>
#include<stdbool.h>
#include<hw_memmap.h>
#include<hw_types.h>
#include<SysCtl.h>
#include<hw_SysCtl.h>
#include<hw_gpio.h>
#include<gpio.h>
#include<tm4c123gh6pm.h>
#include<interrupt.h>
#include<hw_nvic.h>
#include<hw_ints.h>


void delay_ms(int del)
{
del=(SysCtlClockGet()/3.0)*del/1000.0;
SysCtlDelay(del);
}

void GPIOIntHandler(void)
{
if(HWREG(GPIO_PORTB_BASE + GPIO_O_RIS) ==~GPIO_PIN_2)
{HWREG(GPIO_PORTB_BASE + GPIO_O_ICR) =GPIO_PIN_2;
HWREG(GPIO_PORTE_BASE + (GPIO_O_DATA + (GPIO_PIN_3 << 2))) =GPIO_PIN_3;
delay_ms(1000);
HWREG(GPIO_PORTE_BASE + (GPIO_O_DATA + (GPIO_PIN_3 << 2))) =~GPIO_PIN_3;
delay_ms(1000);
}
}

void main()
{
SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);
HWREG(SYSCTL_RCGCGPIO)=SYSCTL_RCGCGPIO_R4|SYSCTL_RCGCGPIO_R1;
HWREG(GPIO_PORTE_BASE + GPIO_O_DIR) = GPIO_PIN_3;
HWREG(GPIO_PORTB_BASE + GPIO_O_DIR) = GPIO_PIN_2;
HWREG(GPIO_PORTE_BASE + GPIO_O_AFSEL) =~GPIO_PIN_3;
HWREG(GPIO_PORTB_BASE + GPIO_O_AFSEL) =~GPIO_PIN_2;
HWREG(GPIO_PORTE_BASE + GPIO_O_DEN) =GPIO_PIN_3;
HWREG(GPIO_PORTB_BASE + GPIO_O_DEN) =GPIO_PIN_2;

//HWREG(GPIO_PORTB_BASE + NVIC_EN0) =0x00000000;//ENABLE
//HWREG(GPIO_PORTB_BASE + GPIO_O_IM) =~GPIO_PIN_2;//DISABEL
HWREG(GPIO_PORTB_BASE + GPIO_O_IS) =~GPIO_PIN_2;//EDGE SELECT
HWREG(GPIO_PORTB_BASE + GPIO_O_IBE) =~GPIO_PIN_2;//EVNT TRIGR
HWREG(GPIO_PORTB_BASE + GPIO_O_IEV) =GPIO_PIN_2;//RAISING EDGE
//HWREG(GPIO_PORTB_BASE + GPIO_O_RIS) =GPIO_PIN_2;//intrrept ocr on pin
//HWREG(GPIO_PORTB_BASE + GPIO_O_MIS) =GPIO_PIN_2;
HWREG(GPIO_PORTB_BASE + GPIO_O_IM) =GPIO_PIN_2;//ENABLE
HWREG(GPIO_PORTB_BASE + NVIC_EN0) =0x00000002;//ENABLE
HWREG(GPIO_PORTB_BASE + NVIC_EN0_INT_M) =0x00000002;

while(1)
{
HWREG(GPIO_PORTB_BASE + (GPIO_O_DATA + (GPIO_PIN_2 << 2))) =~GPIO_PIN_2;
delay_ms(1000);
HWREG(GPIO_PORTB_BASE + (GPIO_O_DATA + (GPIO_PIN_2 << 2))) =GPIO_PIN_2;
delay_ms(1000);
}
}

above is my program.I am using a CCS compiler but it doesn't work plz inform me is there any mistake in my program.. i don't know how to access the NVIC registers is this a correct way to use those registers 

  • Hi Asha,

    Why do you need to make everything in direct register access? Initializations are normally not needed to be criticaly fast code.

    Could you highlight the piece of code you want us to take attention to? Note that you posted the whole code, that's good, but highlighting where your having problems while having the whole code is better.

    Anyway, if you want a interrupt call to handler to occur you need to enable the masked interrupt which you we're disabling, now it's commented out. You need to set the bit of the GPIO you want to enable an interrupt call.



    Also note that here:
    //HWREG(GPIO_PORTB_BASE + NVIC_EN0) =0x00000000;//ENABLE

    You commented out but note that it was really wrong. Why? Your starting base is GPIOB! But NVIC_EN0 is not part of the GPIO registers, instead is from the NVIC.

    You need to learn to check the register maps. Which part are you using?
    Look into 10.4 Register Map on page 658 (if you are using the tm4c123gh6pm). It will show the register map for the GPIO. Then check the description of the registers which will contain also the description of the bit fields.

    Programming in direct register access involves a lot of work and reading which you have to subject yourself if you want to avoid completely using C libraries.
  • Hello Asha,

    I agree with Luis. Do "not" use DRM method for every programming. The existing API's already simplify the development, then why complicate it.

    Regards
    Amit