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

RB0 Interrupt for CANBus between 16f628 and mcp2515

 
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

RB0 Interrupt for CANBus between 16f628 and mcp2515
PostPosted: Fri Jul 21, 2006 12:13 am     Reply with quote

Hi everybody,

I'm trying to configure an RB0 interrupt to detect the INT/ of MCP2515 when there are messages in the buffers. Howevern it didn't work...

Here is my source code:
#include <16F628>
#use delay(clock=8000000)
#fuses HS,NOPROTECT,NOLVP,NOWDT,NOBROWNOUT
#use rs232(baud=9600, xmit=PIN_B6, rcv=PIN_B7)
#define ORANGE_LED PIN_B4
#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("Fan Speed, ");
printf(get_FanSpeed(&buffer_rx[0]));
break;
}
}
}

#int_ext
void PORTB0_isr(void) {
struct struct_CANINTF New_CANINTF;

// Si détection d'un nouveau message
while ( can_kbhit() ) {
output_high(ORANGE_LED);
// On traite le message et envoie les infos du message au PC
traitement_message();
// On eteind la LED verte pour indiquer la détection d'un message
output_low(ORANGE_LED);
}
New_CANINTF = 0;
mcp2510_write(CANINTF, (int)New_CANINTF);
}

void main() {
// Activation et configuration des interruptions
ext_int_edge(h_to_l);
enable_interrupts(global);
enable_interrupts(int_ext);

// Désactiver ce qui ne sert à rien!
SETUP_CCP1(CCP_OFF);
setup_comparator(NC_NC_NC_NC);
setup_vref(VREF_HIGH);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_DISABLED);

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

// On entre dans la boucle principale
while(TRUE) {
printf("rien!");
}
}


Here is the code of my MCP2515.c to configure its interruptions:
b_rxb0ctrl=0;
b_rxb0ctrl.rxm=CAN_RX_VALID;
b_rxb0ctrl.bukt=CAN_USE_RX_DOUBLE_BUFFER;
mcp2510_write(RXB0CTRL, (int)b_rxb0ctrl);
mcp2510_write(RXB1CTRL, (int)b_rxb0ctrl);

// 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 embty interrupt enable
new_CANINTE.tx1ie = 0; //transmit buffer 1 embty interrupt enable
new_CANINTE.tx2ie = 0; //transmit buffer 2 embty 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);


In fact, I put a LED on RB0 and I discovered that the interruption appears once and that's all, RB0 never goes back to high level.

If you have any ideas, in fact i've tried to clear by myself the flags of the interruption(New_CANINTF = 0; mcp2510_write(CANINTF, (int)new_CANINTF)););but it seems that it didn't work!

Thanks for your help!
iso9001



Joined: 02 Dec 2003
Posts: 262

View user's profile Send private message

PostPosted: Fri Jul 21, 2006 12:33 pm     Reply with quote

Shouldn't it be


enable_interrupts(int_ext);

THEN

enable_interrupts(global);

?? I don't actually remember if this matters or not.


I'm pretty sure you should be able to clear the 2515's int register by SPI, but I have not checked this out.

Are you using CCS's 2510 driver that you modified or did you write your own?

From my own expereince they are pretty reliable once you figure out the odd parts, so I'm sure its something easy.

Personally, I just poll the RXSTAT register all the time. Its slower then just having the INT pin go low, but I think its still faster then an interupt that tells you a message has occured but doesn't tell which buffer, so you need to ask over spi the status of the two buffers anyway.

Using the RXINT pins would be better if you are concerned with speed.
iso9001



Joined: 02 Dec 2003
Posts: 262

View user's profile Send private message

PostPosted: Fri Jul 21, 2006 3:34 pm     Reply with quote

I looked at the datasheet today,

The CANINTF flag is writable by the host but it you are trying to write while there are still interupts they might just set themselves again (like an error interupt), is this node hooked upto an active can bus while you are doing all this ?

I would not use the INT pin on the 2515. It mainly for error detection, waking, then tx buffers... THEN it has the option to enable ints for rx buffers. You will still have to poll the registers every time you get any int.

For what you are trying to do (get an interupt on a message receive) I would use the RXBxBF pins. If you have two pins available you can just poll them in the kbhit(), they will be active high when you have a message. If you don't have two pins to spare (I don't think you can just tie them together and use 1 pic pin)

Then you could just poll the RXSTAT registers all the time. That way when you get a hit you already know which buffer to read, and you don't waste any pins of the pic, no interupts, ect.
kedale



Joined: 19 Jul 2006
Posts: 5

View user's profile Send private message

PostPosted: Mon Jul 24, 2006 12:48 am     Reply with quote

Thanks a lot for these answers, Its true that the use of RX0BF and RX1BF seems more...smart! Smile

More, i win a pin in my hardware configuration!

I couldn' solve the problem of INT\ but now I have a new solution Wink thanks a lot!
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