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 reception problem

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



Joined: 19 Jul 2006
Posts: 5

View user's profile Send private message

CAN reception problem
PostPosted: Mon Jul 24, 2006 10:01 am     Reply with quote

Hi everybody, i'm working on a CAN network and i'm blocked by a reception problem.

In fact, i receive only 9 messages as shown in the HyperTerminal:

CAN_GETD(): BUFF=0 ID=18FEBD00 LEN=8 OVF=1 FILT=0 RTR=0 EXT=1 INV=1
DATA = 00 00 A8 8D 00 00 00 00
$
CAN_GETD(): BUFF=0 ID=18FEF100 LEN=8 OVF=1 FILT=0 RTR=0 EXT=1 INV=1
DATA = 00 58 92 00 00 00 00 00

CAN_GETD(): BUFF=0 ID=18FEF100 LEN=8 OVF=1 FILT=0 RTR=0 EXT=1 INV=0
DATA = 00 8C 9A 00 00 00 00 00

CAN_GETD(): BUFF=0 ID=18FEF100 LEN=8 OVF=0 FILT=0 RTR=0 EXT=1 INV=0
DATA = 00 F0 9A 00 00 00 00 00

CAN_GETD(): BUFF=0 ID=18FEBD00 LEN=8 OVF=1 FILT=0 RTR=0 EXT=1 INV=0
DATA = 00 00 54 9B 00 00 00 00
$b
CAN_GETD(): BUFF=0 ID=18FEF100 LEN=8 OVF=1 FILT=0 RTR=0 EXT=1 INV=0
DATA = 00 54 9B 00 00 00 00 00

CAN_GETD(): BUFF=0 ID=18FEF100 LEN=8 OVF=0 FILT=0 RTR=0 EXT=1 INV=0
DATA = 00 B8 9B 00 00 00 00 00

CAN_GETD(): BUFF=0 ID=18FEBD00 LEN=8 OVF=1 FILT=0 RTR=0 EXT=1 INV=0
DATA = 00 00 1C 9C 00 00 00 00
$
CAN_GETD(): BUFF=0 ID=18FEF100 LEN=8 OVF=1 FILT=0 RTR=0 EXT=1 INV=0
DATA = 00 1C 9C 00 00 00 00 00


After, when i test with if(can_kbhit()) , the result is wrong

But Messages are sent in a loop, so, i should always receive these messages!

I am completly disappointed because yesterday it worked, but today, i don't know what i have changed but it doesnt work Confused

Here is my main code:

#include <16F628>
#use delay(clock=8000000)
#fuses HS,NOPROTECT,NOLVP,NOWDT,NOBROWNOUT
#use rs232(baud=9600, xmit=PIN_B6, rcv=PIN_B7)
#include "includes/CANmcp2515.c"
#define FAN 0xFEBD
#define ENGINE_TEMPERATURE 0xFEEE
#define CRUISE_CONTROL 0xFEF1

int16 get_Message(int *pbuffer) {
int16 message;
message = (int16)(pbuffer[1] + (pbuffer[0]<<8>> 8) ) {
case FAN:
printf("$");
printf(get_FanSpeed(&buffer_rx[0]));
printf("\r");
break;
}
}
}

void main() {

// On programme les registres du MCP2515
can_init();
printf("Demarrage\r\n");

// On entre dans la boucle principale
while(TRUE) {
if ( can_kbhit() ) {
traitement_message();
} else {
printf("$NoWo\r\n");
}
delay_ms(10);
}
}


Here is the code of my CanInit()

//IO pins connected to MCP2510
#ifndef EXT_CAN_CS
#define EXT_CAN_CS PIN_A0
#define EXT_CAN_SI PIN_A2
#define EXT_CAN_SO PIN_A1
#define EXT_CAN_SCK PIN_A3
#define EXT_CAN_INT PIN_B0
#define EXT_CAN_RX0BF PIN_B1
#define EXT_CAN_RX1BF PIN_B2
#define EXT_CAN_TX2RTS PIN_B3
#define EXT_CAN_TX1RTS PIN_B4
#define EXT_CAN_TX0RTS PIN_B5
#endif

