MSCAN Problem

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

MSCAN Problem

3,217 次查看
sebasira
Senior Contributor I
Hello! I've downloaded the MCF51JM msCAN Driver from Freescale's website, but I cant get it to work in the DEMOJM board with the JM128 daugther card.

Jumper Selection for the Board as the default in the DEMOJM User Manual:
- CAN to work at high speed
- Rx and Tx enable
- CAN Enable

I'm going to develope a new application with CAN but I can't make it work!

I manage to config a Message Buffer, with "CAN_ConfigMB", then I load the data with "CAN_LoadMB" and then I transmit it with "CAN_TransmitMB", but then I check the status of the sent messsage buffer and it's QUEUED2 wich means that the data has been copied to a CAN buffer but the transmission was never completed!

Here's the code I use:

  Init_MCG();                           // Clock initialization
 
  Init_LED();                           // LED initialization
 
  Init_Button();                        // Button initialization
 
  EnableInterrupts;                 // Enable Interruptes
 
 
  CAN_Init(FAST);                 // MSCAN Fast Initialization



  for(;:smileywink: {
    __RESET_WATCHDOG();                 // Feed the DOG
   
      ERROR_CODE = CAN_ConfigMB(1,TXDF,1);
   
      DATA_BUFFER[0] = 3;                  // Data Length Code
      DATA_BUFFER[1] = 0x17;            // Data 1
      DATA_BUFFER[2] = 0x05;            // Data 2
      DATA_BUFFER[3] = 0x85;            // Data 3
     
      ERROR_CODE = CAN_LoadMB(1,DATA_BUFFER);   
     
      ERROR_CODE = CAN_TransmitMB(1);
     
      while ( status[0] != TRANSMITTED){
        __RESET_WATCHDOG();             // Feed the DOG
        ERROR_CODE = CAN_CheckStatusMB(1, status );
      }
    
      ERROR_CODE = 0;     <--------- I place a BREAKPOINT HERE and it never reach it!!!
}

That's part of the code (in fact, I don't do that in the LOOP, I do it if a button is pressed, but I deleted
that part so the code was simpler)

In every sentece ERROR_CODE = ERR_OK so no error has ocurrer but the it gets stuck in the while loop
because the status freezes on QUEUED2

How can I solve that?

I also try the sample code that comes with the MCF51JM msCAN Driver, and it gets stuck in the same part with the same status value.

I forget the CAN Registers values:
CANCTL0 = 0x14
CANCTL1 = 0x84
CANBTR0 = 0xC7
CANBTR1 = 0xC5
CANIDAC = 0x00

Any help is appreciated!! Thanks in advance!

PS: Here you can find the MCF51JM msCAN Driver: https://www.freescale.com/webapp/Download?colCode=MSCAN_MCF51JM&appType=license&location=null&fsrch=...
When you extract the ZIP file, under the folder "man" you'll find the manul for this driver

标签 (1)
0 项奖励
回复
7 回复数

1,753 次查看
sebasira
Senior Contributor I
I've got some news... Well the problem seems to be that the CAN_TransmitISR is never executed... I placed a breakpoint inside it and the program never gets to it.

Then looking to the vector table definition I found an error, it also seems to be a big one...

Please take a look at the attached image.

According to the Referece Manual (MCF51JM128) CAN Tx Interrupt is at address 0x18C and it is vector number 99.

But in the file MCF51JM128.c (library from Freescale) the address is 0x184 and in exceptions.c (from CodeWarrior v6.1) the vector number is 97...

What's going on here?

PS:  Maybe this error is already corrected, but I don't know where is the error. Is it in the Reference Manual or in the Libraries?


Message Edited by sebasira on 2009-02-11 03:18 AM
0 项奖励
回复

1,754 次查看
sebasira
Senior Contributor I
My head is absolutely messed-up but I think I solve the problem. The correct values for the CAN Tx Interrupt were:

Address = 0x184
Vector Number = 97

I make it work in my coustom application, with loopback enable. But I still can't get the msCAN Driver Sample Project to work.

Anyway I don't fully understand how to work with the msCAN module, I thougth it would be easier, so maybe you'll get some news from me. In fact it would be a cry for help!! LOL

Thanks anyway, and I'll appreciatte any information or correction you can make to me.

SebaS
0 项奖励
回复

1,754 次查看
David_UCT
Contributor III

HI Sebasira

 

Did you ever manage to get this code to work.  I'm working on getting it to work at the moment as well.

 

I get the same issue, the transmit method returns ERR_QED or error the message is queued.  However I have found that the performance is sporadic so the first message I send will transmit onto the bus and I can see it on a scope and then on the next transmit I will get ERR_QED.  This however could be because I'm not getting an acknowledgement message back which could mean the issue is a bit timing issue.

0 项奖励
回复

1,754 次查看
sebasira
Senior Contributor I

Hi David!

 

Well, I actually quit this project years ago... But the last test I performed, worked just fine... if you want I can look-up for the code I finally used. It was very simple, just some test, I've never pass that stage because I get involved in another work.

 

I never get that error or any error. But I also never test the communication with other hardware, just the inside loop-back. If you check the control registers, you'll find a bit to set it up.

 

So I send and receive whatever I've sent. I tested the address bits and masks in order see if it was really working and it was.

 

Maybe the code can help. I'll look for it and post it here.

 

Best Regards!

0 项奖励
回复

1,754 次查看
David_UCT
Contributor III

Hi

 

Thanks for the response, my code also works using loopback mode it just refuses to work in transmission to other nodes.  I'm going to fiddle with the bit time this afternoon and see if the battle can be won there.

0 项奖励
回复

1,754 次查看
sebasira
Senior Contributor I

Ohh!

 

Sorry I can no loger assist you... That's as far as I went... Hope you can solve it!!!

0 项奖励
回复

1,754 次查看
David_UCT
Contributor III

The reason the ISR is never executed in this driver is that the ISR routine is not given a vector number.

 

they have written it as interrupt void CAN_transmitISR

 

insteaed of interrupt 97 void CAN_transmitISR

 

or at least that was the case with the version of the mscan driver from freescale that I used.

0 项奖励
回复