View previous topic :: View next topic |
Author |
Message |
ibsumith
Joined: 24 Jul 2009 Posts: 21
|
Isr not working----plse help |
Posted: Tue Aug 11, 2009 3:03 am |
|
|
#include<18F2550.h> //Microchip PIC18F2550 hardware layer
#define __USB_PIC_PERIF__ 1 //Only for PIC18f4550
#define LEDR PIN_B4 //Red LED is connected to Pin No:25
#define LEDG PIN_B5 //Green LED is connected to Pin No:26
#define BUTTON PIN_C0 //A Button is connected to Pin No:11
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN
#use delay(clock=48000000)
#build(reset=0x1, interrupt=0x8) // Necessary for Bootloader
//#ORG 0x0F00,0x0FFF {} // Necessary for Bootloader
#use rs232(stream=PC, baud=9600, xmit=PIN_C6, rcv=PIN_C7,)
//Tells the CCS PIC USB firmware to include HID handling code.
#define USB_HID_DEVICE TRUE //Previously it was "DEFINE"
//the following defines needed for the CCS USB PIC driver to enable the TX endpoint 1
// and allocate buffer space on the peripheral
#define USB_EP1_TX_ENABLE USB_ENABLE_INTERRUPT //turn on EP1 for IN bulk/interrupt transfers
#define USB_EP1_TX_SIZE 8 //allocate 8 bytes in the hardware for transmission
//the following defines needed for the CCS USB PIC driver to enable the RX endpoint 1
// and allocate buffer space on the peripheral
#define USB_EP1_RX_ENABLE USB_ENABLE_INTERRUPT //turn on EP1 for OUT bulk/interrupt transfers
#define USB_EP1_RX_SIZE 8 //allocate 8 bytes in the hardware for reception
// CCS USB Libraries
#include <pic18_usb.h> //Microchip 18Fxx5x hardware layer for usb.c
#include <usb_desc_hid.h> //USB Configuration and Device descriptors for this UBS device
#include <usb.c> //handles usb setup tokens and get descriptor reports
#define LED_ON output_high //output_high SETS GIVEN PIN TO HIGH
#define LED_OFF output_low //output_low SETS GIVEN PIN TO LOW
#define DELAY 1000
/*#INT_TIMER0 //Timer0 Interrupt
void timer0interrupt()
{
LED_OFF(LEDG);
LED_OFF(LEDR);
disable_interrupts(int_timer0);
delay_ms(1000);
}*/
#INT_RDA //interrupt fires when receive data available
void serial_isr()
{
LED_OFF(LEDG);
LED_OFF(LEDR);
delay_ms(1000);
}
void main() {
int8 out_data[2];
int8 in_data[2];
enable_interrupts(global);
enable_interrupts(INT_RDA);
usb_init();
LED_OFF(LEDR);
usb_task(); //Will call usb_attach().To attach USB Device to the bus.
usb_wait_for_enumeration();
if(usb_enumerated()){ //Checks if device Enumeration Successful or Not
LED_ON(LEDR);
delay_ms(DELAY);
LED_OFF(LEDR);
delay_ms(DELAY);
LED_ON(LEDG);
delay_ms(2000);
}
else
LED_OFF(LEDR);
#if defined(AN0) //Enabling Port for Communication
setup_adc_ports(AN0);
#elif defined(AN0_AN1_AN3)
setup_adc_ports(AN0_AN1_AN3);
#else
#error CONFIGURE ADC PORTS SO WE CAN READ CHANNEL 0
#endif
setup_adc(ADC_CLOCK_INTERNAL);
set_adc_channel(0);
while(input(BUTTON)) //Initially Button Status is High
{
LED_ON(LEDG);
LED_ON(LEDR);
}
} |
|
|
rnielsen
Joined: 23 Sep 2003 Posts: 852 Location: Utah
|
|
Posted: Tue Aug 11, 2009 3:11 am |
|
|
First of all, do not disable/enable interrupts inside an ISR. A BIG no-no. Second, don't place delays inside ISRs. ISRs should be short, get in, do something quickly and then get out.
You don't show any setup statement for timer0 so I can't see if it's being set up properly. You don't have any statement that enables timer0's ISR, inside of main(). It's not going to be triggered unless it's enabled.
Just looked at your code rather quickly, since it's soooo late. That's what I could see for now. I'm sure other people will have more to comment.
Ronald |
|
|
Wayne_
Joined: 10 Oct 2007 Posts: 681
|
|
Posted: Tue Aug 11, 2009 3:12 am |
|
|
Please use code tags when posting code.
You need to read the character to clear the interrupt.
Code: |
#INT_RDA //interrupt fires when 1 character is available
void serial_isr()
{
int c = fgetc(PC);
}
|
But you have a bigger problem.
You get an interrupt on every single char recieved. The serial hardware can only hold 2 chars at a time. Anymore and you get an error condition.
After you have read the first one you have a delay of 1 second.
In this time (1 sec) you may recieve a lot more chars.
This WILL cause your serial port to hang.
You can fix the hang by placing ERRORS in your #use rs232 statement BUT you will still end up missing lots of chars during that period of time.
I realise this is only a test program so make sure you only send 1 character at a time with at least a 1 second delay between them. Remember that pressing return on the terminal program may send more than 1 char! |
|
|
sumith Guest
|
|
Posted: Tue Aug 11, 2009 4:16 am |
|
|
still not working properly.....iN DEVICE MANAGER ITS SHOWING yellow color.........thank you for replying |
|
|
ibsumith
Joined: 24 Jul 2009 Posts: 21
|
I changed it to |
Posted: Tue Aug 11, 2009 4:22 am |
|
|
Code: | #include<18F2550.h> //Microchip PIC18F2550 hardware layer
#define __USB_PIC_PERIF__ 1 //Only for PIC18f4550
#define LEDR PIN_B4 //Red LED is connected to Pin No:25
#define LEDG PIN_B5 //Green LED is connected to Pin No:26
#define BUTTON PIN_C0 //A Button is connected to Pin No:11
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN
#use delay(clock=48000000)
#build(reset=0x1, interrupt=0x8) // Necessary for Bootloader
//#ORG 0x0F00,0x0FFF {} // Necessary for Bootloader
#use rs232(stream=PC, baud=9600, xmit=PIN_C6, rcv=PIN_C7,)
//Tells the CCS PIC USB firmware to include HID handling code.
#define USB_HID_DEVICE TRUE //Previously it was "DEFINE"
//the following defines needed for the CCS USB PIC driver to enable the TX endpoint 1
// and allocate buffer space on the peripheral
#define USB_EP1_TX_ENABLE USB_ENABLE_INTERRUPT //turn on EP1 for IN bulk/interrupt transfers
#define USB_EP1_TX_SIZE 8 //allocate 8 bytes in the hardware for transmission
//the following defines needed for the CCS USB PIC driver to enable the RX endpoint 1
// and allocate buffer space on the peripheral
#define USB_EP1_RX_ENABLE USB_ENABLE_INTERRUPT //turn on EP1 for OUT bulk/interrupt transfers
#define USB_EP1_RX_SIZE 8 //allocate 8 bytes in the hardware for reception
// CCS USB Libraries
#include <pic18_usb.h> //Microchip 18Fxx5x hardware layer for usb.c
#include <usb_desc_hid.h> //USB Configuration and Device descriptors for this UBS device
#include <usb.c> //handles usb setup tokens and get descriptor reports
#define LED_ON output_high //output_high SETS GIVEN PIN TO HIGH
#define LED_OFF output_low //output_low SETS GIVEN PIN TO LOW
#define DELAY 1000
#INT_RDA //interrupt fires when receive data available
void serial_isr()
{
int c;
c = fgetc(PC);
LED_OFF(LEDG);
LED_OFF(LEDR);
delay_ms(100);
}
void main() {
int8 out_data[2];
int8 in_data[2];
enable_interrupts(global);
enable_interrupts(INT_RDA);
usb_init();
LED_OFF(LEDR);
usb_task(); //Will call usb_attach().To attach USB Device to the bus.
usb_wait_for_enumeration();
if(usb_enumerated()){ //Checks if device Enumeration Successful or Not
LED_ON(LEDR);
delay_ms(DELAY);
LED_OFF(LEDR);
delay_ms(DELAY);
LED_ON(LEDG);
delay_ms(2000);
}
else
LED_OFF(LEDR);
#if defined(AN0) //Enabling Port for Communication
setup_adc_ports(AN0);
#elif defined(AN0_AN1_AN3)
setup_adc_ports(AN0_AN1_AN3);
#else
#error CONFIGURE ADC PORTS SO WE CAN READ CHANNEL 0
#endif
setup_adc(ADC_CLOCK_INTERNAL);
set_adc_channel(0);
while(input(BUTTON)) //Initially Button Status is High
{
LED_ON(LEDG);
LED_ON(LEDR);
} |
|
|
|
Wayne_
Joined: 10 Oct 2007 Posts: 681
|
|
Posted: Tue Aug 11, 2009 4:56 am |
|
|
sumith wrote: | still not working properly.....iN DEVICE MANAGER ITS SHOWING yellow color.........thank you for replying |
So this is nothing to do with the ISR (Serial) it is to do with USB!
Please state clearly what the problem is you are having with it!
i.e The USB device on the PC is yellow with an exclamation mark in it. |
|
|
ibsumith
Joined: 24 Jul 2009 Posts: 21
|
|
Posted: Tue Aug 11, 2009 6:02 am |
|
|
yah..I am trying to communicate with pc |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Aug 11, 2009 12:10 pm |
|
|
It looks like you are trying to make the CCS HID demo work. You should
have put that in the title of your post: "Need help with HID demo"
In the link below, I provide a "walk through" for the CCS Hiddemo
example. It explains how to modify the Ex_usb_hid.c file, so it will
work with your hardware:
http://www.ccsinfo.com/forum/viewtopic.php?t=38897 |
|
|
|