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 support@ccsinfo.com

PIC16F1718 Serial Interrupt

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



Joined: 25 Oct 2004
Posts: 136

View user's profile Send private message

PIC16F1718 Serial Interrupt
PostPosted: Thu Oct 22, 2015 5:41 am     Reply with quote

Hello Friends

Since i am converting to this new chip I have a lot of troubles to solve.

Today I need your help with a very easy problem, but I can't see the solution.

Easy program, serial data out, serial interrupt BUT no interrupt occurs !!!!

Serial data out is working !

Has anybody an idea ????
Code:

#include <C:/pic_projekte/LEGO_Controller/16F1718.h>
#device ICD=TRUE
#device adc=8

#FUSES NOWDT                    //No Watch Dog Timer
#fuses INTRC_IO
#FUSES PUT                      //Power Up Timer
#FUSES MCLR                     //Master Clear pin enabled
#FUSES PROTECT                  //Code protected from reads
#FUSES NOBROWNOUT               //NO  Reset when brownout detected//
#FUSES IESO                     //Internal External Switch Over mode enabled
#FUSES FCMEN                    //Fail-safe clock monitor enabled
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES DEBUG                    //Debug mode for use with ICD
#FUSES NOWRT                    //Program memory not write protected
#FUSES RESERVED                 //Used to set the reserved FUSE bits

#define Com1 Ser1

#use delay(clock=8000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=Ser1,errors)


#define TxDat   PIN_C6
#define RxDat   PIN_C7

int8 ch;

#int_RDA
void  RDA_isr(void)
{
 ch = getch(Com1);
}

void main()
{
setup_oscillator(OSC_8MHZ);
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);
output_float(RxDat);

fprintf(Com1,"A5A5A5A5A5A");

while(TRUE)
{
    printf(Com1,"123456");
}
}


As IDE I use MPLABX because MPLAB is not supporting this chip...

Hope to get some help here.

best regards
Andreas
temtronic



Joined: 01 Jul 2010
Posts: 9198
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Oct 22, 2015 5:44 am     Reply with quote

Quick look...


Your 'stream' is called Ser1, your ISR getch(COM1). That might be it...

OR

You have ICD and Debug ON, that might be it.


I need more coffee, but that's a start...

Jay
Andreas



Joined: 25 Oct 2004
Posts: 136

View user's profile Send private message

PostPosted: Thu Oct 22, 2015 6:08 am     Reply with quote

Hello temtronic

Take your coffee !!!

I just tried your ideas, no change !

BUT I got one new Problem, the line with A5A5A5 has been sent, but not the line with 12345 in the main program !!!!

It looks that there is a more basic problem.

best regards
Andreass
Andreas



Joined: 25 Oct 2004
Posts: 136

View user's profile Send private message

PostPosted: Thu Oct 22, 2015 6:13 am     Reply with quote

hello temtronic

Sorry, forget the last problem, was a typo, the program now sends the data in the main every pass !

BUT no rcv interrupt occurs with serial data incoming.

best regards
Andreas
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Thu Oct 22, 2015 8:04 am     Reply with quote

Hi Andreas,

Well, first off, your test program is *really* weird! I'm really not sure you understand the use of 'streams', because you aren't doing it correctly! I'm also not sure how you *know* that the serial interrupt isn't firing because as-written your code does not provide the necessary feedback. Try this code, and see what happens:

Code:

#include <C:/pic_projekte/LEGO_Controller/16F1718.h>
#device ICD=TRUE
#device adc=8

#FUSES NOWDT                    //No Watch Dog Timer
#fuses INTRC_IO
#FUSES PUT                      //Power Up Timer
#FUSES MCLR                     //Master Clear pin enabled
#FUSES PROTECT                  //Code protected from reads
#FUSES NOBROWNOUT               //NO  Reset when brownout detected//
#FUSES IESO                     //Internal External Switch Over mode enabled
#FUSES FCMEN                    //Fail-safe clock monitor enabled
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES DEBUG                    //Debug mode for use with ICD
#FUSES NOWRT                    //Program memory not write protected
#FUSES RESERVED                 //Used to set the reserved FUSE bits

#use delay(clock=8000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=Ser1,errors)

int1 CharRcvd = False;
int8 ch = 0;

#int_RDA
void  RDA_isr(void)
{
 ch = fgetc(Ser1);
 CharRcvd = True;
}

void main()
{
setup_oscillator(OSC_8MHZ);
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);

fprintf(Ser1,"Here at the top of Main!\n\r");

while(TRUE)
{
    if(charRcvd)
    {
   fprintf(Ser1,"%u\n\r", ch);
   CharRcvd = False;
    }
    else
        fprintf(Ser1,"Waiting for Character\n\r", ch);
       
}
}


