Problem with CANIF on AT32UC3C1512C / STK600

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Keep getting CAN_CMD_REFUSED on call to can_init.  Have STK600 PE4 and PE5 connected to CAN RX and CAN TX respectively. Have tried CAN slope jumper in both positions.
Have CAN DB9 connector attached to 120 Ohm terminated cable going to USB CAN adapter at 500 kbps setting.  Am using the following code. Any ideas would be greatly appreciated!

 

 volatile can_msg_t     mob_ram_ch0 [NB_MOB_CHANNEL];

 

#define FOSC0 32000000

 

sysclk_init();
scif_enable_osc(SCIF_OSC0, OSC_STARTUP_4096, true);
pm_set_mclk_source(PM_CLK_SRC_OSC0);

// Setup the generic clock for CAN
scif_gc_setup(AVR32_SCIF_GCLK_CANIF, AVR32_SCIF_GC_USES_CLK_CPU, AVR32_SCIF_GC_NO_DIV_CLOCK, 2);  // Divide down to 16 MHz?
// Now enable the generic clock
scif_gc_enable(AVR32_SCIF_GCLK_CANIF);

static const gpio_map_t CAN_GPIO_MAP =
{
   {AVR32_CANIF_RXLINE_0_0_PIN,  AVR32_CANIF_RXLINE_0_0_FUNCTION },
   {AVR32_CANIF_TXLINE_0_0_PIN,  AVR32_CANIF_TXLINE_0_0_FUNCTION},
};

gpio_enable_module(CAN_GPIO_MAP, sizeof(CAN_GPIO_MAP) / sizeof(CAN_GPIO_MAP[0]));

result = can_init  (0, (U32)&mob_ram_ch0[0], CANIF_CHANNEL_MODE_NORMAL , can_msg_callback);
if(result == CAN_CMD_REFUSED)
{
  cbtSerialSendString("CAN Init error!\r\n");
}

 

Also have these in conf_can.h: (which I saw on a post and believe to be correct)

#define CAN_BAUDRATE_500KBPS_CANCLOCK_16MHz_SJW 1    
#define CAN_BAUDRATE_500KBPS_CANCLOCK_16MHz_PRES 3
#define CAN_BAUDRATE_500KBPS_CANCLOCK_16MHz_PRS 2
#define CAN_BAUDRATE_500KBPS_CANCLOCK_16MHz_PHS1 1
#define CAN_BAUDRATE_500KBPS_CANCLOCK_16MHz_PHS2 1

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am guessing that your system clock configuration is using a 32MHz external source connected to XIN0.


If you want the GCLK_CANIF clock to be 1/2 of the system clock you should use AVR32_SCIF_GC_DIV_CLOCK in scif_gc_setup(AVR32_SCIF_GCLK_CANIF, AVR32_SCIF_GC_USES_CLK_CPU, AVR32_SCIF_GC_NO_DIV_CLOCK, 2);

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks! That was a good catch, however I still get the error on the can_init call when using the AVR32_SCIF_GC_DIV_CLOCK in place of  AVR32_SCIF_GC_NO_DIV_CLOCK.  I must be missing something else.