• 0

Question

Hello members,

I have the Zybo-Z7 Board and I want to connect it with other Zybo-Z7 Board via CAN.

The board has an integrated CAN Controller and I need following PmodCAN-Connector which has also can controller integrated.

http://store.digilentinc.com/pmod-can-can-2-0b-controller-with-integrated-transceiver/

 

Which CAN Controller shall I use and how do I make it work?

I have implemented a basic design for Zybo in Vivado and added the IP core for PmodCAN. Is something more I need?

 

Cheers,

mb

 

zybo_can.JPG

Share this post


Link to post
Share on other sites

Recommended Posts

  • 0

Hi @JColvin, @jpeyron, @artvvb,

How can I check the Acknowledge Bit to make sure transmission of message was successful?

I know there is this check but it wont work when PmodCAN on receiver board is disconnected.

 

CAN_SendMessage(&pmod, TxMessage, CAN_Tx0);
CAN_ModifyReg(&pmod, CAN_CANINTF_REG_ADDR, CAN_CANINTF_TX0IF_MASK, 0);

do {
  status = CAN_ReadStatus(&pmod);
} while ((status & CAN_STATUS_TX0IF_MASK) != 0);


Thanks,
Mirco

Edited by mbo

Share this post


Link to post
Share on other sites
  • 0

Hi @mbo,

Are you using the most up to date Pmod CAN ip core? We recently connected the interrupt to the IP Core. For checking status, does the status check exits the loop, or if it loops forever (as expected)? I would also suggest looking at section 3.6.3 of the MCP25625 datasheet. I reached out to a co-worker about your thread and they suggested that If you are polling, rather than using the full interrupt mode that you have two approaches.

First if the loop never terminates, you can add a timeout clause, ie if (timeoutcount++>=timeoutperiod) break;

Second, if the loop exits prematurely, you can add additional status register reads as required, We are not sure what this would consist of, but you'd want to make sure that the flag you are looking for in the TX0 interrupt flag reg is the correct one for all situations. 

The other option if you would like to eliminate polling would be to incorporating the ISR process.
 

thank you,

Jon

 

 

 

 

Share this post


Link to post
Share on other sites
  • 0

Hi @jpeyron,

I found out that I am not using the latest release of Pmod CAN ip core. First, thank you for that information.

Lets say we have following scenario. Board A wants to send a message to Board B. On Board A Pmod CAN is connected but on Board B not.
So Board A tries to send a message but it will never be received by Board B. 

The shown code snipped for checking status exists immediately the loop but message has never been received by Board B or transmitted successfully.


The check of an additional status register you mentioned is also the approach of my choice. So am I correct that I need to extend the status check in mentioned loop above? For example like...

do {
  status = CAN_ReadStatus(&pmod);
} while ((status & CAN_STATUS_TX0IF_MASK) != 0 && (status & OTHER_REG_MASK) != 0);


What do you mean with full interrupt mode? You mean ISR process?

Thank you for your advices and I will try to get further information from other registers.

Thanks,
Mirco

Share this post


Link to post
Share on other sites
  • 0

Hi @mbo,

Sorry if my post was confusing the full interrupt mode was referring to the ISR process.

Your do while loop will no work correctly because it can only check if a different bit of the status register is also 1
if you need to test if a single bit in a register other than status is 1. Some pseudo code for the do while:
do {
  status = CAN_ReadStatus(&pmod);
  other_reg_value = CAN_ReadReg(&pmod, OTHER_REG_ADDR);
} while ((status & CAN_STATUS_TX0IF_MASK) != 0 && (other_reg_value & OTHERREG_1BIT_MASK) != 0);

One of my co-worker also suggested that often its safer to do a multi-byte SPI transaction than to do multiple single-reg reads, assuming that you don't need to go as fast as possible. Usually this ensures that nothing has changed between when the different bytes are read.

thank you,

Jon

 

 

Share this post


Link to post
Share on other sites
  • 0

Hi @jpeyron,

thank you for that advice. Is there a example how to use function CAN_ReadReg, because there are some parameter I do not understand how to use?

 

void CAN_ReadReg(PmodCAN *InstancePtr, u8 reg, u8 *data, u32 nData) {
   u8 buf[nData + 2];
   u32 i;
   buf[0] = CAN_READ_REG_CMD;
   buf[1] = reg;
   XSpi_Transfer(&InstancePtr->CANSpi, buf, buf, nData + 2);
   for (i = 0; i < nData; i++)
      data[i] = buf[nData + 2];
}


What is the best way to do a multi-byte SPI transaction?

Thanks,
Mirco

Edited by mbo

Share this post


Link to post
Share on other sites
  • 0

Hi @mbo,

Here is what xspi_transfer function takes for input:

int XSpi_Transfer(XSpi *InstancePtr, u8 *SendBufPtr, u8 *RecvBufPtr, unsigned int ByteCount)

The CAN_ReadReg function does read multi-bytes.  We were just making sure that you did not alter the CAN_ReadReg to only read one byte at a time. Are you using this function to get your data?

thank you,

Jon

 

 

 

Share this post


Link to post
Share on other sites
  • 0

Hi Gents,

allow me to ask you a question about same subject. I have also discussed it with @jpeyron and @mbo sent me some files.

I am trying to stablish a CAN bus network with a Ultrazed (ultrascale+) board with a axi_quad_spi interface and a Digilent PMOD CAN breakout board.

Reason I am not using PMODCAN is that I had a bad time repackaging it to UltraScale+.

 when I run the loopback.c test, apparently it goes well - it manages to send and fetches the message pre-define. When I remove the breakout board, it goes on "waiting to send"; so I believe it is working.

However, when I run either the RX or TX, having and Arduino (with CAN bus shield) at the other end, I do not manage to stablish the link.

For instance, for the TX, it stucks on the "waiting to send"....(Arduino is then configured as receive_check) - nothing gets through.

(I am using a twisted pair cable for CANH and CANL)

I would appreciate if you could shed some light on this.

Best regards,

 

 

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now