MSCAN driver problems

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

MSCAN driver problems

2,189 Views
Morrison
Contributor I

Hi,


I'm working with MCF51AC microcontroller, and I found some problems when I tried to use the MSCAN drivers.

 

The interrupts (CAN_TransmitISR, CAN_ReceiveISR, CAN_WakeupISR) aren't executed.

 

I found an error in the function "CAN_QueueMB", when the transmitted interrupt flag is setting on (CANTFLG register):

if (MB_MSCAN[0] == 0xff)  {
   ......
   ......  
   CANTFLG = 0x01;
   ......
   }

This is wrong, the interrupt flag enable when TX buffer 0 is full (loaded with a message due for transmission ) is:
CANTFLG = 0x06;

 

If I change the register value, the CAN_TransmitISR is executed, but the transmission is not correct. I'll have to find the problem :-(( .


Also, I have problems with receiver canbus data, the data fills the bufferCANRX (@ffff989f) and seems to be OK, but the tx interrupt isn't executed (the address filter is all FF)

 

this is my MSCAN test code:

UINT8 data[] = {8,0,0,7,0,0,4,0,1};
UINT8  status[2];

 

MCU_init();
Config_ports();
EnableInterrupts; /* enable interrupts */
    
CAN_Init(FAST);
CAN_ConfigMB (1,  TXDF, 1);
CAN_ConfigMB (0,  RXDF, 0);

///receive data
/*do{
  (void)CAN_CheckStatusMB( 0, status );
  }while ( status[0] != NEWDATA);
  CAN_ReadDataMB(0,data );
 */


/// transmit data
CAN_LoadMB(1, data);
CAN_TransmitMB(1) ;
do{
  (void)CAN_CheckStatusMB(1, status);
 } while(status[0] != TRANSMITTED);

 

 

Morrison.
 

Message Edited by Morrison on 2009-02-23 03:10 PM
Labels (1)
0 Kudos
8 Replies

699 Views
kef
Specialist I

CANTFLG = 1; will clear CANTFLG bit 0 and shedule TX buffer 0 for transmission

 

CANTFLG = 6; will clear CANTFLG bits 1 and 2 and shedule TX buffers 1 and 2 for transmission

 

If you are using some ready to use software driver, the you should name it properly. Others may have no idea what driver you are using.

0 Kudos

699 Views
Morrison
Contributor I

I'm sorry,..., we are talking about the MSCAN driver, and MCF51AC256 microcontroller 

 

I was lost when I spoke about a mistake in the MSCAN code, ... when you write 1 in CANTFLG, clears flag, and when you write 0 is ignored.

 

 

When I try to sent or receive a message, ISR's aren't executed because CAN controller doesn't put the flags in CANRFLG and CANTFLG registers, for example, when I try to receive data, the RX CAN buffer fills up with the correct identifier, data, timestamp, but the CAN RX flag in the CANRFLG register stills to 0, and, of course, the receive ISR isn't executed, Why????

 

 

 

 

 

 

0 Kudos

699 Views
kef
Specialist I
Is acceptance filters setup OK? RXF flag is set only when received message passes through one of acceptance filters.
0 Kudos

699 Views
Morrison
Contributor I

Thank's for your help.....

Aceptance filters are setup to "FF".

define ID_CODE0_CAN 0xFF

....

define ID_CODE7_CAN 0xFF

define ID_MASK0_CAN 0xFF

....

define ID_MASK7_CAN 0xFF

I tried to configure the loopback selt test mode in CANCTR1 register, and it works correctly, I can transmit and receicer my own messages, but when I try to receive or transmit a external message to another can bus node, fails.

I captured with a scope the TXcan and RXcan data frame's, and seems to be ok .

I'm using a usb-canbus interface (www.canusb.com) to test the canbus controller of MCF51AC256, but I supose that it can't be a problem.

0 Kudos

699 Views
TomE
Specialist II

That's a long time (nearly 6 years) between your initial questions and these latest ones.

> Aceptance [sic] filters are setup to "FF".

Have you set up CANIDAC properly? I guess if you're receiving Loopback frames then you probably have the filters set up OK. The Reference Manual implies the filters have to be set up for loopback to work.

> but when I try to receive or transmit a external message to another can bus node, fails.

You should be getting received data or you should be getting errors. Put some code in there to indicate what errors you're getting and that may point to your problem. You should also check the other end (usb-canbus interface) to see if it is reporting errors on packets you're sending from MSCAN.

> I captured with a scope the TXcan and RXcan data frame's, and seems to be ok .

Check them again. You've probably got a mismatch between the bit-rate on the MSCAN controller and what you've programmed the USB-CAN device to. Send some packets from the USB-CAN device and monitor them on the Oscilloscope - compare the bit period with the ones the MSCAN device is generating. That should show any problem with this part.

Tom

0 Kudos

699 Views
Morrison
Contributor I

more news,

 

when I configure the Listen only mode in CANCRL1 register, I can receive a external CANbus message,  :smileyhappy: but, of course, I can't transmit nothing  :smileysad:

0 Kudos

699 Views
Morrison
Contributor I

and finally,

 

#define PROP_SEG_CAN   11
#define PHASE_SEG1_CAN 2
#define PHASE_SEG2_CAN 2

 

 It works :smileyhappy:

 

before I did this change I used:

#define PROP_SEG_CAN   7

#define PHASE_SEG1_CAN 4

#define PHASE_SEG2_CAN 4

 

 

 

0 Kudos

699 Views
flameman
Contributor I

could you post a bit of code ?

i am working with that chips and i have a lot of issue

0 Kudos