i am working on a project in msp430f2274 microcontroller. In my project i am trying to read an reed switch which is being connected to a GPIO pin at P2.3. Normally the pin will remain HIGH as it is being connected to pull up from the hardware. when once the switch is pressed/activated a LOW will come and it will trigger the Hardware. till here it is working fine. but now i want to read the other interrupt also, when it goes back to high. I have tried the interrupt type from low - high to high -low in ISR but still no efffect. please help.
i have added ISR from the code
static char x=0;
#pragma vector=PORT1_VECTOR
__interrupt void PORT1_ISR(void)
{
P1IES^=BIT2;
P1OUT^=(BIT0); // enrer the rest code for detection of door open or close.
P1IFG &= ~BIT2;
//P1IES&=~BIT2;
__bis_SR_register_on_exit(GIE+LPM0_bits); // Enter LPM3 on ISR exit
}
Just an idea, sry if this doesn't help.
You could use a timer that starts with the button click and triggers an interrupt when the button is released.
Related
I have an EFR32FG14 evaluation board with the example shown in the end.
where it get triggered by an odd number of pins getting pressed.
I want to change this example (in code) so i get the interrupt be triggered by a single pin ,not odd or even.
I have looked inside the example and i see there two lines
NVIC_EnableIRQ(GPIO_ODD_IRQn);
GPIO_ODD_IRQn = 18, /*!< 16+18 EFR32 GPIO_ODD Interrupt */
Inside the GPIO_ODD_IRQHandle event handler called we have
GPIO_IntClear(0xAAAA);
i want to enable interrupt only for PF7(not even or odd) and write an event handler for it.
Is it possile?Thanks.
datasheet:
https://www.silabs.com/documents/public/data-sheets/efr32fg14-datasheet.pdf
user guide:
https://www.silabs.com/documents/public/user-guides/ug318-brd4257b-user-guide.pdf
code example link:
https://github.com/SiliconLabs/peripheral_examples/blob/master/series1/gpio/switch_led_interrupt/src/main_s1.c
I have learned the interrupt system,and ran close example to what i want shown in the post.
The interrupt numbers are fixed when the silicon chip is manufactured. You can't change them.
To have some action taken on PF7 only you could try to use the odd numbered pin interrupt, and then in the handler check which pin was signalled. If it wasn't PF7, then do nothing.
I am currently learning CMSIS-RTOS v2 and I have an issue that is bugging me and I can't find the answer I need.
I am using the STM32L476-Disco board and the joystick center button as an interrupt. I have a very simple Interrupt callback for my center joystick interrupt :
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin){
//osEventFlagsSet(evt_id,0x0001);
HAL_GPIO_TogglePin(LD5_GPIO_Port,LD5_Pin);
osThreadFlagsSet(ThId_Led_Blink,0x0001);
}
When I call osThreadFlagsSet, the microcontroller freezes and nothing else happen. This is why I've put the HAL_GPIO_TogglePin : to see if the mcu was still responding or not.
I know that my interrupt resets correctly because when I only put my pin toggle, I can toggle the Led correctly.
ThId_Led_Blink is a ThreadId
osThreadId ThId_Led_Blink;
I've checked that the ID is set correctly in my debugger and it is (it's not null).
As you can see, I've tried with osEvenFlagsSet and I have the same result.
When I check the CMSIS_RTOS v2 documentation, it does specify that osThreadFlagsSet can be called from an ISR, but I am not sure if I need to do something else in that case for the Flags to be set correctly and resolve the issue when the ISR is hanging.
Thanks for your help
So after frustrating hours of searching, I finally fixed my issue.
As described in this website : https://www.freertos.org/RTOS-Cortex-M3-M4.html, for STM32 microprocessor, you need to set the NVIC Group Priority to 4. If you look on freeRTOS, they are talking about putting this line in your code :
NVIC_PriorityGroupConfig( NVIC_PriorityGroup_4 );
However, the STM32 has it's own library for the NVIC and the correct function to set the priority group is :
HAL_NVIC_SetPriorityGrouping(4);
Why go with the same name when you can change everything?
So make sure to call this function before your kernel initialization if you are using nested interrupts with FreeRTOS/CMSIS RTOS.
Also, make sure that your nested interrupt priority is in the range of configured interrupt priority for your FreeRTOS, otherwise, the osThreadFlagsSet function will fail automatically.
I have a problem with both the sleepmodes and NVIC_reset(), aka software reset.
The problem is present on two totally distinct boards, both with a LPC1769 uC.
If I enter the sleepmode within main() or another function, except an interrupt routine, the sleep mode is working perfecly. The uC wakes also with an external interrupt on EINT0. The reset function does its job also well in the main function.
But when a sleepmode or reset request is invoked inside an interrupt routine trouble starts. The sleep mode lookes to be entered but the uC does not wake up anymore.
E.g. enter a sleep mode with EINT1 and wake with EINT0:
void EINT0_IRQHandler(void)
{
EXTI_ClearEXTIFlag(0);
}
void EINT1_IRQHandler(void)
{
EXTI_ClearEXTIFlag(1);
CLKPWR_Sleep();
}
Anybody a clue why this does not work properly?
Have you checked your interrupt priorities?
34.3.5.2.1 Wakeup from WFI or sleep-on-exit
Normally, the processor wakes up only when it detects an exception with sufficient priority
to cause exception entry.
I have been using the mouse sketch at the bottom of this message (written by someone else) to try to get the motion data out of a PS/2 mouse. I have checked the specification for this mouse which says that it is PS/2 compatible. However, when I run it it appears to stop at the first line of mouse_init where it says, "mouse.write(0xff); // reset". This is a call to a function in ps2.h. ps2.h has been around since 2008 and has been used in a number of projects, so I assume it is okay, but I was wondering if there might be some peculiar features of USB mice connecting as PS/2 mice that this library was never designed to cope with. Does anyone have any experience that might shed some light on this?
I have been able to determine that mouse.write is changing the state of my Genius mouse, but it gets stuck at the point where the Mouse is supposed to bring the clock state low so that the host can proceed to transmit data. Before mouse.write starts the clock state is low, but it gets pushed high by the host a few lines into mouse.write and stays there. The mouse never pulls it low again. Any thoughts on what the trouble might be would be greatly appreciated.
#include <ps2.h>
/*
* an arduino sketch to interface with a ps/2 mouse.
* Also uses serial protocol to talk back to the host
* and report what it finds.
*/
/*
* Pin 5 is the mouse data pin, pin 6 is the clock pin
* Feel free to use whatever pins are convenient.
*/
PS2 mouse(6, 5);
/*
* initialize the mouse. Reset it, and place it into remote
* mode, so we can get the encoder data on demand.
*/
void mouse_init()
{
mouse.write(0xff); // reset
mouse.read(); // ack byte
mouse.read(); // blank */
mouse.read(); // blank */
mouse.write(0xf0); // remote mode
mouse.read(); // ack
delayMicroseconds(100);
}
void setup()
{
Serial.begin(9600);
mouse_init();
}
/*
* get a reading from the mouse and report it back to the
* host via the serial line.
*/
void loop()
{
char mstat;
char mx;
char my;
/* get a reading from the mouse */
mouse.write(0xeb); // give me data!
mouse.read(); // ignore ack
mstat = mouse.read();
mx = mouse.read();
my = mouse.read();
/* send the data back up */
Serial.print(mstat, BIN);
Serial.print("\tX=");
Serial.print(mx, DEC);
Serial.print("\tY=");
Serial.print(my, DEC);
Serial.println();
// delay(20); /* twiddle */
}
Solved it. As it turns out the Genius mouse I brought is not backward compatible with PS/2 even though the specification says it is. They must have exchanged the sensor chip for one where the PS/2 capability was not present at some point. I now have another USB mouse which is doing the job I wanted perfectly.
I want to configure two AVR butterfly boards in such a way that PORT D is an output port in the first one and two pins of this PORT D are connected to pins B.4 and B.5 of port B of the second AVR butterfly board. I also want to enable pull-ups on these port B pins. Is this configuration correct for the second AVR ? Is there something that i am missing?
//Init port pins
DDRB = 0x00;
PORTB |= 0X30;
//Enable pin change interrupt on PORTB
PCMSK1 = 0X30;
EIFR = 0XC0;
EIMSK = 0XC0;
SIGNAL(SIG_PIN_CHANGE1)-- Pin change interrupt of PIN B.4
{..}
SIGNAL(SIG_PIN_CHANGE2)-- Pin change interrupt of PIN B.5
{..... }
You have set up you PORT B correctly but it wouldn't hurt to improve your coding conventions a little.
DDRB&= ~(1<<PB0)|(1<<PB1);
PORTB|= (1<<PB0)|(1<<PB1);
Unless I am miss-understanding what your trying to accomplish, I don't think your interrupts are configured correctly.
PB4 and PB5 correspond to PCINT12 and PCINT13 respectively.
Since both correspond to Pin Change Interrupt Enable 1 you'll want to only have that pin enabled.
EIMSK = (1<<PCIE1);
You don't actually need to set EIFR unless your trying to manually trigger an interrupt. This register gets flagged automatically whenever a pin change occurs.
In PCMSK1 you want to set PCINT13 and PCINT12
PCMSK1 |= (1<<PCINT12)|(1<<PCINT13);
This enables interrupts on the corresponding pins.
Also SIGNAL is depreciated. #include avr/interrupt.h and use ISR.
ISR(PCINT1_vect){}
Both Pin changes will be handled by this vector.
Hope this clears things up a bit.