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

No UART interrupt

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



Joined: 12 May 2015
Posts: 14

View user's profile Send private message

No UART interrupt
PostPosted: Tue May 12, 2015 1:55 am     Reply with quote

Hello people of the CCS community,

Recently I started using the CCS compiler as a trainee at a company. But I think I found a problem. When I want to use the hardware UART of the device(dsPIC30F6014A) it doesn't work on interrupt base. I tried to read the UART manually and it worked. Therefore I think it might be the interrupt handling. I have also looked at other code for another UART interrupt on a different device (18F6620). The interrupt for this device works perfect. Therefore I went deeper in the code and ended in the .lst file. In this file I found the difference between a working and none working UART interrupt. Following is the code I came across:

18F6620:
Code:
 #include <18F6620.h>  //or 18F6620 for double program space
  #fuses HS,NOWDT
  #device ADC=10  //Set to 10bits AD converter
  #use delay(clock=20M,crystal,RESTART_WDT)
  #use rs232(baud=9600, XMIT=PIN_C6, RCV=PIN_C7,STREAM=HOST,ERRORS, TIMEOUT = 20) //setup serial.

This code results in the following in the list file:
Code:

....................   #use rs232(baud=9600, XMIT=PIN_C6, RCV=PIN_C7,STREAM=HOST,ERRORS, TIMEOUT = 20) //setup serial.
035A2:  MOVLW  40
035A4:  MOVLB  1
035A6:  MOVWF  x18
035A8:  CLRWDT
035AA:  MOVLW  02
035AC:  MOVWF  x19
035AE:  MOVLW  9A
035B0:  MOVWF  x1A
035B2:  MOVLB  0
035B4:  BRA    357E
035B6:  MOVLB  1
035B8:  DECFSZ x19,F
035BA:  BRA    35AE
035BC:  DECFSZ x18,F
035BE:  BRA    35C6
035C0:  CLRF   1D
035C2:  CLRF   01                                     
035C4:  BRA    35DA
035C6:  BTFSS  F9E.5
035C8:  BRA    35A8
035CA:  MOVF   FAB,W
035CC:  MOVWF  1D
035CE:  MOVF   FAE,W
035D0:  MOVWF  01
035D2:  BTFSS  1D.1
035D4:  BRA    35DA
035D6:  BCF    FAB.4
035D8:  BSF    FAB.4
035DA:  MOVLB  0
035DC:  GOTO   35E6 (RETURN)
 

As far I can see this is a good code for hardware UART with interrupt (which works). The following is the code for the dsPIC30F6014A:
Code:

 #include <30F6014A.h>
   #device ADC = 12  //Set to 12bits AD converter
   #fuses HS, NOMCLR, PUT64, NOWDT                                                 
   #use delay (clock = 20M, CRYSTAL, RESTART_WDT)   
   #use rs232 (UART2,BAUD = 9600, ERRORS, STREAM = UART_MASTER)
 

This code results in the following in the list file:
Code:

  ....................    #use rs232 (UART2,BAUD = 9600, ERRORS, STREAM = UART_MASTER)   
 

There is no assembly code showing as it did in the example for the 18F6620. Could this be the problem why my UART interrupt doesn't work?

An additional test I had performed is to convert to a software UART, I know this doesn't generate any interrupt but I want to know if it would change the code in the lst file for the UART. And it did change when I converted it to a software UART. This was for both metthods (FORCE_SW, and selecting hardware UART with UART1 but change the RX an TX pin to a none hardware UART).

If someone had the same problem or know the solutions please help me.
This isn't my first programming project and I already "master" different program languages therefore it's really bothering and annoying me and I'm eager to know/learn to solution.

Kind regards,

Remco

ps: If you want more information, please ask I'm happily to provide it.
Ttelmah



Joined: 11 Mar 2010
Posts: 19499

View user's profile Send private message

PostPosted: Tue May 12, 2015 2:42 am     Reply with quote

Start at the beginning. CCS generally _does not_ show it's own routines in the listing.

This is controlled by the line #NOLIST at the start of the processor include file. At some point, somebody has removed this (probably remmed it out), for your 6620 chip, so the listing is there. Do the same for your DSPIC and the listing will appear.

This is done because when you are debugging _your_ code, having dozens of bits of CCS code shown can be confusing.

Always what you post should be a small complete program that shows the problem. Currently we can't compile your code without a lot of guessing as to the missing bits. Something like:
Code:

#include <30F6014A.h>

#FUSES NOWDT                   
#FUSES CKSFSM                 
#FUSES BROWNOUT
#FUSES BORV42
#FUSES NOMCLR
#FUSES HS
#FUSES NODEBUG

#device ICSP=1
#use delay(crystal=20M)
#use rs232(UART2, BAUD=9600, ERRORS, BRGH1OK, STREAM=UART_MASTER)

int1 have_data=FALSE;
int8 chr;

#INT_RDA2
void RX2_int(void)
{
   //crude test for RX2 interrupt
   chr=fgetc(UART_MASTER);
   have_data=TRUE;
}

void main()
{
   int8 local;
   delay_ms(100); //allow time for RS232 buffers to settle
   clear_interrupt(INT_RDA2);
   enable_interrupts(GLOBAL);
   enable_interrupts(INT_RDA2);
   //enable serial interrupt on UART2
   do
   {
      if (have_data)
      {
         //interrupt has occured
         local=chr;
         have_data=FALSE;
         //Now toggle an output to show the interrupt has happened
         //and send the inverted character back
         fputc(local ^ 0xFF, UART_MASTER);
         output_toggle(PIN_B15);
      }
   } while (TRUE);
}

As comments, get rid of restart_wdt. Since you don't have the watchdog enable, 'pointless', and if you were using the watchdog for real, also pointless!....

generally to use the watchdog properly, it must _only_ be restarted, when the code is properly running. Have 'compiler generated' restarts put into bits of the code where the chip could be hung, completely destroys the point of the watchdog....

Using timeout with the interrupt is also pointless. Using the serial interrupt, you should _only_ be reading characters when the interrupt occurs to say 'there is a character'.

Then repeat three times 'what compiler version'....
Remco



Joined: 12 May 2015
Posts: 14

View user's profile Send private message

PostPosted: Tue May 12, 2015 3:50 am     Reply with quote

Ttelmah,

Thank you for your quick reaction. but in the mean time I was trying to get it to work, and I did it. I don't know how but that's I would say usual. But I little at the #NOLIST command. This command only make the C code in the .lst file invisible. This code was not implemented in my code. However thank you for your reaction. I hope this UART interrupt would last by now I hope.

Kind regard,

Remco
jeremiah



Joined: 20 Jul 2010
Posts: 1345

View user's profile Send private message

PostPosted: Tue May 12, 2015 9:44 am     Reply with quote

The compiler doesn't generate code unless you use it or there are some special preprocessor directives used to force it (like the #int_xxx for example).

It's possible you had a mistake in your code that made the compiler think you were never gonna call the function, so it didn't generate code for it.
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