FlexCan strange behaviour

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

FlexCan strange behaviour

2,465件の閲覧回数
Simone
Contributor II
Hello!
I'm working on a FlexCan application on the MCF52235. Everything works well, until I have at least two devices connected on the bus. Today I discovered that there is a problem when I left the board with the micro unconnected. The program stucks at this instruction:
Code:
while( (MCF_CAN_ERRSTAT & MCF_CAN_ERRSTAT_IDLE)==0 );

 

 

The complete code for sending routine is the following:
Code:
void CANSendData(int i, int ID, int length, int *data, int ide ){ //Attendi che il bus sia idlewhile( (MCF_CAN_ERRSTAT & MCF_CAN_ERRSTAT_IDLE)==0 );MCF_CAN_MBUF_CODE(i) = MCF_CAN_TX_INACTIVE; //MBi is inactive while( (MCF_CAN_ERRSTAT &    (MCF_CAN_ERRSTAT_TXRX + MCF_CAN_ERRSTAT_IDLE))       == MCF_CAN_ERRSTAT_TXRX);    // Configure IDMCF_CAN_MBUF_ID(i) = ID;  // Copy Tx data bytes to the message bufferCANLoadBufferData(i, length, data);      if(ide){ MCF_CAN_MBUF_CTRL(i) = 0x40 + 0x20 + length; }else { MCF_CAN_MBUF_CTRL(i) = length; }MCF_CAN_MBUF_CODE(i) = MCF_CAN_TX_TRONCE;}

 I thought that the bus never goes "idle" if the micro is not connected; so I removed the two while loop, and the program started to work correctly even when unconnected (or at least, doesn't stuck in the loop).
 
I'm still quite uncertain about the usefulness of these while loops...but I was adviced to put them in the code to be sure that the buffer was deactivated.
Does anybody  find a similar problem?
 
Simone

 

ラベル(1)
0 件の賞賛
返信
2 返答(返信)

902件の閲覧回数
Nouchi
Senior Contributor II
hello,

You should have a look to RXECTR and ERRSTAT registers, maybe the FLEXCAN is in bus off state, because if the cpu core is halted, messages buffers aren't serviced anymore.


Emmanuel,
0 件の賞賛
返信

902件の閲覧回数
Simone
Contributor II
Hello Emmanuel!
I think that FlexCan is in bus-off state when disconnected; infact when I reconnect it again it exits the loops and works.
The problem is that the cpu remains stuck in the while loop (waiting for the bus to go idle), preventing the rest of the program to run when the board is disconnected from the can bus. I tried removing the loops, and it still seems to work, but I'm afraid that there will be strange behaviours in future (maybe with more device connected on the bus, trying to send two or more message at the same time).
If I remove the loops, the only problem is that I can lost messages, or there is something else?
 
Simone
0 件の賞賛
返信