I am usig 18F4550 usb and i wanna send data through eusart. I am also using easypic V7 so i can see every differencies on board. Here is my problem. When usb pluged in, some of my uart bytes sent (for few seconds) but then it stops. When i plug off and plug in it sends some again. I believe there is intrerrupt colission. When i set usb interrupt priority high usb works fine but not uart. When i set uart interrupt priority high, USB doesnt recognise. Do you have any idea ? I am using 18F4450 internnal clock and 20Mhz crystal for usb.
Code: Select all
unsigned char readbuff[64] absolute 0x500; // Buffers should be in USB RAM, please consult datasheet
unsigned char writebuff[64] absolute 0x540;
unsigned int i=10;
char uart_rd;
#include <PcParam.h>
#include <ChParam.h>
void interrupt_low(void){
USB_Interrupt_Proc(); // USB servicing is done inside the interrupt
}
void interrupt(){
INTCON.GIE=0; // Global interrupts enabled -high priority- ********
if (PIR1.RCIF) // If interrupt is generated by RCIF
{
UART1_Write(UART1_Read()+1);
PORTB=UART1_Read();
if (RCSTA.RX9){
PORTB=UART1_Read(); // Show me data
}
if (RCSTA.OERR){ // if overrun error=1 then show me
PORTB=0xfc;
// RCSTA.CREN=0; //CREN: Continuous Receive Enable bit
}
if (RCSTA.FERR){ // if framing error=1 then show me
PORTB=0xfe;
}
}
RCIF_bit=0;
INTCON.GIE=1; // Global interrupts enabled -high priority- ********
}
void main(void){
ADCON1 = 0x0F; //all port pins are digital
ADCON0 = 0x00;
ADCON2 = 0x00;
OSCCON.IRCF0=0; // 4 mhz internal timer setup configrations
OSCCON.IRCF1=1; // See datasheet
OSCCON.IRCF2=1;
OSCCON.SCS0=1;
OSCCON.SCS1=1;
TRISC.RC7=1; // Page 274
TRISC.RC6=1; // Page 274
PIE2.USBIE=1; // USB Interrupt Enable Bit
RCON.IPEN=1; // Enable priority levels on interrupts
INTCON.PEIE=1; // Peripheral interrupts enabled -low priority-
INTCON.GIE=1; // Global interrupts enabled -high priority- ********
IPR1.RCIP=1; // EUSART Receive Interrupt Priority bit - pg 106 -
IPR1.TXIP=1; // EUSART Transmit Interrupt Priority bit
IPR2.USBIP=0; // USB Interrupt Priority bit *********
TXSTA.TX9=1; //TX9: 9-bit Transmit Enable bit pg 277
TXSTA.TXEN=1; //TXEN: Transmit Enable bit(1) ***********
TXSTA.SYNC=0; //SYNC: Asynchronous EUSART Mode Select bit
TXSTA.SENDB=1; //SENDB: Send Break Character bit
TXSTA.BRGH=1; //BRGH: High Baud Rate Select bit
RCSTA.SPEN=1; //SPEN: Serial Port Enable bit pg 278 ******
RCSTA.RX9=1; //RX9: 9-bit Receive Enable bit
RCSTA.CREN=1; //CREN: Continuous Receive Enable bit ********
RCSTA.ADDEN=0; //ADDEN: Address Detect Enable bit
BAUDCON.ABDEN=0; //ABDEN: Auto-Baud Detect Enable bit pg 279
BAUDCON.BRG16=1; //BRG16: 16-bit Baud Rate Generator bit
UART1_Init(9600); // Initialize UART module at 9600 bps
Delay_ms(100); // Wait for UART module to stabilize
TRISB=0;
PORTB=0;
HID_Enable(&readbuff,&writebuff); // Enable HID communication
return;
while(1){
if(HID_Read())
{
GetPcParam(); // Get values that sent from pc
for (i=9; i<30; i++ ) writebuff[i]=readbuff[i]; // Send back Signal specs to check
while(!HID_Write(&writebuff,64)); //Send to PC
Delay_ms(5);
// RCSTA.CREN=1; //CREN: Continuous Receive Enable bit
// TXSTA.TXEN=1; //TXEN: Transmit Enable bit(1)
}
}
}