PIC18 I seem to have a conflict with UART interrupt and SPI

Beta Testing discussion on mikroC PRO for PIC.
Post Reply
Author
Message
robviljoen
Posts: 4
Joined: 27 Nov 2010 11:28

PIC18 I seem to have a conflict with UART interrupt and SPI

#1 Post by robviljoen » 05 May 2012 11:14

If any one can help me, I am developing a home management system. I am using the EasyBee board to communicate between a central controller (PIC18F4685), IO Units (PIC16F887), human interface unit (PIC18F87J50) and a PC. For the central controller I'm using interrupts for the UART connection to the EasyBee and I have a MMC using SPI. The program complexity is fairly high and it seems the UART interrupt is interfering with the MMC or SPI communication giving me random read and write errors when I have high UART activity. Is this possible and if so what may be the best way to manage this without compromise to either the UART and SPI communication? Appreciate any help. I want to push the PIC18F4685 to run at it's max of 40 m Hz (current 11 m Hz) and reduce the UART interrupt to a few lines of assembler code and run the SPI at a higher speed (current DIV64).

Regards
Rob Viljoen

User avatar
janko.kaljevic
Posts: 3565
Joined: 16 Jun 2011 13:48

Re: PIC18 I seem to have a conflict with UART interrupt and

#2 Post by janko.kaljevic » 07 May 2012 12:41

Hello,

This is really strange and definitely UART interrupts should not interfere with SPI communication.
This behavior is caused by something else in your code.

If you can post here your ISR.

It is always good idea to minimize ISR and you should do that.

Best regards.

robviljoen
Posts: 4
Joined: 27 Nov 2010 11:28

Re: PIC18 I seem to have a conflict with UART interrupt and

#3 Post by robviljoen » 07 May 2012 20:05

//------------------------------------------------------------------------------
// INTERUPT PROCEDURE
//------------------------------------------------------------------------------
void interrupt() {

//--READ UART AND BUFFER THE DATA RECIEVED FROM EASYBEE-------------------------

uart_data_buffer[rx_pointer] = UART_Read();
++rx_pointer;
if (rx_pointer >= 60)
rx_pointer = 0;
}

I have reduced the code in the ISR to a minimum, it was much longer. The program seems to be working much better. I do not seem to be getting MMC init errors and MMC write errors.
Surely with time critical code, if the interrupt occurs just before the SPI register (SSPBUF) is read and does not return in time an overflow can occur and the SSPOV: Receive Overflow Indicator bit will be set? I'm running a 60 character buffer and seems to be ok, is the array method efficient in assembler? I'm also not modifying any of the ISR variables in my main code.

Regards
Rob Viljoen

User avatar
janko.kaljevic
Posts: 3565
Joined: 16 Jun 2011 13:48

Re: PIC18 I seem to have a conflict with UART interrupt and

#4 Post by janko.kaljevic » 08 May 2012 08:43

Hello,

With minimized ISR you should get proper behavior.
And I think that you are doing it well. Also you can check if receive overflow occurs and clear it in your code.
Or increase frequency of the controller.

Best regards.

Post Reply

Return to “mikroC PRO for PIC Beta Testing”