cancel
Showing results for 
Search instead for 
Did you mean: 

Cant get CAN module working

ben2
Associate II
Posted on January 13, 2005 at 08:52

Cant get CAN module working

2 REPLIES 2
ben2
Associate II
Posted on January 12, 2005 at 08:48

Hi All

I am having trouble getting the CAN module to work.

By using the following code to initialise the module in loop back mode I can see transmitted messages correctly using a can bus monitor.

Also a receive interrupt gets generated each time I transmit a message.

void Can_Init(void)

{

GPIO_Config(GPIO1,(1<

GPIO_Config(GPIO1,(1<

CAN->CR = CAN_CR_CCE | CAN_CR_INIT | CAN_CR_TEST;

CAN->TESTR=0x0010; // set loopback mode to test

CAN->SR = 0; // reset the status

CAN->BRPR = 0;

CAN->BTR=0x34d7; // 100kbits @ 24Mhz clk

CAN_InvalidateAllMsgObj();

SetMessageObjects(); // set message object 1 to transmit and 2- 32 as receive fifo

CAN->CR = CAN_CR_IE | CAN_CR_TEST ;

}

Because it works fine in loop back mode I assume I have the message objects setup correctly.

Now when I set

CAN->TESTR=0x0000;

and

CAN->CR = CAN_CR_IE;

at the end of Can_Init(). After I do this

I no longer see CAN messages externally.

I dont get a receive interrupt if I send CAN messages to the board.

I dont get a ''message transmitted ok'' in the CAN_SR register

The CAN_TRnR register has the correct bit set to indicate I have requested a transmit.

The CAN_NDnR register has the corresponding bit cleared, even though I set it in the transmit. Is it cleared by the CAN module ?

The CAN_MVnR register has the correct bit to indicate the message object is valid.

I am confused as to why I can get CAN messages in test mode with loop back enabled but as soon as I

come out of test mode nothing appears to work.

Also if I stay in test mode but dont enable loop back (CAN_TESTR = 0) I still get no CAN externally even though from the data sheet I would expect some as bits 5 & 6 indicate the CAN_TRX pin is controlled by the CAN moudle.

I have spent a day trying to get this to work and as far as I can see I am not doing anything wrong.

thanks for any help

Ben,

ben2
Associate II
Posted on January 13, 2005 at 08:52

Ok have now got it working.

Think the data sheet could be a little clearer.

I was setting GPO1.11 (CAN RX) to alternate function when it needs to be an input. Had there been no alternate function option I would have set GPO1.11 to an input and wouldnt have had this trouble.

Have left GPO1.12 (CAN TX) configured as alternate function.