jayanth.devarayanadurga
Banned
- Joined
- Dec 4, 2012
- Messages
- 4,280
- Helped
- 822
- Reputation
- 1,654
- Reaction score
- 791
- Trophy points
- 1,393
- Location
- Bangalore, India
- Activity points
- 0
I am using ATMEGA16 and mikroC PRO AVR compiler. I need to know why serial reception using interrupts is not working. The UART transmit is working fine.
Edit: The problem is solved. I used the mikroC PRO AVR interrupt assistant and it worked.
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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 // LCD module connections sbit LCD_RS at PORTB2_bit; sbit LCD_EN at PORTB3_bit; sbit LCD_D4 at PORTB4_bit; sbit LCD_D5 at PORTB5_bit; sbit LCD_D6 at PORTB6_bit; sbit LCD_D7 at PORTB7_bit; sbit LCD_RS_Direction at DDB2_bit; sbit LCD_EN_Direction at DDB3_bit; sbit LCD_D4_Direction at DDB4_bit; sbit LCD_D5_Direction at DDB5_bit; sbit LCD_D6_Direction at DDB6_bit; sbit LCD_D7_Direction at DDB7_bit; // End LCD module connections unsigned char ackPacket[64] = ""; unsigned int i = 0; unsigned char processAck = 0, cmd = 0; #define Lo(param) ((char *)¶m)[0] #define Hi(param) ((char *)¶m)[1] #define Higher(param) ((char *)¶m)[2] #define Highest(param) ((char *)¶m)[3] const unsigned int gheader = 0xEF01; unsigned long goriginalModuleAddress = 0xFFFFFFFF; unsigned long gnewModuleAddress = 0xAABBCCDD; unsigned long gmoduleAddress = 0xFFFFFFFF; unsigned long gchipAddress = 0xFFFFFFFF; unsigned long int gpassword = 0xABCDEF01; unsigned short gturnOnPort = 1, gturnOffPort = 0; unsigned short gbufferID = 0, gpageNum2 = 0; unsigned int gpageID = 0, gnoOfTemplates = 0, gstartPage = 0, gpageNum = 0; unsigned char gdataContent[32] = ""; void UART1_Write_Byte(unsigned char byte){ UART1_Write(byte); } unsigned int findChecksum(unsigned char PID, unsigned int pLen, unsigned char instructionCode){ return (PID + pLen + instructionCode); } void cmd_GenerateImage(const unsigned int header, unsigned long int moduleAddress, unsigned char PID, unsigned int pLen, unsigned char instructionCode); //Finger Print Processing Functions //Generate Image void cmd_GenerateImage(const unsigned int header, unsigned long int moduleAddress, unsigned char PID, unsigned int pLen, unsigned char instructionCode){ UART1_Write_Byte(Hi(header)); UART1_Write_Byte(Lo(header)); UART1_Write_Byte(Highest(moduleAddress)); UART1_Write_Byte(Higher(moduleAddress)); UART1_Write_Byte(Hi(moduleAddress)); UART1_Write_Byte(Lo(moduleAddress)); UART1_Write_Byte(PID); UART1_Write_Byte(Hi(pLen)); UART1_Write_Byte(Lo(pLen)); UART1_Write_Byte(instructionCode); UART1_Write_Byte((findChecksum(PID, pLen, instructionCode) >> 8)); UART1_Write_Byte((findChecksum(PID, pLen, instructionCode) & 0xFF)); } void Interrupt(){ if(RXC_bit){ if(cmd == 7){ ackPacket[i] = UDR; i++; } if(i == 10)processAck = 1; } RXC_bit = 0; } void main() { DDRB = 0xFF; PORTB = 0x00; DDRD = 0xFE; PORTD = 0x00; UART1_Init(57600); Delay_ms(2000); RXCIE_bit = 1; asm{ sei } Lcd_Init(); // Initialize LCD Lcd_Cmd(_LCD_CLEAR); // Clear display Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off Lcd_Out(1,1,"FP Scanner"); // Write text in first row while(1){ //Send some command to FP Scanner if(!processAck){ cmd = 7; cmd_GenerateImage(gheader, gmoduleAddress, 0x01, 0x03, 0x01); } else if(processAck){ if(ackPacket[9] == 0x00)Lcd_Out(2,1,"Finger collection success"); else if(ackPacket[9] == 0x01)Lcd_Out(2,1,"Error when receiving Package"); else if(ackPacket[9] == 0x02)Lcd_Out(2,1,"Can't detect finger"); else if(ackPacket[9] == 0x03)Lcd_Out(2,1,"Fail to collect finger"); else if(ackPacket[0] == 'K')Lcd_Out(2,1,"Received..."); processAck = 0; i = 0; cmd = 0; } Delay_ms(10000); } }
Edit: The problem is solved. I used the mikroC PRO AVR interrupt assistant and it worked.
Last edited: