SAME54 Can drivers

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

I'm building a c++ interface for the start.atmel.com generated SAME54 ASF Can drivers and I'm having some issues.  At the moment I'm just trying to write a test message out to the bus.  After the system_init (and thus can_init), registering a tx callback, and calling can_async_enable, I make periodic calls to can_async_write to send my test message.  The first two writes complete without error except nothing appears on the bus, the callback is never called, and the message seems stuck in the tx fifo queue. After that the queue is full and all subsequent writes return ERR_NO_RESOURCE.

 

I do have another CAN device on the line, both are terminated.  I also have a scope on the line.  I think both are set at 250k baud although that's part of what I'm testing.

 

Any Atmel CAN wizards out there with ideas about what could cause the behavior I've described?

Last Edited: Thu. May 28, 2020 - 12:57 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Maybe you can reference to the CANDEMO example project. The code directly configured by the start.atmel.com with the SAME54 chip do NOT directly work with my project (I'm using the SAM54 EVM). 

Also, the two CAN device need have same CAN configures. If you were using two same CAN devices with same code, it may work.

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

To what CANDEMO example project are you referring?

 

Thanks

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

CANFDDemo for SAM E54 Xplained Pro. The Demo works, but the code created by the start.atmel needs some extra initialization of the pin13 for my case.

Also take care about the \config\hpl_can_config.h file. All CAN configures are in this file.

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

I am having similar issues with CANFD, and specifically with the CANFD demo. I have two ATSAME54 Xplained Pro boards and get the same behavior - I can see the writes on my scope but no callbacks, etc.

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

Kevin what extra initialization is needed?

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

Hello Jake,

 

The initialization which needed for the EVM is the CAN_STANDBY GPIO (It's a special requirement for the CAN chip, not for the CAN protocol), which needs to be pull low. That's PC13. It has been set in the EVM's CANFDDemo code.

 

If you are using two identical EVM, and both are flashed with the identical CAN demo, then at hardware side you only need to connect the two EVM boards with CANH pin to CANH pin, CANL pin to CANL pin.

If the EVM boards are using different power(which means they are not sharing the same ground), also the ground need to be connected between the EVM boards. For developing purpose, do not use long cable (my is less than 1 meter).

After that, at one side of the (uart)console, you set to receive data; at another side, corresponding to the receive setting, you send the data on the console.

With above, you will see some data printed at the receive side.

 

If you are using different CAN transmitter, and trying to use the Atmel chip to receive the data, then you must to set the Atmel's CAN format setting exactly same as the CAN transmitter you are using.

Including but not limited as Clock speed, Norminal bit rate configure and data bit rate  configure of: Sync jump, Baud rate prescaler, Pro seg, sampling point, phase seg1, phase seg2...

Some of the parameters are related with each others.

 

By the way, the AtmelStudio's Ethernet driver(LwIP) has conflict with the CAN driver. If you're using them simultaneously, I suggest that you had better switch to MPLAB X with Hamony v3 (using Berkeley driver).

Good luck!

 

Regards,

Kevin

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

I have two ATSAME54 xplained boards. I am not explicitly sharing ground, but the debug ports are both on the same hub. The two boards are about 20cm from each other. Both boards are flashed with the exact same binary. Ethernet is not being used.

 

I am going to tie the ground planes together to see if that helps.

 

Also I REALLY thank you for your help :)

 

The generated init code can is: 

 

void CAN1_init(void)
{
	hri_mclk_set_AHBMASK_CAN1_bit(MCLK);
	hri_gclk_write_PCHCTRL_reg(GCLK, CAN1_GCLK_ID, CONF_GCLK_CAN1_SRC | (1 << GCLK_PCHCTRL_CHEN_Pos));
    can_async_init(&Can1, CAN1);
	CAN1_PORT_init();
}

void CAN1_PORT_init(void)
{
}

void system_init(void)
{
    init_mcu();

    // GPIO on PC13

    gpio_set_pin_level(CAN_STDBY,
                       // <y> Initial level
                       // <id> pad_initial_level
                       // <false"> Low
                       // <true"> High
                       false);

    // Set pin direction to output
    gpio_set_pin_direction(CAN_STDBY, GPIO_DIRECTION_OUT);

    gpio_set_pin_function(CAN_STDBY, GPIO_PIN_FUNCTION_OFF);

    stdio_serial_init();
    CAN1_init();
}

 

 

 

Last Edited: Mon. Jun 1, 2020 - 05:51 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

For this EVM with this example demo, I used as it's. It's pretty straightforward demo. Nothing need to be modified.

 

Below is the demo code:

 

 

Last Edited: Mon. Jun 1, 2020 - 06:15 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

#include "driver_init.h"
#include <peripheral_clk_config.h>
#include <utils.h>
#include <hal_init.h>

struct can_async_descriptor CAN_0;

struct usart_sync_descriptor TARGET_IO;

void TARGET_IO_PORT_init(void)
{

	gpio_set_pin_function(PB25, PINMUX_PB25D_SERCOM2_PAD0);

	gpio_set_pin_function(PB24, PINMUX_PB24D_SERCOM2_PAD1);
}

void TARGET_IO_CLOCK_init(void)
{
	hri_gclk_write_PCHCTRL_reg(GCLK, SERCOM2_GCLK_ID_CORE, CONF_GCLK_SERCOM2_CORE_SRC | (1 << GCLK_PCHCTRL_CHEN_Pos));
	hri_gclk_write_PCHCTRL_reg(GCLK, SERCOM2_GCLK_ID_SLOW, CONF_GCLK_SERCOM2_SLOW_SRC | (1 << GCLK_PCHCTRL_CHEN_Pos));

	hri_mclk_set_APBBMASK_SERCOM2_bit(MCLK);
}

void TARGET_IO_init(void)
{
	TARGET_IO_CLOCK_init();
	usart_sync_init(&TARGET_IO, SERCOM2, (void *)NULL);
	TARGET_IO_PORT_init();
}

void CAN_0_PORT_init(void)
{

	gpio_set_pin_function(PB13, PINMUX_PB13H_CAN1_RX);

	gpio_set_pin_function(PB12, PINMUX_PB12H_CAN1_TX);
}
/**
 * \brief CAN initialization function
 *
 * Enables CAN peripheral, clocks and initializes CAN driver
 */
void CAN_0_init(void)
{
	hri_mclk_set_AHBMASK_CAN1_bit(MCLK);
	hri_gclk_write_PCHCTRL_reg(GCLK, CAN1_GCLK_ID, CONF_GCLK_CAN1_SRC | (1 << GCLK_PCHCTRL_CHEN_Pos));
	can_async_init(&CAN_0, CAN1);
	CAN_0_PORT_init();
}

void system_init(void)
{
	init_mcu();

	// GPIO on PC13

	gpio_set_pin_level(CAN_STDBY,
	                   // <y> Initial level
	                   // <id> pad_initial_level
	                   // <false"> Low
	                   // <true"> High
	                   false);

	// Set pin direction to output
	gpio_set_pin_direction(CAN_STDBY, GPIO_DIRECTION_OUT);

	gpio_set_pin_function(CAN_STDBY, GPIO_PIN_FUNCTION_OFF);

	TARGET_IO_init();
	CAN_0_init();
}

 

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

I changed it to CAN1 because the board exposes CAN1 and I kept getting confused. lol. I did modify where needed.

 

I am going to re-create the sample in start and run it untouched to see how it works.

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

JakeSays wrote:

I changed it to CAN1 because the board exposes CAN1 and I kept getting confused. lol. I did modify where needed.

 

I am going to re-create the sample in start and run it untouched to see how it works.

 

You do NOT need to create the sample. You can directly download the whole demo project at the start.atmel.com

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

I went the whole demo route instead of creating a sample.

 

And it works!

 

Now I need to figure out why it wouldn't work with threadx.

 

Thank you Kevin for you help!

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

laugh Using the same demo code works fine under threadx as well. Thanks again!

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

Hello guys,

I have some problem with can driver. I also used E54 Xplained pro board and got wrong msg when trying to trasmit a frame through CAN_Tx.

Unfortunately, I can not find any resource and example project from  start.atmel.com.

Can you guys give me a hand, thanks a lot!!

 

The following is the seeting for my board and the attached file is a generated project file.

 

 

Attachment(s): 

pinxian

Last Edited: Thu. Sep 17, 2020 - 07:41 AM