Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

About interrupt on PIC18F25k50

Status
Not open for further replies.

maniac84

Full Member level 6
Full Member level 6
Joined
Mar 4, 2012
Messages
337
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,298
Visit site
Activity points
3,661
Hi guys,

I'm using PIC18F25K50 and using in serial comm as well as usb comm. I'm using interrupt on the serial comm.
My application is sending the data through usb on whatever it received on serial.
Just want to know, is it that during when usb is transmitting, we have to close the interrupt of the serial comm (INTCONbits.GIE = 0)? Or it can be on?
 

GIE is not serial interrupt but it is Global Interrupt Enable. Don't disable any interrupt. USB and UART uses different interrupts.

So is it that when USB is transmitting, I can still receive data from serial interrupt? Because I have this problem, when my USB is transmitting, I can't receive anything from my serial communication.

Just checking am I write the correct coding, may I ask what is the register for enable/disable usb interrupt and what is the register for enable/disable serial interrupt?
 
Last edited:

Can we received data from serial interrupt while transmitting through data from usb?
 

I think USB interrupt has higher priority than serial interrupt and hence when USB is working you are not able to receive serial data. Try to modify interrupt priority and make serial interrupt highest priority.
 

I found out that it is not my serial communication problem anymore. I did received the data through serial.
Now the problem is that the destination of my usb transmission sometimes receive my data, sometimes did not.
May I ask, is it that by using the coding below that I will be able to transmit usb data?
Code:
if (HIDTxHandleBusy(USBInHandle) == 0)		 
{
	USBInHandle = HIDTxPacket(HID_EP, (BYTE*)&tx_data, HID_INPUT_REPORT_BYTES);

}
As long as I put my data in "tx_data", my data will be sent out right?
Then why is it sometimes the destination did not received?
 

I'm doing a circular buffer for the serial side. Below is the partial coding:

Code:
void YourHighPriorityISRCode()
{
	if(INTCON3bits.INT2IF == 1)
	{
		INTCON3bits.INT2IF = 0;	
	}	
	
	if(PIR1bits.RCIF!=1) 
		return;

	rxbuf = RCREG;

	if (rxbuf==TOKEN)
	{
		b485RxToken = 1;
		return;
	}	

	if (!b485SOH)
	{
		if (rxbuf!=SOH)
		{
			return;
		}
		b485SOH=1;
		return;
	}	
	if (n485RxDataPos>=RS485RXSIZE)
		n485RxDataPos = 0;

	RS485RXDATA[n485RxDataPos++] = rxbuf;
	if (rxbuf == EOT) 
		b485SOH = 0;	
}

void main(void)
{
nstate = STATE_RS485_RXDATA;
    while(1)
    {
        USBDeviceTasks();
	switch (nState)
	{
		////////////////////////////////////////////////////////////////////////////////////////////////////////
		case STATE_RS485_RXDATA:
			p485 = 0;
			INTCONbits.GIE = 1;
			if (nUSBReady == 0)
			{
				if (n485RxDataPos != n485PrDataPos)
				{
					j = n485PrDataPos;
					for (i=0; i<RS485RXSIZE; i++)
					{
						if (RS485RXDATA[n485PrDataPos] == EOT)
						{
							byTmp = i;
							n485PrDataPos++;
							memset (hid_report_in, 0, sizeof(hid_report_in));
							hid_report_in[0] = SOH;
							if (RS485RXSIZE - j >= byTmp + 1)
								memcpy ((void*)&hid_report_in[1], (void*)&RS485RXDATA[j], byTmp);
							else if (RS485RXSIZE - j < byTmp + 1)
							{
								memcpy ((void*)&hid_report_in[1], (void*)&RS485RXDATA[j], byTmp);
								memcpy ((void*)&hid_report_in[RS485RXSIZE - j + 1], (void*)&RS485RXDATA[0], (byTmp+1)-(RS485RXSIZE - j));
							}
							hid_report_in[byTmp+1] = EOT;
							hid_report_in[byTmp+2] = 0x00;
							if (RS485RXSIZE - j >= byTmp + 1)
								memset (&RS485RXDATA[j], 0, byTmp+1);
							else if (RS485RXSIZE - j < byTmp + 1)
							{
								memset (&RS485RXDATA[j], 0, byTmp+1);
								memset (&RS485RXDATA[0], 0, (byTmp+1)-(RS485RXSIZE - j));
							}
							nState = STATE_SERVER_TXDATA;
							nRS485TX = 1;
							nUSBReady = 1;
							break;
						}
						n485PrDataPos++;
						if (n485PrDataPos>=RS485RXSIZE)
							n485PrDataPos = 0;
					}
				}
			}
                      break;

		case STATE_SERVER_TXDATA:
			if (nHoldTXServer>0)		
			{
				nHoldTXServer--;
				break;
			}
			if (HIDTxHandleBusy(USBInHandle) == 0)		 
			{
				USBInHandle = HIDTxPacket(HID_EP, (BYTE*)&hid_report_in, HID_INPUT_REPORT_BYTES);
				nState = STATE_RS485_RXDATA;
				nWaitTXServer = 0;
				nHoldTXServer = nDefaultHoldTXServer;
				if (nRS485TX == 1) 
				{
					nRS485TX = 0;
					nUSBReady = 0;
				}
			}

			if (nWaitTXServer <= 0)
			{
				nWaitTXServer = 5000;
			}
			else
				nWaitTXServer--;

			break;
}
}

I don't have the coding for the usb receiver's device. I just want to check on my side here am I sending all the data out.
Could you guys help me?

- - - Updated - - -

How do I make sure that my data got transmit out by the usb?
I'm using Pickit3 and since there's no debug window, the only way I do is to put a breakpoint on the line "USBInHandle = HIDTxPacket(HID_EP, (BYTE*)&hid_report_in, HID_INPUT_REPORT_BYTES);". Whenever my routine run until that breakpoint it will halt. Does by putting a breakpoint at that line shows that my data got transmit out by the usb?
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top