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

a question about CAN with disPIC33EP256MU814

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



Joined: 29 Aug 2012
Posts: 97

View user's profile Send private message

a question about CAN with disPIC33EP256MU814
PostPosted: Tue Sep 04, 2012 4:00 pm     Reply with quote

Hi, there

I am using disPIC33EP256MU814 with ccs pcd 4.133 compiler,
I am playing with CAN module now, however I got a CAN interrupt problem,

my code is below:
Code:

#if defined(__PCD__)
#include <33EP256MU814.h>
//#include <i2c.h>
#fuses HS,PR,NOWDT,ICSP2
#device ADC=12
#use delay(clock=20000000)
#pin_select U1TX = PIN_D0
#pin_select U1RX = PIN_D1
#pin_select U2TX = PIN_D2
#pin_select U2RX = PIN_D3
#use RS232(UART1, STREAM = GSM, BAUD=9600, XMIT = PIN_D0 , RCV = PIN_D1 ,  BITS = 8, STOP = 1, PARITY = N, ERRORS) // Actual Baud is 38400 due to clock (10M not 20M)
#use RS232(UART2, STREAM = MODBUS, BAUD=9600, XMIT = PIN_D2 , RCV = PIN_D3 ,  BITS = 8, STOP = 1, PARITY = N, ERRORS) // Actual Baud is 38400 due to clock (10M not 20M)
//#use spi(MASTER, DO = PIN_G8, CLK = PIN_G6, mode = 3, stream=SPI_STREAM)
#use i2c(MASTER, I2C1,SCL = PIN_D10, SDA = PIN_D9 , FORCE_SW)
#pin_select IC1=PIN_F0
#pin_select C1TX = PIN_D6
#pin_select C1RX = PIN_D5
#endif


And I want to use interrupt to deal with incoming CAN messages, so I define CAN interrupt as follow:
Code:

#INT_CAN1RX
void can1_isr()
{
   can_getd(rx_id, &in_data[0], rx_len, rxstat);
   CAN_Mgs_Ready = TRUE;
   canMsgCounter ++;
}

however, when I compiled, the ccs report an error as "Line 118(0,1): Invalid Pre-Processor directive"
If I change "#INT_CAN1RX" to "#INT_CAN1", the compile can pass, but once the message comes in, it triggers the default interrupt which means the program can NOT find the entrance for CAN interrupt of receive.
I also tried #int_canrx0 or #int_can0rx ect. but got the same compiling error.
Anything wrong I did? please help, Thanks a lot!

Regards
Mark
naughty_mark



Joined: 29 Aug 2012
Posts: 97

View user's profile Send private message

PostPosted: Tue Sep 04, 2012 4:59 pm     Reply with quote

Hi, there

I checked the latest PCD reference manual, and it said now only supports #INT_CAN1 and #INT_CAN2, all interrupts related to corresponding CAN share the same interrupt entrance.

However, I still have problem, as I mentioned, even I use "#INT_CAN1", the program can NOT find the proper interrupt, and it jumps into default interrupt instead! Any idea?

Thanks~ Smile
naughty_mark



Joined: 29 Aug 2012
Posts: 97

View user's profile Send private message

PostPosted: Tue Sep 04, 2012 5:43 pm     Reply with quote

Hi, guys,

some updates.
the default interrupt was not caused by incoming CAN messages, a bug in my LCD display function. I fixed that.
Now, there is no interruption happened during CAN messages coming in!

I put some code that if CAN interruption is called, then micro will display "What!" on LCD display, but nothing there.

Code:

void test_can( void )
{

   static int1 in=0;
   char s[30];

   restart_wdt();

   can_init();
      can_enable_interrupts(RB|RXOV|WAK);

     sprintf(s, " CAN Init Done ");
     printCusString(s);


      delay_ms(100);
     sprintf(s, "CAN TEST ");
     printCusString(s);

      enable_interrupts(INTR_GLOBAL);

     do
     {
        if (CAN_Mgs_Ready)
        {
           decode_can();
           restart_wdt();
        }
     }while(canMsgCounter < 100);

}


And the CAN interruption now is
Code:

#INT_CAN1
void CAN1_isr()
{
   unsigned int16 tmp;
   char s[11];
   if (C1INTF.rbif == 1/*can_kbhit()*/)
   {
      can_getd(rx_id, &in_data[0], rx_len, rxstat);
      CAN_Mgs_Ready = TRUE;
      canMsgCounter ++;
   }
   tmp = C1INTF; //clear flags, no idea if it works well
   sprintf(s, "Whaaaaaat!");
   printCusString(s);
}

Any idea?
naughty_mark



Joined: 29 Aug 2012
Posts: 97

View user's profile Send private message

PostPosted: Tue Sep 04, 2012 7:30 pm     Reply with quote

Hi, guys

I made it works!

Firstly, there is #INT_CAN1 and #INT_C1RX interrupt name can be used, the first one is for general CAN event, the second for CAN1 receive interrupt and I used the second.

Secondly, I add "IEC2 |= 0x04; //enable can rx interrupt in interrupt register" after can_enable_interrupts() statement, you can find what this register does in micro data sheet.

Thanks for your guys concern.
Maybe more question further, who knows~ Razz
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