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

PSoC™ 6 Forum Discussions

vikas_d
Level 1
5 sign-ins First reply posted First question asked
Level 1

Hello,

I have configured CAN controller to recieve packets. But it does not seem to read any packets. I have connected Cy8c6244Lqi micocontroller with CAN Transceiver and at other end connected Peak CAN to laptop. 

1.  PCAN configuration, b/w CAN_l and CAN_h 120ohm register has been connected.

vikas_d_0-1658243767425.png

vikas_d_1-1658244259901.png

 

2. On transceriver, RX pin I could see waveform, so confirm that packets are received at end, but micocontroller do not detect the packets.

3. CAN configuration, 

vikas_d_2-1658244468524.pngvikas_d_3-1658244542021.pngvikas_d_4-1658244576133.pngvikas_d_5-1658244635646.pngvikas_d_6-1658244687854.png

Pin 5,0 configured for CAN Rx. Tried with slew rate fast and slow.

vikas_d_7-1658244770375.png

Pin 5, 1 configured as CAN tx

vikas_d_8-1658244841890.png

3. Microcontroller firmware

bool InitCAN()
{
bool RetStatus = false;
cy_en_canfd_status_t CANSysRetStatus = CY_CANFD_SUCCESS;
cy_en_sysint_status_t INITSysRetStatus = CY_SYSINT_SUCCESS;

cy_en_gpio_status_t ret = Cy_GPIO_Pin_Init(USER_CAN_RX_PORT, USER_CAN_RX_NUM, &USER_CAN_RX_config);
printf(" GPIO init %u 5.0", ret);
ret = Cy_GPIO_Pin_Init(USER_CAN_TX_PORT, USER_CAN_TX_NUM, &USER_CAN_TX_config);
printf(" GPIO init %u 5.1", ret);

uint32_t status = (CY_CANFD_RX_BUFFER_NEW_MESSAGE | /* Message stored to Rx Buffer */
CY_CANFD_RX_FIFO_1_NEW_MESSAGE | /* Rx FIFO 1 New Message */
CY_CANFD_RX_FIFO_0_NEW_MESSAGE | /* Rx FIFO 0 New Message */
CY_CANFD_TRANSMISSION_COMPLETE |
CY_CANFD_TRANSMISSION_CANCEL_FINISHED |
CY_CANFD_TX_EVENT_FIFO_NEW_ENTRY |
CY_CANFD_TX_FIFO_EMPTY);

Cy_CANFD_SetInterruptMask(CANFD0, 0UL, status);

Cy_CANFD_SetInterruptLine(CANFD0, 0UL, Cy_CANFD_GetInterruptLine(CANFD0, 0UL) |
CY_CANFD_TRANSMISSION_COMPLETE);

 

uint32_t channelMask = 0x00000001UL; /* Enable the first channel */
Cy_CANFD_Enable(CANFD0, channelMask);


if (Cy_CANFD_IsInterruptLineEnabled(CANFD0, 0UL, CY_CANFD_INTERRUPT_LINE_0_EN))
{
printf("Interrupt line is enabled \r\n");
}
else
{
Cy_CANFD_EnableInterruptLine(CANFD0, 0UL, CY_CANFD_INTERRUPT_LINE_0_EN);
//Cy_CANFD_EnableInterruptLine(CANFD0, 0UL, CY_CANFD_INTERRUPT_LINE_1_EN);
printf("Interrupt line is enabled \r\n");
}

Cy_CANFD_EnableInterruptLine(CANFD0, 0UL, CY_CANFD_INTERRUPT_LINE_0_EN);

if(CY_CANFD_SUCCESS == (CANSysRetStatus = Cy_CANFD_Init (CANFD0, 0, &CAN_CHANNEL_config, &CAN_CHANNEL_context)))
{
/* Enable for configuration changes to set Test mode */
Cy_CANFD_ConfigChangesEnable(CANFD0, 0);

/* Sets the Test mode configuration */
Cy_CANFD_TestModeConfig(CANFD0, 0, CY_CANFD_TEST_MODE_DISABLE);

/* Disable for configuration changes */
Cy_CANFD_ConfigChangesDisable(CANFD0, 0);


uint32_t status = (CY_CANFD_RX_BUFFER_NEW_MESSAGE | /* Message stored to Rx Buffer */
CY_CANFD_RX_FIFO_1_NEW_MESSAGE | /* Rx FIFO 1 New Message */
CY_CANFD_RX_FIFO_0_NEW_MESSAGE); /* Rx FIFO 0 New Message */

Cy_CANFD_SetInterruptMask(CANFD0, 0UL, status);

/* Hook the interrupt service routine and enable the interrupt */
if(CY_SYSINT_SUCCESS == (INITSysRetStatus = Cy_SysInt_Init(&irq_cfg, &CANInterruptHandler)))
{
NVIC_EnableIRQ(canfd_0_interrupts0_0_IRQn);

RetStatus = true;
}
else
{
CANErrorsStatus = CAN_INIT_ERROR;
}

if(CY_SYSINT_SUCCESS == (INITSysRetStatus = Cy_SysInt_Init(&irq_cfg1, &CANInterruptHandler1)))
{
NVIC_EnableIRQ(canfd_0_interrupts1_0_IRQn);

RetStatus = true;
}
else
{
CANErrorsStatus = CAN_INIT_ERROR;
}

if(CY_SYSINT_SUCCESS == (INITSysRetStatus = Cy_SysInt_Init(&irq_cfg2, &CANInterruptHandler2)))
{
NVIC_EnableIRQ(canfd_0_interrupt0_IRQn);

RetStatus = true;
}
else
{
CANErrorsStatus = CAN_INIT_ERROR;
}

}
else
{
CANErrorsStatus = CAN_INIT_ERROR;
}

...............................................................................................................................

cy_stc_canfd_context_t CAN_CHANNEL_context; /* This is a shared context structure,
* unique for each channel
*/

const cy_stc_sysint_t irq_cfg =
{
.intrsrc=canfd_0_interrupts0_0_IRQn,
.intrPriority = 6UL /* Interrupt priority */
};

const cy_stc_sysint_t irq_cfg1 =
{
.intrsrc=canfd_0_interrupts1_0_IRQn,
.intrPriority = 6UL /* Interrupt priority */
};

const cy_stc_sysint_t irq_cfg2 =
{
.intrsrc=canfd_0_interrupt0_IRQn,
.intrPriority = 6UL /* Interrupt priority */
};

/* CANFD interrupt handler */
void CANInterruptHandler(void)
{
/* Just call the IRQ handler with the current channel number and context */
Cy_CANFD_IrqHandler(CANFD0, 0, &CAN_CHANNEL_context);
}

/* CANFD interrupt handler */
void CANInterruptHandler1(void)
{
/* Just call the IRQ handler with the current channel number and context */
Cy_CANFD_IrqHandler(CANFD0, 0, &CAN_CHANNEL_context);
}

/* CANFD interrupt handler */
void CANInterruptHandler2(void)
{
/* Just call the IRQ handler with the current channel number and context */
Cy_CANFD_IrqHandler(CANFD0, 0, &CAN_CHANNEL_context);
}

..................................................................................................................

void CANTxCallback(void)
{

}

void CANRxCallback(bool rxFIFOMsg, uint8_t msgBufOrRxFIFONum, cy_stc_canfd_rx_buffer_t* basemsg)
{
printf("Data received \n\r");
}

void CANErrCallback(uint32_t errorMask)
{
printf("CAN error \n\r");
}

.............................................................................................................

No interrupts are detected using breakpoints in interrupt handler and neither Rx callback or error callback hit. I have tried test methods for internal loop back and external loop back by sending packets and tried to recieve, but that also not worked.

Please help me to figure out in case i am missing any thing. I have taken reference from PDL library documentation "pdl_api_reference_manual".

Thanks.

 

 

0 Likes
2 Replies
Alakananda_BG
Moderator
Moderator 50 likes received 250 sign-ins 250 replies posted
Moderator

Hi @vikas_d ,

  1. Can you share the waveform with us.
  2. Can you let us know if the received message is getting acked or nacked?
  3. Can you also try sending something on the TX line and observe what is happening?
  4. Can you also check if the receive buffer filters are set correctly?

Regards,

 

Alakananda
0 Likes
vikas_d
Level 1
5 sign-ins First reply posted First question asked
Level 1

Hello Alakananda,

Thanks for reply.

Here are the wave forms.

I am using Infeneon TLE7250V CAN transceiver. I have switched to default example CAN application and tried with both cases filter ON, NO filter and transmit only to PCAN device connected over laptop.  I do not see the other end is able to acknowledge the messages as PCAN device is not detecting the sent messages from MCU (PSOC 6 Cy8c6244Lqi ). I checked with two PcAN devices, there I could see stuff error messages.

I am able to capture transmit messages using local and external loopback features.

1. Waveform at TX of MCU

vikas_d_0-1658754250721.png

2. Waveform at Rx of MCU

vikas_d_1-1658754334430.png

3. Waveform at CAN L

vikas_d_2-1658754413311.png

4. waveform at CAN h

vikas_d_3-1658754459271.png

Regards,

Vikas

 

 

 

 

 

 

 

0 Likes