CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

PIC16F88 UART interrupt problem?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
onuruygur



Joined: 17 Jul 2009
Posts: 7

View user's profile Send private message

PIC16F88 UART interrupt problem?
PostPosted: Fri Jul 17, 2009 8:47 am     Reply with quote

Hi all,

I am working on PIC16F88. Here is the project task:

When the right id is received on UART HW RX, PIC16F88 will send a sensor measurement word.

I have to use HW UART because i need INT_RDA routine. But when I simulate the code on ISIS and send any character on virtual terminal, I receive the error: logic contentions.

"This message has been generated because one or more logic contentions have occurred on the specified net. A logic contention occurs when two or more outputs of the same strength attempt to drive the net into opposing logic states. A logic contention is also reported if a strong logic state is overridden by a generator or power rail. "

PIC doesn't run the code in the int_rda routine and goes to main's loops.

This is a basic application I guess...? what is the problem?

Here is my basic HW_UART code:
Code:

#include <16F88.h>
#device adc=8

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES HS                       //High speed Osc (> 4mhz)
#FUSES NOPUT                    //No Power Up Timer
#FUSES MCLR                     //Master Clear pin enabled
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD                    //No EE protection
#FUSES NOWRT                    //Program memory not write protected
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES PROTECT                  //Code protected from reads
#FUSES NOFCMEN                  //Fail-safe clock monitor disabled
#FUSES NOIESO                   //Internal External Switch Over mode disabled

#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_B5,rcv=PIN_B2,bits=8,stream=MODEM,errors)


and the C file is:
Code:

#int_RDA
RDA_isr()
{
output_bit(PIN_B1,1); //This is just for indication.
}

void main()
{
   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_OFF);
   setup_spi(FALSE);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   setup_oscillator(False);

   // TODO: USER CODE!!

while(TRUE){
fprintf(MODEM,"hi all");
delay_ms(500);}
}


Thanks in advance.
Smile
mkuang



Joined: 14 Dec 2007
Posts: 257

View user's profile Send private message Send e-mail

PostPosted: Fri Jul 17, 2009 9:06 am     Reply with quote

You are using the standard hardware uart ports on this PIC. You can omit the stream name MODEM in your #use RS232 declaration. In your main code you can just use printf instead.

Also you need to enable serial interrupt. Add these lines of code in main():

Code:

clear_interrupt(INT_RDA);
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);
dyeatman



Joined: 06 Sep 2003
Posts: 1935
Location: Norman, OK

View user's profile Send private message

PostPosted: Fri Jul 17, 2009 9:40 am     Reply with quote

They will also have to perform a getc() in the ISR to clear the interrupt.

Code:
 byte inputchar;
 inputchar=getc();

_________________
Google and Forum Search are some of your best tools!!!!
onuruygur



Joined: 17 Jul 2009
Posts: 7

View user's profile Send private message

PostPosted: Fri Jul 17, 2009 11:23 am     Reply with quote

Thank you for your replies, Wink

I am sorry that I have forgotten to put the codes related with enabling interrupts although I was already placed in my own code. Here is the new code which also includes your advices. But nothing have changed.

Would you share your comments pls?

Code:

#include <16F88.h>
#device adc=8

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES HS                       //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOPUT                    //No Power Up Timer
#FUSES NOMCLR                   //Master Clear pin used for I/O
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD                    //No EE protection
#FUSES NOWRT                    //Program memory not write protected
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES PROTECT                  //Code protected from reading
#FUSES NOFCMEN                  //Fail-safe clock monitor disabled
#FUSES NOIESO                   //Internal External Switch Over mode disabled

#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_B5,rcv=PIN_B2,bits=8,errors)


and the main.c is:

Code:

#include "f88_hw_uart.h"

byte inputchar;

#int_RDA
void  RDA_isr(void)
{
output_bit(PIN_B1,1);
inputchar=getc();
}

void main()
{

   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_OFF);
   setup_spi(SPI_SS_DISABLED);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   
   clear_interrupt(INT_RDA);
   enable_interrupts(INT_RDA);
   enable_interrupts(GLOBAL);

//Setup_Oscillator parameter not selected from Intr Oscillator Config tab

   // TODO: USER CODE!!
   printf("Hi all!\n\r");
   
while(TRUE){
delay_ms(500);
putc(inputchar);
}
}


The problem is same on ISIS:
At startup:
CFGWORD2 not implemented,
and when any char is sent over virtual terminal :

Logic contention is detected on PIC_RX.

Thanks is advance...
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jul 17, 2009 11:34 am     Reply with quote

Quote:

setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF);
setup_spi(SPI_SS_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);

That line sets the TRIS for the hardware SPI pins. The SPI module
shares the SDO pin with the Rx pin for the UART. The SDO pin is
an output pin, but the Rx pin is an input pin. This is causing the
"logic contention". Remove the line shown in bold.
onuruygur



Joined: 17 Jul 2009
Posts: 7

View user's profile Send private message

PostPosted: Fri Jul 17, 2009 1:41 pm     Reply with quote

PCM programmer wrote:
Quote:

setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF);
setup_spi(SPI_SS_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);

That line sets the TRIS for the hardware SPI pins. The SPI module
shares the SDO pin with the Rx pin for the UART. The SDO pin is
an output pin, but the Rx pin is an input pin. This is causing the
"logic contention". Remove the line shown in bold.



Very good orientation! That solved the problem. Thank you very much to all, of course to PCM Programmer also. Very Happy
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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