CAN Protocol is not working

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

Using cypress controller CY8C4247AXI-M485  and feeding internal clock of 48 MHZ with WCO  enabled , we could not able to transmits and receive data .

We have tried with example code which given in cypress forum still we can't able to communicate .please share the information if any one worked on it.

1. Currently running baud rate 125 Kbps

2. Do we need to connect the Tr_Enable pin ?

see the below mentioned configuration details 

Capture.PNGCapture2.PNG

please let us know if any changes required in configurations.

0 Likes
1 Solution
lock attach
Attachments are accessible only for community members.

Hi Harish,

The external clock settings look fine. Could you please peovide us the following information, so that we could debug on this issue further?

1) Tx pin of PSoC with the timing information (to confirm if the baud rate is accurate)

2) Scope shots of CAN transceiver high and low signals (to verify the working/interface with CAN controller)

3) The error registers in PSoC (to check the error that causes bus-off condition)

In order to monitor the error registers, you can use the following API.

uint32 CAN_RSM_ReadErrorCaptureRegister(void).

The error register bits and description is available in the attached image.

Thanks,
Shanmathi

View solution in original post

8 Replies
ShanmathiN_06
Employee
Employee
100 replies posted 50 replies posted 25 replies posted

Hello,

Please mention the code example that you had referred and the transceiver used.

If it is a custom firmware, please attach the project here.

In general, you can refer to CAN_Basic_P4_Example and CAN_Full_P4_Example, by navigating to PSoC Creator-> File->Code example.

Thanks,
Shanmathi

Anonymous
Not applicable

Hi Shanmathi,

I have tested  example code which is there in the cypress forum . I couldn't able to transmits data . CAN_EN and CAN_STB  pin we are controlling by using GPIO ,Does it correct way or not ?.Please check the schematics of Transceiver and controller pins . Please let us know , if is there any changes required in the schematics .

Sch-CAN_Pins.PNGSch-CAN_Transreciver.PNG

0 Likes

Hi,

Do you mean the code examples we had provided or some projects posted in forum? It would be helpful if you could provide a link to the forum page containing the example code that you had tested.

I did not find any issues with the schematics. You can control EN and STB by enabling it as a GPIO in the host MCU.

Thanks,
Shanmathi

Anonymous
Not applicable

Hi ,

Thanks you for information .

Please  check the below attached code which presently i am using for CAN Communication.

#include <project.h>

#include <stdio.h>

#define PWM_PULSE_WIDTH_STEP        (10u)

#define SWITCH_PRESSED              (1u)

#define PWM_MESSAGE_ID              (0x1AAu)

#define PWM_MESSAGE_IDE             (0u)    /* Standard message */

#define PWM_MESSAGE_IRQ             (0u)    /* No transmit IRQ */

#define PWM_MESSAGE_RTR             (0u)    /* No RTR */

#define CAN_RX_MAILBOX_0_SHIFT      (1u)

#define CAN_RX_MAILBOX_1_SHIFT      (2u)

#define TX_DATA_SIZE                (25u)

#define ONE_BYTE_OFFSET             (8u)

/* Function prototypes */

CY_ISR_PROTO(ISR_CAN);

/* Global variables used to store configuration and data for BASIC CAN mailbox */

CAN_DATA_BYTES_MSG dataPWM;

CAN_TX_MSG messagePWM;

/* Global variable used to store PWM pulse width value  */

uint8 pulseWidthValue = 0u;

/* Global variable used to store receive message mailbox number */

volatile uint8 receiveMailboxNumber = 0xFFu;

/*******************************************************************************

* Function Name: main

********************************************************************************

*

* Summary:

*  main() performs the following functions:

*  1: Initializes a structure for the Basic CAN mailbox to send messages.

*  2: Starts the CAN and UART components.

*  3: When received Message 1, sends the PWM pulse width and sends

*     received switch status and value of PWM pulse width over UART;

*     When received Message 2, sends the received ADC data over UART.

*

* Parameters:

*  None.

*

* Return:

*  None.

*

*******************************************************************************/