I didn't test this, but it should be OK, and should show you that the serial interrupt is working!
_________________
John

If it's worth doing, it's worth doing in real hardware!
Ttelmah



Joined: 11 Mar 2010
Posts: 19436

View user's profile Send private message

PostPosted: Thu Oct 22, 2015 8:51 am     Reply with quote

The reason is actually rather obvious.

Your chip has PPS. The pins can be programmed to be on particular locations. This _has_ to be setup, or CCS will by default always use software RS232 (hence no interrupt).....

Code:

//suitable header for your chip
#PIN_SELECT U1RX=PIN_C7
#PIN_SELECT U1TX=PIN_C6
//program UART1 to use it's pins on PORTC

#use rs232(baud=9600,parity=N,UART1,bits=8,stream=SER1)
//now setup this UART

void main()
{

   while(TRUE)
   {
      fprintf(SER1,"Hello"); //send something to the UART
   }

}

You will then find the interrupts will work (since now the hardware UART is being used).
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Thu Oct 22, 2015 9:44 am     Reply with quote

Hi,

Err, of course! Highlights the importance of consulting the device datasheet before 'shooting from the hip'..... Shocked
_________________
John

If it's worth doing, it's worth doing in real hardware!
Andreas



Joined: 25 Oct 2004
Posts: 136

View user's profile Send private message

PostPosted: Thu Oct 22, 2015 10:13 am     Reply with quote

Hi All

Strange to me is that the compiler should take care of pin settings??

Okay I will try all Your hints later this night, I should deliver tomorrow.........

Also i am little confused because the whole prog runs on the 886 since 2 years!!!!

BTW is the setting of the PPS possible With compiler functions????

Again thanks for your suggestion.

Best regards Andreas
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Thu Oct 22, 2015 10:25 am     Reply with quote

Hi,

PPS = 'Peripheral Pin Select', which means that certain peripheral functions, such as the UART, can be 'mapped' by the user to specific user-defined pins on the PIC. Thus, on chips equipped with PPS, you must tell the compiler which peripheral functions get mapped to which pins. In the case of the 16F1718 UART, without explicitly stating the pin assignment using the 'PIN_SELECT' directive, the compiler will default to using a software serial implementation, and thus no interrupt.

I don't think that the 16F886 has PPS, so it wouldn't be an issue for that chip.
_________________
John

If it's worth doing, it's worth doing in real hardware!
Andreas



Joined: 25 Oct 2004
Posts: 136

View user's profile Send private message

PostPosted: Thu Oct 22, 2015 10:47 am     Reply with quote

Hi ezflyr

I have read the manual but couldn't find an entry for the uart 1.

Also in the uart setup i defined the pins to use, is that not enough ???

Best regards
Andreas
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Thu Oct 22, 2015 11:33 am     Reply with quote

Hi,

Correct, that is not enough! You must do it like Ttelmah showed you!

Look at the #pin_select entry in the CCS manual...
_________________
John

If it's worth doing, it's worth doing in real hardware!
Andreas



Joined: 25 Oct 2004
Posts: 136

View user's profile Send private message

PostPosted: Thu Oct 22, 2015 12:24 pm     Reply with quote

Hello To All !


Thanks a lot for your comments, yes the information from Ttelmah was the solution !

I was reading the manual but again, the info that the serial port function is called U1RX I couldn't found, where is this described ?

Best regards and many thanks.
Andreas
Ttelmah



Joined: 11 Mar 2010
Posts: 19436

View user's profile Send private message

PostPosted: Thu Oct 22, 2015 1:03 pm     Reply with quote

If you look at the top of the .h file for the processor, it lists the names of all the re-mappable device pins on the chip.

The compiler 'does' take care of it all for you, but you do have to tell it what you want to do. Smile
Andreas



Joined: 25 Oct 2004
Posts: 136

View user's profile Send private message

PostPosted: Thu Oct 22, 2015 3:14 pm     Reply with quote

Thanks Ttelmah

Sometimes the solution more nearby than you can think !!

best regards
Andreas
Ttelmah



Joined: 11 Mar 2010
Posts: 19436

View user's profile Send private message

PostPosted: Fri Oct 23, 2015 12:40 am     Reply with quote

Yes, it is also a thing of 'migration'.

Generally the smaller PIC's all came along, long before any form of peripheral re-mapping existed. So people get into thinking "the peripheral is 'on' these pins". It's only a few of the more recent PIC16's that support PPS (and even then in a slightly more restrictive way than the older chips). However you could (for instance) be setting up the UART on another pair of pins somewhere later, so the compiler cannot assume you want to use the UART, unless it is told that you are connecting the UART to these particular pins...
The way I do it (using the UART _name_ to ensure that the #USE _will_ use the hardware), is the most reliable way of working with the re-mappable peripherals. Very Happy

Have fun.
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