|
|
View previous topic :: View next topic |
Author |
Message |
ibsumith
Joined: 24 Jul 2009 Posts: 21
|
Interrupt not firing on DATA Receive(INT_RDA,USB HID DEMO) |
Posted: Sat Aug 22, 2009 12:35 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
//#include <usb_cdc.h>
#include <usb.h>
//#include <usbn960x.c>
#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
int8 out_data[2]={1,2};
int8 in_data[2];
//#PRIORITY RDA
#INT_RDA //interrupt fires when receive data available
void serial_isr()
{
LED_ON(LEDG);
if(usb_kbhit(1)){
usb_get_packet(1,in_data,2);
out_data[0]=in_data[0];
out_data[1]=in_data[1];
if (usb_put_packet(1, out_data, 2, USB_DTS_TOGGLE)){return;}
}
return;
}
void main() {
// int8 out_data[2];
// int8 in_data[2];
// output_c(0x04);
// set_tris_c(0x00);
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);
usb_init();
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);
}
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(TRUE)
{
LED_ON(LEDR);
delay_ms(100);
LED_OFF(LEDR);
delay_ms(100);
LED_OFF(LEDG);
}
} |
Please help. This is my code. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Aug 22, 2009 12:42 am |
|
|
#int_rda is the UART receive interrupt. You must use getc() or fgetc()
to get the character from the UART in that interrupt routine. |
|
|
ibsumith
Joined: 24 Jul 2009 Posts: 21
|
|
Posted: Sat Aug 22, 2009 1:07 am |
|
|
thank you for your reply....But i am not getting Interrupt.... |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Aug 22, 2009 1:19 am |
|
|
Are you sending characters to the UART in the PIC, over a RS-232 cable ?
Do you have a MAX232-type chip connected to pins C6 and C7 of your PIC ?
What device is sending the characters to the PIC's UART ? Is it a terminal
program on a PC ?
Just make a small program that only tests the PIC's ability to receive
characters in its UART, using the #int_rda interrupt.
Example of simple program to test the operation of #int_rda:
http://www.ccsinfo.com/forum/viewtopic.php?t=27156&start=1 |
|
|
ibsumith
Joined: 24 Jul 2009 Posts: 21
|
|
Posted: Sat Aug 22, 2009 1:31 am |
|
|
I am trying to communicate through PC program....It is working well when I am using polling....i am connecting to PC using USB cable....C6 and C7 are not externally connected to anything....But when I am Using TBE interrupt is generating...I am using PIC2550.... |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Aug 22, 2009 1:37 am |
|
|
I can't help any more. |
|
|
sumith Guest
|
|
Posted: Sat Aug 22, 2009 3:20 am |
|
|
thank you..........IS there any alternate way ......... to get an interrupt when a data is receive in Endpoint1 |
|
|
bela
Joined: 31 Aug 2008 Posts: 27 Location: Bedford, BEDS UK
|
|
Posted: Sun Aug 23, 2009 3:08 am |
|
|
The usb.c driver uses the USB interrupt (#INT_USB) and it pulls in the data so you shouldn't need to use an interrupt. Simply use usb_kbhit(x) to check if there's data ready. |
|
|
ibsumith
Joined: 24 Jul 2009 Posts: 21
|
|
Posted: Sun Aug 23, 2009 10:49 pm |
|
|
thank u
But where should i check it...Inside while loop.???there is no #int_usb in usb.c...It is in pic18_usb.h |
|
|
broque
Joined: 03 Apr 2012 Posts: 2
|
|
Posted: Sun Apr 15, 2012 11:50 pm |
|
|
Using delay function disables the interrupts. Try not to use delay, you can create a for statement for it. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19498
|
|
Posted: Mon Apr 16, 2012 2:38 am |
|
|
Take a step back, and a deep breath.
Each interrupt in the system responds to a specific _hardware_ event.
INT_RDA, responds to a character being received by the hardware UART, _not_ anything to do with USB.
INT_USB, responds to all the USB stuff, but this doesn't imply a character has been send/received. For instance you will get USB interrupts for enumeration, and commands like 'set line coding', etc. etc..
The whole 'point' of the USB code, is it handles all this for you - automatically sorting out the transfers that contain/expect data, and sending/receiving these for you, allowing you to do other things, and just look whenever you want and see if anything is pending. If you want to respond to the USB interrupt, then you have several thousands of lines of code that need to be written....
Now, to emulate a serial port, you should really be using the USB CDC driver, not fiddling around.
Some comments apply:
For instance, you have the line:
Code: |
#define USB_HID_DEVICE TRUE //Previously it was "DEFINE"
|
It only needs to be defined. the code does not care _what_ it is defined 'as'.
You seem to be trying to fiddle with things, without reading the documentation (the USB code has 90% of it's documentation _in_ the include files - read the headers of these).
However much simpler to just keep to CDC.
So, you could do a basic 'respond to a character received on the CDC device' routine, with:
Code: |
#include<18F2550.h>
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN
#use delay(clock=48000000)
#build(reset=0x1, interrupt=0x8) // Necessary for Bootloader
//Get into the _habit_ of putting all the system configuration _first_.
//Though it doesn't matter for basic 'defines', it does for some stuff
//and it'll 'catch' you one day.
#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
//Do you have a USB connection sense pin?. Use it if so.
#define USB_CON_SENSE_PIN PIN_B2 //remove otherwise
#include <stdlib.h>
#define __USB_PIC_PERIF__ 1
#include <usb_cdc.h>
//All that is needed to load the entire CDC driver....
int8 tick=0;
#INT_TIMER2
void tick_interrupt(void) {
if (tick) --tick;
}
//Simple system clock called every 1/200th second
void main() {
int16 temp_adc;
int8 temp_ch;
//The USB code enables it's interrupts automatically
usb_init();
setup_timer_2(T2_DIV_BY_16,249,15);
enable_interrupts(INT_TIMER2); //system 'clock'
setup_adc_ports(AN0);
//Read the data sheet - is 'INTERNAL' a legal/recommended clock rate.....
setup_adc(ADC_CLOCK_DIV_64);
//
set_adc_channel(0);
delay_us(10);
do {
usb_init(); //change to init_cs if you have a sense pin
if (usb_enumerated()) {
if (usb_cdc_kbhit()) {
//Here a character has been received on the USB
temp_ch=usb_cdc_getc();
switch (temp_ch) {
case 'A':
case 'a':
//If I see an 'A' or 'a' respond with the analog voltage
temp_adc=read_adc();
printf(usb_cdc_putc,"Voltage :- %5.3f\n\r",temp_adc*0.0048828125*
break;
case 'T':
case 't':
//If I see 'T' or 't' 'toggle' the greed LED
output_toggle(LEDG);
break;
} //Ignore every other character
}
}
if (tick==0) {
output_toggle(LEDR);
tick=199; //Toggle the red LED every second
}
}
}
|
Now, 'no guarantees', have just typed this in as a demo, so could easily have a typing error or two, but this should wake up the USB (use the connection sense setting if you have it), thne sit waiting and flashing the green LED every second, then if you press 'T', toggle the green LED, or if you press 'A' read the analog voltage.
The point is you just ask the USB driver 'has anything arrived' (for the CDC 'kbhit'), at regular intervals. The driver has done all the donkey work of actually transferring the data, and storing it.
Best Wishes |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|