SAME54 XPlained CAN BUS don't work

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

Hi

I used the SAME54 Xplained development board for CAN communication debugging, but it was not successful. I use a 48MHz clock, BRP=6, TSEG1=11, TSEG2=4, SJW=4, so the baud rate is 500Kbps.PB12-Tx,PB13-Rx,PC13-STANDBY. Then I wrote the segment test program in the same way as driver_example.c.According to CAN Transceiver ATA6561,in NORMAL MODE,STBY Pin is in a low level and TXD Pin is in a high level,so i set the two GPIO pin state in main.c.Through the debug observation, when the _can_async_write program is executed to hri_can_write_TXBAR_reg When the register PSR_LEC = 0X5, it means that Bit0 Error is in the BUS-OFF state, I don't know what the reason is.Atmel Start's configuration can be seen through the attachment.

main.c code:

#include <atmel_start.h>
#include "CANTEST.h"

int main(void)
{
	/* Initializes MCU, drivers and middleware */

	atmel_start_init();
	gpio_set_pin_level(PC13,false);
	gpio_set_pin_level(PB12,true);
	/* Replace with your application code */
	while (1) {
			can_transmit();
			can_receive();
			//CAN_1_init();
			delay_ms(1000);
	}
}

can_transmit and can_receive :

debug process:PSR_LEC = 0X5, bit0 error,in bus-off

Attachment(s): 

Last Edited: Thu. Apr 18, 2019 - 12:15 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I've worked through a lot of the CAN stuff the last few months on an E51 part and have it working reliably, so I will try my best to help yea out.. There really can't be too many things wrong here if you are using the example code

 

kd35-2812 wrote:
TXD Pin is in a high level

 

You definitely should not be asserting TXD on your own. Start by removing this and see what happens.. Next thing is I would verify the transceiver IC is in the correct state.

 

Also, what are you connecting to, to verify that you are transmitting correctly? CAN requires at least one other device on the bus to be connected so an "ACK" can be asserted when the message has been sent. If you attempt to send too many message without an "ACK" you will get into the BUS OFF state.

murph

Debugging - Being a detective in a crime movie where you are also the murderer.

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

Thank for your reply.In general, the CAN bus often has problems due to incorrect baud rate,but i think my baud rate set is right.I connect the board's CANH and CANL by dupont line to USB-CAN ,and i verify the dupont line and USB-CAN are ok. Because i have tested the communication between USB-CAN and STM32. According to your reply,i removed TXD Pin set,but it also doesn't work...

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

Here are my settings for each baudrate. These assume a 48Mhz clock being supplied to the CAN module.

 

typedef struct {
    uint32_t nbrp;
    uint32_t nsjw;
    uint32_t ntseg1;
    uint32_t ntseg2;
} can_baud_config_t;

const can_baud_config_t can_baud_config[4] =
{
    {0x18,0x01,0x0D,0x02}, // 125Kbps
    {0x0C,0x01,0x0D,0x02}, // 250Kbps
    {0x06,0x01,0x0D,0x02}, // 500Kbps
    {0x03,0x01,0x0D,0x02}, // 1Mbps
};

 

I'll take a closer look at your config this weekend.

murph

Debugging - Being a detective in a crime movie where you are also the murderer.

Last Edited: Fri. Apr 19, 2019 - 12:49 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you very much.I found out where the problem is.I made a rookie mistake ,I set PC13 pin as a peripheral IO, in fact it should be a digital output... The baud rate is no problem.So i will not bother your weekend, haha.

Last Edited: Fri. Apr 19, 2019 - 01:05 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Good to hear. Feel free to IM me if you run into more problems.

murph

Debugging - Being a detective in a crime movie where you are also the murderer.

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

Hi  kd35-2812 ,

I have some problem with my e54 xplained pro when using can driver.

Can you give me a hand or provide a generated file from ASF start?

Thank you very much!!

 

pinxian