We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
This program sends 1 byte sequential numbers to CAN BUS using Channel 12. Interrupt occurs each time message is transferred. When interrupt occurs CANCONCH and CANSTCH registers should be cleared for the next intterrupt. Unfortunatelly clearing CANCONCH and CANSTCH doesnt clear the CANGIT register automatically althoug it should be (From Atmels data book). For this reason Interrupt function is called back for the second time. The only solution i found is to clear CANGIT^7 manually Altough it is imposible to clear this bit in real IC (CANGIT^7 is readonly bit) but keil software does? What do you suggest to overcome this problem. is this a bug or am i doing something wrong? Thanks for all
#include <Can1_Drv.h> #include <reg51cc01.h> static bit SendInfo; unsigned char i; void CanInterrupt (void) interrupt 7 using 1 { SendInfo = 0; //Init for nex message to send CANCONCH = 0; //reset Launch Transmission CANSTCH = 0; //reset TxOk //CANGIT = 0; } void CanSend () { unsigned char num_data; CANMSG = i++; for (num_data = 1; num_data<8; num_data++) { CANMSG = 0x00; } CANCONCH = 0x51; //Send 1 byte msg. id29 SendInfo = 1; //Message is being sent } void main (void) { CanInit (); EA = 1; // Enable All Interrupts (IEN0^7) ECAN = 1; // Enable CAN Interrupts (IEN1^1) CANGIE = 0x10; // En. Transmit Int.CANGIE^4) CANIE1 = 0x10; // Enable M.O. Int.(CANIE1^4) SendInfo = 0; // Msg hasn't been sent yet CANPAGE = CanChannel(12);// Use Channel 12 CANSTCH = 0x00; CanSetIDT(ID0); while (1) { if (!SendInfo) // Wait until message is send { CanSend (); } } }
Hi, Unfortunately, I don't seen a can driver you have used. Anyway, here are some suggestions. 1) Unfortunatelly clearing CANCONCH and CANSTCH doesnt clear the CANGIT register automatically althoug it should be (From Atmels data book). Sorry? Datasheet I have, talks me that all the bits of CANGIT are resetable by user. There is an example in the same databook which shows how produce interrupt routine. It says: if it is not a channel interrupt ... clear CANGIT register 2) I suggest you to check interrupt event especialy for CAN Timer Overflow - OVRTIM bit. 3)Altough it is imposible to clear this bit in real IC (CANGIT^7 is readonly bit) Probably it is simulator error; anyway you may do CANGIT &= 0x80; to clear bits of this register. Good days!