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

CAN issue (pin selection?) on 24HJ64GP504 CANBUS [SOLVED]

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



Joined: 19 Jan 2015
Posts: 3

View user's profile Send private message

CAN issue (pin selection?) on 24HJ64GP504 CANBUS [SOLVED]
PostPosted: Mon Jan 19, 2015 5:24 pm     Reply with quote

Hi, I'm having trouble getting any output from the CAN module on a 24HJ64GP504. After digging around a bit on here, I have this much:

Header:
Code:
#include <24HJ64GP504.h>
#device *=16
#device ICD=TRUE

#use delay(clock=20000000, osc) // OSC turns on external oscillator input instead of RC

#define VREF_P   PIN_A0
#define VREF_N   PIN_A1
#define CLK_IN   PIN_A2
#define PGED     PIN_B0
#define PGEC     PIN_B1
#define LED_15   PIN_B2
#define CAN_EN   PIN_B3
#define I2C_SCL  PIN_B8
#define I2C_SDA  PIN_B9
#define SPI_CS1  PIN_B10
#define SPI_CLK  PIN_B11
#define SPI_RD   PIN_B12
#define SPI_WR   PIN_B13
#define CAN_TXD  PIN_C0
#define CAN_RXD  PIN_C1
#define RS232_RX PIN_C4
#define RS232_TX PIN_C5
#define SPI_CS2  PIN_C6
#define SPARE2   PIN_C7
#define SPARE1   PIN_C8
#define INTX     PIN_C9
#define INT_AFE  PIN_B7

#use fixed_IO(B_outputs = PIN_B1,PIN_B2,PIN_B3,PIN_B8,PIN_B10,PIN_B11,PIN_B13)
#use fixed_IO(C_outputs = PIN_C5,PIN_C6)

...


Main:
Code:
#include <07740.h>
#include <2402.C>
#include <float.h>
#include <math.h>
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <can-PIC24.c>
#include <lm76.c>

#FUSES HS,NOWDT,NOOSCIO
#build (stack=256)

...
//CANBUS Clock configuration
#define CAN_BRG_PRESCALAR           4    //Set CAN Baud Rate to 125K
#define CAN_BRG_PHASE_SEGMENT_1     1    //Tq = (2(1+PRESCALAR))/(Fosc/2)
#define CAN_BRG_PHASE_SEGMENT_2     1    //Tq = (2(1+4)/(20000000/2) = 0.000001
#define CAN_BRG_PROPAGATION_TIME    2    //Baud Rate = 1/(((PHASE_SEGMENT_1+1)+(PHASE_SEGMENT_2+1)+(PROPAGATION_TIME+1)+(JUMP_WIDTH+1))*Tq)
#define CAN_BRG_SYNCH_JUMP_WIDTH    0    //Baud Rate = 1/(((1+1)+(1+1)+(2+1)+(0+1))*0.000001) = 125000

//CANBUS pin assignment
// pin_select does not work, pins must be assigned manually!!!!!
// See http://www.ccsinfo.com/forum/viewtopic.php?t=39189
#bit IOLOCK  = 0x742.6
#byte OSCCONL = 0x742
#word RPINR26 = 0x06B4  // Location to assign pin to use for CAN RX
#byte RPOR8 = 0x6D0     // Location to assign function to Pin RP16

//CANBUS TX Buffer
unsigned int8 cantxbuffer[8];

...

void main()
{

...

//CANBUS

   OSCCONL = 0x46;
   OSCCONL = 0x57;
   IOLOCK = 0;
   RPINR26 = 0x11;  // Pin RP17 assigned to CAN 1 RX function
   RPOR8 = 0x10;    // CAN 1 TX function to Pin RP16
   OSCCONL = 0x46;
   OSCCONL = 0x57;
   IOLOCK = 1;

   can_init();
   can_set_mode(CAN_OP_CONFIG);

   can_enable_b_transfer(TRB0);  //make buffer 0 a transmit buffer  //
   can_enable_b_receiver(RB8);

   can_set_mode(CAN_OP_NORMAL); 




   enable_interrupts(INT_TIMER1);
   enable_interrupts(INT_EXT1);
   enable_interrupts(INT_EXT2);

...

   while(1) // Main loop
   {
      processHWisrs();
      processRxBuff();

//CANBUS
      cantxbuffer[0]=0x5a;
      can_putd(0x123, &cantxbuffer[0], 1, 1, 1, 0);

...
    }


I thought that I had (manually) unlocked and configured the pins correctly, but am I missing something? Something else? Timing and message are just to see if I can get anything to show up on the TX pin and/or transceiver chip.

I got much of the info here:
http://www.ccsinfo.com/forum/viewtopic.php?t=39189

But that didn't seem to have a full resolution.

Thanks for any help!


Last edited by johns_sd on Tue Jan 20, 2015 6:06 pm; edited 1 time in total
dyeatman



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

View user's profile Send private message

PostPosted: Mon Jan 19, 2015 5:51 pm     Reply with quote

Just FYI, as a general rule the #Fuses must always be right after your #device line(s) BEFORE the #use delay() line;

Code:
#include <24HJ64GP504.h>
#device *=16
#device ICD=TRUE

#FUSES HS,NOWDT,NOOSCIO  <***************** goes here

#use delay(clock=20000000, osc) // OSC turns on external oscillator input instead of RC

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



Joined: 19 Jan 2015
Posts: 3

View user's profile Send private message

PostPosted: Mon Jan 19, 2015 5:55 pm     Reply with quote

Thanks. It didn't make a difference, and the other timing-related stuff was working with it out of place. It used to be there (I deleted some commented-out fuses statements), but I moved it for some reason.

The rest of the code was/is working well before adding the CAN stuff.
RF_Developer



Joined: 07 Feb 2011
Posts: 839

View user's profile Send private message

PostPosted: Tue Jan 20, 2015 3:13 am     Reply with quote

The CAN defines - clock and any other stuff - must be BEFORE the include of can-PIC24.c, otherwise the CAN will use default parameters.
johns_sd



Joined: 19 Jan 2015
Posts: 3

View user's profile Send private message

PostPosted: Tue Jan 20, 2015 6:09 pm     Reply with quote

SOLVED: Apparently the CANBUS software was (generally) working, but the program got hung up on another routine due to an apparent switch of the compiler. Has the order in which use statements and other configurations switched from 4.x to 5.x? I had the appropriate I2C code in the body, it just ignored it based on an earlier #include file in 5.x, but worked fine in 4.x.

Thanks all for the suggestions.
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