int main()

{

    char8 txData[TX_DATA_SIZE];

    uint16 adcData;

  

    /* BASIC CAN mailbox configuration */

    messagePWM.dlc = CAN_TX_DLC_MAX_VALUE;

    messagePWM.id  = PWM_MESSAGE_ID;

    messagePWM.ide = PWM_MESSAGE_IDE;

    messagePWM.irq = PWM_MESSAGE_IRQ;

    messagePWM.msg = &dataPWM;

    messagePWM.rtr = PWM_MESSAGE_RTR;

   // UART_Start();

    CAN_Start();

    CAN_STB_Write(1);

CyDelay(1000);

    CAN_EN_Write(1);

    CyDelay(1000);

    /* Set CAN interrupt handler to local routine */

    CyIntSetVector(CAN_ISR_NUMBER, ISR_CAN);

    CyGlobalIntEnable;

    for(;;)

    {

        dataPWM.byte[0u] = pulseWidthValue;

        CAN_SendMsg(&messagePWM);   // sending message

      

        CyDelayUs(500);

      

    }

}

/*******************************************************************************

* Function Name: ISR_CAN

********************************************************************************

*

* Summary:

*  This ISR is executed at a Receive Message event and set receiveMailboxNumber

*  global variable with receive message mailbox number.

*

* Parameters:

*  None.

*

* Return:

*  None.

*

*******************************************************************************/

CY_ISR(ISR_CAN)

{

    /* Clear Receive Message flag */

    CAN_INT_SR_REG = CAN_RX_MESSAGE_MASK;

    /* Switch status message received */

    if ((CAN_BUF_SR_REG & CAN_RX_MAILBOX_0_SHIFT) != 0u)

    {

        receiveMailboxNumber = CAN_RX_MAILBOX_switchStatus;

        /* Acknowledges receipt of new message */

        CAN_RX_ACK_MESSAGE(CAN_RX_MAILBOX_switchStatus);

    }

    if ((CAN_BUF_SR_REG & CAN_RX_MAILBOX_1_SHIFT) != 0u)

    {

        receiveMailboxNumber = CAN_RX_MAILBOX_ADCdata;

      

        /* Acknowledges receipt of new message */

        CAN_RX_ACK_MESSAGE(CAN_RX_MAILBOX_ADCdata);

    }

}

/* [] END OF FILE */

Regards,

Harish

0 Likes

Hi Harish,

Could you please confirm if external crystal is connected to WCO pins?

Thanks,
Shanmathi

0 Likes
Anonymous
Not applicable

Hi Shanmathi,

Thanks for  response.

I didn't connected WCO pin to the external clock. when i am trying to send data getting the interrupt of  CAN_BusOffIsr(). we are getting signal on the transmitter pin .

Please check the attached images of clock configuration and waveform.

if clock configuration is not correct way kindly inform or reply back.
High_Fre_Clk.PNGHigh_Fre_Clk.PNG

We captured the Tx signal

wave.jpg

Could you please help us how to solve the bus off error.

Regards,

Harish

0 Likes
lock attach
Attachments are accessible only for community members.

Hi Harish,

The external clock settings look fine. Could you please peovide us the following information, so that we could debug on this issue further?

1) Tx pin of PSoC with the timing information (to confirm if the baud rate is accurate)

2) Scope shots of CAN transceiver high and low signals (to verify the working/interface with CAN controller)

3) The error registers in PSoC (to check the error that causes bus-off condition)

In order to monitor the error registers, you can use the following API.

uint32 CAN_RSM_ReadErrorCaptureRegister(void).

The error register bits and description is available in the attached image.

Thanks,
Shanmathi

Anonymous
Not applicable

Hi Shanmathi,

Thank you for information .

Now CAN is  working properly.

Regards,

Harish

0 Likes