void can_init(void) {
struct struct_RXB0CTRL new_rxbnctrl;
struct struct_BFPCTRL new_BFPCtrl;
struct struct_CANINTE new_CANINTE;
struct struct_TXRTSCTRL new_TX_RTS_CTRL;
char string[5]; // A effacer : test

mcp2510_init();

can_set_mode(CAN_OP_CONFIG); //must be in config mode before params can be set

delay_ms(100);
while((mcp2510_read(CANSTAT) & 0xE0) != 0x80){
can_set_mode(CAN_OP_CONFIG);
}

//Configuration du baudrate, CNF1,CNF2,CNF3
can_set_baud();

// Configuration des registres de controle TXB0CTRL, TXB1CTRL, TXB2CTRL
new_TX_RTS_CTRL.B0RTSM = 1;
new_TX_RTS_CTRL.B1RTSM = 1;
new_TX_RTS_CTRL.B2RTSM = 1;
new_TX_RTS_CTRL.B0RTS = 0;
new_TX_RTS_CTRL.B1RTS = 0;
new_TX_RTS_CTRL.B2RTS = 0;
mcp2510_write(TXRTSCTRL, (int)new_TX_RTS_CTRL);

// Configuration des registres de controle RX0CTRL et RX1CTRL
new_rxbnctrl=0;
new_rxbnctrl.rxm=CAN_RX_VALID;
new_rxbnctrl.bukt=CAN_USE_RX_DOUBLE_BUFFER;
mcp2510_write(RXB0CTRL, (int)new_rxbnctrl);
mcp2510_write(RXB1CTRL, (int)new_rxbnctrl);

// Configuration des interruptions
new_CANINTE.rx0ie = 1; //Interruption du buffer de r�ception 0
new_CANINTE.rx1ie = 1; //Interruption du buffer de r�ception 1
new_CANINTE.tx0ie = 0; //transmit buffer 0 empty interrupt enable
new_CANINTE.tx1ie = 0; //transmit buffer 1 empty interrupt enable
new_CANINTE.tx2ie = 0; //transmit buffer 2 empty interrupt enable
new_CANINTE.errie = 0; //error interrupt enable
new_CANINTE.wakie = 0; //wakeup interrupt enable
new_CANINTE.merre = 0; //message error interrupt enable
mcp2510_write(CANINTE, (int)new_CANINTE);

//Configuration des RXnBF Pins
new_BFPCtrl.b0bfm = 0; //1=pin is interrupt when message loaded into rxb0, 0=digital
new_BFPCtrl.b1bfm = 0; //1=pin is interrupt when message loaded into rxb1, 0=digital
new_BFPCtrl.b0bfe = 0; //rx0bf pin function enable
new_BFPCtrl.b1bfe = 0; //rx1bf pin function enable
new_BFPCtrl.b0bfs = 0; //rx0bf pin state
new_BFPCtrl.b1bfs = 0; //rx1bf pin state
mcp2510_write(BFPCtrl, (int)new_BFPCtrl);

//if you want to configure the TXnRTS pins, do it here. default is off

// 1er Buffer
can_set_id(RX0MASK,0x00FFFF00,TRUE);
can_set_id(RX0FILTER0,0xFEBD00,TRUE);
can_set_id(RX0FILTER1,0xFEBD00,TRUE);
// 2eme Buffer
can_set_id(RX1MASK,0x00FFFF00,TRUE);
can_set_id(RX1FILTER2,0xFEEE00,TRUE);
can_set_id(RX1FILTER3,0xFEEE00,TRUE);
can_set_id(RX1FILTER4,0xFEF100,TRUE);
can_set_id(RX1FILTER5,0xFEF100,TRUE);

delay_ms(1000);

while((mcp2510_read(CANSTAT) & 0xE0) != 0x00){
can_set_mode(CAN_OP_NORMAL);
}

}


Thanks for your help...
iso9001



Joined: 02 Dec 2003
Posts: 262

View user's profile Send private message

PostPosted: Mon Jul 24, 2006 10:27 am     Reply with quote

I would lay off from printing every 10ms that you don't have a can message. Seems pointless to tell you that nothing is happening.

Putting you code is [ code ] brackets makes it easier to read.

I am assuming you took the ccs driver and modified it to make "CANmcp2515.c" correct ? Has kbhit() ever worked correctly ? I'm thinking maybe you just renamed the file since you still call mcp2510_init();

Are you using software SPI ? If you are I can recommend against it, you have a hardware SPI module that is faster and doesn't delay the chip so much, you might want to use it.

I sent you a PM about some other stuff,

You should post some details about the termination you are using and if you are certain the other module is sending correctly. Is the other module reporting errors (ie: it is sending but getting no acks) ?
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