Altera_Forum
Honored Contributor
19 years agoGetting variables out of Interrupts
I'm in the process of learning Quartus, SOPC and NIOS and I have many years of programming embedded micros in assembler and C. I have managed to get a littlle system up and running on a 2C20 dev board, including, after much trial, error, reading this forum and Altera apps notes, some interrupt routines. What I just don't seem to be able to do is save a value within a routine and pass it to the main loop.
I have managed to get a serial interrupt handler going and write the ASCII vale of the received character onto the seven segment displays but I can only do that by calling the routines to write to the seven segment displays from within the serial interrupt routine! What I have tried to do is have a global variable called Flags. Within the serial routine I have a line: Flags |= HAD_SERIAL; where HAD_SERIAL is a# define value of 0x01 In the main loop I have the code: if ((Flags & HAD_SERIAL == HAD_SERIAL) { Flags &= ~HAD_SERIAL; WriteToSevSeg(NUMBER1,(ByteRec & 0x0F)); WriteToSevSeg(NUMBER0,((ByteRec >> 4) & 0x0F)); } The serial handler looks like this: void UART_RxD_Int(void* context, alt_u32 id) { ByteRec = IORD(UART_0_BASE, ALTERA_AVALON_UART_RXDATA_REG); // WriteToSevSeg(NUMBER1,(ByteRec & 0x0F)); // WriteToSevSeg(NUMBER0,((ByteRec >> 4) & 0x0F)); Flags = 1; } ByteRec and Flags are global variables. Although I can break within the serial interrupt, the program just refuses to behave properly! It simply will not go to the WriteToSevSeg routine. If I set a breakpoint in the interrupt Flags is allegedly getting set to 1. If I comment out those lines in the interrupt routine, the ASCII value of the character sent is displayed on the seven segment displays. This is exactly the way I handled countless serial interrupts over the years on various "normal" processors. Can anyone tell me what I am doing wrong? I have a suspicion you have to do this with pointers, but I've had a play with them too and can't get it to work. Thanks in advance!