erpgc82
Junior Member level 1
Hello mr's, I'm having a problem here and I'm not able to solve it, I don't know what happens, if it is some bit of some transmission register that I must clear, if it is the serial interrupt that I need to clear clear_interrupts (INT_RDA) ;.
I put delay_ms (1) as a test, after sending the character.
I've done clear_interrupts (INT_RDA); after re-enabling the serial interrupt.
Anyway, I've done everything and nothing works.
Here is just a piece of the code.
Today I can get the string that arrives at the RX (hardware) I do what I have to do with it and send it to the PC via TX (hardware) and it works perfectly.
The response variable, if it is 1 (TRUE) when the PIC reads sensors / input pins, it must send a certain character to the PC, only when doing this the serial interrupt #INT_RDA stops working.
If the response variable is 0 (FALSE), that is, never send characters to the PC, the serial interrupt works perfectly. Note¹: it always stops when a certain number of characters arrives, and then right after a certain function that takes about 5 seconds to occur, the serial interruption is reactivated and this works PERFECTLY.
I'm not getting to know why it hangs / stops after sending a character to the PC. Note¹: Whenever I send a character to the computer, the serial interrupt is activated (at least it was supposed to be) because until then the PIC had not read anything from it and so it was not deactivated.
tanks();
I put delay_ms (1) as a test, after sending the character.
I've done clear_interrupts (INT_RDA); after re-enabling the serial interrupt.
Anyway, I've done everything and nothing works.
Here is just a piece of the code.
Today I can get the string that arrives at the RX (hardware) I do what I have to do with it and send it to the PC via TX (hardware) and it works perfectly.
The response variable, if it is 1 (TRUE) when the PIC reads sensors / input pins, it must send a certain character to the PC, only when doing this the serial interrupt #INT_RDA stops working.
If the response variable is 0 (FALSE), that is, never send characters to the PC, the serial interrupt works perfectly. Note¹: it always stops when a certain number of characters arrives, and then right after a certain function that takes about 5 seconds to occur, the serial interruption is reactivated and this works PERFECTLY.
I'm not getting to know why it hangs / stops after sending a character to the PC. Note¹: Whenever I send a character to the computer, the serial interrupt is activated (at least it was supposed to be) because until then the PIC had not read anything from it and so it was not deactivated.
tanks();
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 #include <16F876a.h> #case #use delay(clock=10000000) #fuses HS,NOWDT, PUT, BROWNOUT, NOLVP #use rs232(baud=9600, parity=N, xmit=PIN_C6, rcv=PIN_C7, bits=8, stop=1, ERRORS) int1 returns=1; char X='X'; char Y='Y'; #INT_RDA void serial_isr() { restartRS232(); // It's unnecessarily here int t; buffer[next_in]=getc(); t=next_in; next_in=(next_in+1)%BUFFER_SIZE; if(next_in==next_out) next_in=t; } BYTE bgetc() { BYTE c; while(!bkbhit); c=buffer[next_out]; next_out=(next_out+1)%BUFFER_SIZE; return(c); } void main() { enable_interrupts(GLOBAL); enable_interrupts(INT_RDA); while(TRUE) { if(bkbhit) { c=bgetc(); if(c=='0') { key_card=TRUE; clean_keyboard(); output_high(BEEP); delay_ms(40); output_low(BEEP); barcode_buffer[0]=c; barcode_buffer[1]=bgetc(); barcode_buffer[2]=bgetc(); barcode_buffer[3]=bgetc(); barcode_buffer[2]=0; printf("%c%c%c%c%c%cC\n\r",barcode_buffer[0],barcode_buffer[1],barcode_buffer[2],barcode_buffer[3]); d_int_rda=FALSE; disable_interrupts(INT_RDA); read_code(); } /*******************************************************************************************/ if((returns)&&(!input(SENSOR_OUT))) printf("%c\r\n",X); if((returns)&&(!input(SENSOR_IN))) printf("%c\r\n",Y); } } }