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

Help me.. about a CAN Communication

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







Help me.. about a CAN Communication
PostPosted: Wed Jan 19, 2005 10:02 am     Reply with quote

Hello.
I was question this.
but still have a problem.

my english is very poor.

i want to use CAN, but CAN is not response.
i try to programming for 4 days, but I do not success
I need your help.


this codes is a initializing CAN "include "can18xxx8.c" and "can18xxx8.h"
i modified some flag for "500Kbps Baudrates"

Code:

void can_init(void) {
   can_set_mode(CAN_OP_CONFIG);   //must be in config mode before params can be set
   can_set_baud();

   RXB0CON=0;
   RXB0CON.rxm=CAN_RX_VALID;
   RXB0CON.rxb0dben=CAN_USE_RX_DOUBLE_BUFFER;
   RXB1CON=RXB0CON;

   CIOCON.endrhi=CAN_ENABLE_DRIVE_HIGH;
   CIOCON.cancap=CAN_ENABLE_CAN_CAPTURE;

   can_set_id(RX0MASK, CAN_MASK_ACCEPT_ALL, 1);  //set mask 0
   can_set_id(RX0FILTER0, 0, 1);  //set filter 0 of mask 0
   can_set_id(RX0FILTER1, 0, 1);  //set filter 1 of mask 0

   can_set_id(RX1MASK, CAN_MASK_ACCEPT_ALL, 1);  //set mask 1
   can_set_id(RX1FILTER2, 0, 1);  //set filter 0 of mask 1
   can_set_id(RX1FILTER3, 0, 1);  //set filter 1 of mask 1
   can_set_id(RX1FILTER4, 0, 1);  //set filter 2 of mask 1
   can_set_id(RX1FILTER5, 0, 1);  //set filter 3 of mask 1

   set_tris_b((*0xF93 & 0xFB ) | 0x08);   //b3 is out, b2 is in

   can_set_mode(CAN_OP_NORMAL);
}

////////////////////////////////////////////////////////////////////////
//
// can_set_baud()
//
// Configures the baud rate control registers.  All the defines here
// are defaulted in the can-18xxx8.h file.  These defaults can, and
// probably should, be overwritten in the main code.
//
// Current defaults are set to work with Microchip's MCP250xxx CAN
// Developers Kit if this PIC is running at 20Mhz.
//
////////////////////////////////////////////////////////////////////////
void can_set_baud(void) {
   BRGCON1.brp=4;                                 //baud rate generator prescalar   def:4
   BRGCON1.sjw=1;                                 //synchronized jump width   def:0

   BRGCON2.prseg=1;                              //propagation time select   def:2
   BRGCON2.seg1ph=3;                              //phase segment 1   def:5
   BRGCON2.sam=0;                                 //sample of the can bus line   def:0
   BRGCON2.seg2phts=TRUE;                        //phase segment 2 time select bit   def:true   (TRUE: freely programmable)

   BRGCON3.seg2ph=3;                              //phase segment 2 time select   def:5
   BRGCON3.wakfil=FALSE;                        //selects can bus line filter for wake up bit   def:false
}

void can_set_mode(CAN_OP_MODE mode) {
   CANCON.reqop=mode;
   while( (CANSTAT.opmode) != mode );
}




this is a main codes
Recieving data and Sending data
Code:

   while(TRUE)
   {
      if ( can_kbhit() )   //if data is waiting in buffer...
      {
         if(can_getd(rx_id, &in_data[0], rx_len, rxstat))
         {
            
         }
      }
      if(ms>2000)
      {
         ms=0;
         can_putd(tx_id, out_data, tx_len,tx_pri,tx_ext,tx_rtr); //put data on transmit buffer
      }
   }



CPU : PIC18F258
OSC : 40Mhz (HS with PLL)


help me, please.
i need a help.
denkid1
Guest







Post.Script.
PostPosted: Wed Jan 19, 2005 10:05 am     Reply with quote

I use the "2Channel PCI CAN Board"
i wanna commnucation "PCI CAN Board <---> PIC"
help me.
Guest








Re: Post.Script.
PostPosted: Wed Jan 19, 2005 10:37 am     Reply with quote

denkid1 wrote:
I use the "2Channel PCI CAN Board"
i wanna commnucation "PCI CAN Board <---> PIC"
help me.


-------- i can't understand --------------------------------------
PIC (PIN_B2/TXD) <--> TXD(PCA82C251)
PIC (PIN_B3/RXD) <--> RXD(PCA82C251)
--------------------------------------------------------------------
set_tris_b((*0xF93 & 0xFB ) | 0x08); //b3 is out, b2 is in
--------------------------------------------------------------------
out is a RXD? .... PIC PIN_B3 is a RXD..
why these difference?

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