Hi,
i'm trying to use the CAN Interface of my AT32UC3C.
The Problem is i'm not able to manage it to activate the channel. I been
engaged in the data sheet and i'm quite sure i did exactly as stated in
the data sheet.
As you can see below i wrote the CANCTRL Register in the variable
canctrl_status. I was monitoring that variable to confirm that the
correct value is written in the CANCTRL Register. This is the case and i
can't see any Problem there. Following i programmed a Loop to poll the
variable channel_status. This variable contains the channel enable
Status flag (CANSR.CES). As soon as the channel enable status flag is
set (by hardware) the programm should Exit the loop but thats not
Happening.
What did i Forget? What's wrong about the code?
I would be thankful for any help!
1 | //----- Channel configuration (Bit time / SamplingMode / OperatingMode / OverrunMode / Memory pointer -----//
|
2 | if(CANIF_channel_enable_status(ch1) == 1) //If channel enabled
|
3 | {
|
4 | CANIF_disable(ch1) //Disable channel to write the CANCFG register (S. 764)
|
5 | while((AVR32_CANIF.channel[1].cansr & AVR32_CANIF_CANSR_CES_MASK) == 1); //Wait until channel is disabled
|
6 | }
|
7 |
|
8 | CAN_clear_init(ch1) //Clear INIT to write the CANCTRL register (S. 766)
|
9 |
|
10 | if(((&mobch0[63]) != mobch1) && (mobch0 != (&mobch1[63]))) //Assure that memory spaces do not overlap
|
11 | {
|
12 | CANIF_set_ram_add(ch1, (unsigned long) mobch1) //Set start address of RAM for channel[1]
|
13 | }
|
14 |
|
15 | //For bit time=25*TQ -> baud rate=500kHz --> bit time is set to 17*TQ so baud rate is higher than 500kHz
|
16 | CANIF_conf_bt(ch1)
|
17 | CANIF_set_channel_mode(ch1, CANIF_CHANNEL_MODE_LOOPBACK)
|
18 |
|
19 | //----- Channel handling (Initialization / Enabling / Overload Frame / Errors / Wake-up mode) ----------//
|
20 | CAN_set_init(ch1) //initialization request
|
21 | CAN_clear_init(ch1) //release initialization
|
22 | CANIF_enable(ch1) //Enable (restart) channel 1
|
23 |
|
24 | canctrl_status = CAN_get_canctrl(ch1);
|
25 | channel_status = CANIF_channel_enable_status(ch1);
|
26 | while(CANIF_channel_enable_status(ch1)==0);
|