Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Error in cane protocol communication

Status
Not open for further replies.

jaga123

Member level 1
Member level 1
Joined
May 16, 2011
Messages
32
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,288
Location
india
Activity points
1,533
Error in can protocol communication

i am using mcp 2515 in can communication
in transmission i am getting some problem. my data has not transmitted properly.. i thnik there must some error.. i have no analyzer to see.. so is there any alternative way to check error which found in tx as well as reception
.. please help me out.



with regards,
jaga123
 
Last edited:

Re: Error in can protocol communication

is your baud rate etc correct?
if you have an oscilloscope you can check it
 

Re: Error in can protocol communication

yes sir
i have select correct baud rate. but in my transmission i get error.. but i can't be sure which error it is?
how should i do?
 

Re: Error in can protocol communication

yes sir
i have select correct baud rate. but in my transmission i get error.. but i can't be sure which error it is?
how should i do?
have you set up the other CAN parameters correctly
e.g. initialisation
Code:
/*********************************************************************
 * Function:        void CANEnable(int Channel, int BusSpeed )
 *
 * PreCondition:    SPI port configured, CANReset is called, and RXB 
 *					Filters intitialized.
 *
 * Input:			Channel: SPI channel number, 1 based
 *					BusSpeed: Bus Speed code: CAN_500kbps
 *							CAN_250kbps, or CAN_125kbps
 *                  mode    1 = REQOP_NORMAL else REQOP_LOOPBACK
 *
 * Output:          None
 *
 * Side Effects:    None
 *
 * Overview:		Sets the CAN bus speed and turns on the CAN controller.
 *
 * Note:            None.
 ********************************************************************/
void CANEnable( int Channel, int BusSpeed, int mode )
{
	//Set CNF1
	CAN2515ByteWrite(Channel, CNF1, BusSpeed); 
	
	//Set CNF2
//	CAN2515ByteWrite(Channel, CNF2,0x80 | PHSEG1_3TQ | PRSEG_1TQ);
	CAN2515ByteWrite(Channel, CNF2,0x80 | PHSEG1_3TQ | PRSEG_3TQ);
	
	//Set CNF3
	CAN2515ByteWrite(Channel, CNF3, PHSEG2_3TQ);
	
	//Interrupt on RXB0 - CANINTE
	CAN2515ByteWrite(Channel, CANINTE,0x01); // Interrupts are on
	
    if(mode)
       {
  	    //Set NORMAL mode
    	CAN2515ByteWrite(Channel, CANCTRL,REQOP_NORMAL | CLKOUT_ENABLED);

	    CAN2515ByteRead(Channel, CANSTAT); //dummy read to give 2515 time to switch to normal mode
	
	    if( (CAN2515ByteRead(Channel, CANSTAT) & 0xE0) != OPMODE_NORMAL )
	  	    CAN2515ByteWrite(Channel, CANCTRL,REQOP_NORMAL | CLKOUT_ENABLED);
        else
            xprintf("\nCAN enabled normal mode \n");
       }
    else
       {
	    CAN2515ByteWrite(Channel, CANCTRL,REQOP_LOOPBACK | CLKOUT_ENABLED);
	    CAN2515ByteRead(Channel, CANSTAT); //dummy read to give 2515 time to switch to normal mode
	    if( (CAN2515ByteRead(Channel, CANSTAT) & 0xE0) != REQOP_LOOPBACK )
            {
            printf("CAN setting loopback mode failed - try again\n");
	   	    CAN2515ByteWrite(Channel, CANCTRL, REQOP_LOOPBACK | CLKOUT_ENABLED);
            }
        else
            xprintf("CAN enabled loop back mode \n");
       }
}

also set up standard or extended addresses and the filters and masks etc

it is also worth using loop back mode to check that SPI communication etc is working OK


I find that a CAN USB device is useful for debugging CAN systems if one does not have a full protocol analyser, e.g.
http://www.can232.com/canusb/
 
Last edited:

Re: Error in can protocol communication

thanks sir for your reply..
yes i have initialize can controller correctly..
i think i can use loop back mode to check error..


one doubt is there ..
sir can u tell me what happen if one node is sending a data to two other node with same id than what happen ?
 

Re: Error in can protocol communication

thanks sir for your reply..

one doubt is there ..
sir can u tell me what happen if one node is sending a data to two other node with same id than what happen ?

CAN is a broadcast network (not point to point like TCP/IP where each node has a unique ID)
nodes don't have IDs - all nodes receive the broadcast and depending upon the mask and filters accept or reject it, e.g. consider a car where a command to switch on the lights will be acted on by several controllers
a controller can accept many message IDs, e.g. a car lights controller could accept messages to switch on side lights, break lights, head lights, etc all with unique IDs
 

Re: Error in can protocol communication

yes it true that CAN is a broadcast message and transmitted message can be shown by each other node.
but if ii set same mask and filter in two node (knowingly) than if i transmit a message to these node which will receive message and how?
 

Re: Error in can protocol communication

yes it true that CAN is a broadcast message and transmitted message can be shown by each other node.
but if ii set same mask and filter in two node (knowingly) than if i transmit a message to these node which will receive message and how?

if the masks and filters in the nodes are set to receive the ID both (or more) nodes can read and accept the same message
 

Re: Error in can protocol communication

thank u sir,
u clear my doubt..

can u tell me on which logic arbitration field is working in CAN?
 


Re: Error in can protocol communication

actually i got this question. that on which logic the arbitration of CAN worked.. i know that CAN IS WORKING ON WIRE AND LOGIC . i am quite confused, so please suggest me the right answer
 

Re: Error in can protocol communication

actually i got this question. that on which logic the arbitration of CAN worked.. i know that CAN IS WORKING ON WIRE AND LOGIC . i am quite confused, so please suggest me the right answer

are you thinking of the how the high priority messages win over the low priority?
when a message ID is transmitted a low bit wins over a high bit
for example, say two nodes start to transmit node A with ID 01100000001 and node B with ID 01000000000
1. both transmit 0
2. both transmit 1
3. node A transmits 1 and node B transmits 0 - the 0 wins and A stops transmitting and B goes on the transmit the rest of the ID etc

therefore many nodes may start to transmit but the one with the highest priority wins - the others stop, e.g. a command in car to put on the breaks will be higher priority than the commands to wind a window down

there is a nice animation in
https://www.can-cia.org/index.php?id=systemdesign-can-protocol
 

Re: Error in can protocol communication

are you thinking of the how the high priority messages win over the low priority?
when a message ID is transmitted a low bit wins over a high bit
for example, say two nodes start to transmit node A with ID 01100000001 and node B with ID 01000000000
1. both transmit 0
2. both transmit 1
3. node A transmits 1 and node B transmits 0 - the 0 wins and A stops transmitting and B goes on the transmit the rest of the ID etc

therefore many nodes may start to transmit but the one with the highest priority wins - the others stop, e.g. a command in car to put on the breaks will be higher priority than the commands to wind a window down

there is a nice animation in
https://www.can-cia.org/index.php?id=systemdesign-can-protocol

thank you sir for your reply.
this above part is all about arbitration.
i have confused in one point in arbitration, i.e bit error is not consider in arbitration field, but when bit error has occurred during data field than which error will count means the TEC will increased due to bit error or crc error , any thing else?

please enlightening this..
thank you..
 

Transmitter listen the meassage which is transmitting so when then there is bit error then transmitter itself will generate the error.

- - - Updated - - -

and CRC error will generate when whole meassage get transmit.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top