LPC54608 Can Driver

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

LPC54608 Can Driver

1,139 Views
fatihozen
Contributor IV

Hello,

I have OM13092 Dev. Board and using mcan_loopback example. I changed it little bit and receiving some datas on canbus. I know what datas should seen on canbus. There is a problem or I miss something. When I use semihost console datas have expected values. In second byte(column) I must see all zeros.But if I use UART console I see there some non-zero values. What does cause this ?
/*

for(int a=0;a<8;a++) {rcv_data[a] = *(rxFrame.data + a);}

Can_get_ID = rxFrame.id>>18U;
PRINTF("GET_ID: %x", Can_get_ID);
PRINTF(" DATA: ");
{PRINTF(" %d %d",rcv_data[0],rcv_data[1]);}

*/
pastedImage_1.jpgpastedImage_2.jpg

Labels (1)
Tags (1)
0 Kudos
3 Replies

728 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi fatih ozen,

    Do you mean the lpc54608 sdk code in folder: SDK_2.3.0_LPCXpresso54608\boards\lpcxpresso54608\driver_examples\mcan\loopback\iar?

    Which line do you modify the code?

    I use the official code, it works OK, but I don't where you modify the code, you said : I changed it little bit and receiving some datas on canbus. I know what datas should seen on canbus.

   Do you also disable the loopback mode, and receive the data from the CAN bus directly? As you know the OM13092 don't have the CAN transceiver, do you connect the external CAN transceiver? If you still use the official code:

    while(!rxComplete)
    {
    }
    PRINTF("Received Frame ID: 0x%x\r\n", rxFrame.id >> STDID_OFFSET);
    PRINTF("Received Frame DATA: ");
    while(rxFrame.dlc--)
    {
        PRINTF("0x%x ", *(rxFrame.data++));
    }

Can you receive the correct data?


Have a great day,
Kerry

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

728 Views
fatihozen
Contributor IV

Hi kerryzhou‌,


I am using mcu xpresso ide and folder is SDK_2.3.0_LPCXpresso54608\boards\lpcxpresso54608\driver_examples\mcan\loopback.
I am not using loopback mode and I have Can Transceiver.

Here you can see the code :

#include "fsl_debug_console.h"
#include "fsl_mcan.h"
#include "board.h"
#include "pin_mux.h"
#include <stdbool.h>
#include <canbus.h>
volatile bool txComplete = false;
volatile bool rxComplete = false;
mcan_tx_buffer_config_t txBuffer;
mcan_tx_buffer_frame_t txFrame;
mcan_rx_buffer_frame_t rxFrame;
uint8_t rcv_data[8];
uint16_t MSG[4];
uint32_t Can_get_ID;
mcan_config_t mcanConfig;
mcan_frame_filter_config_t rxFilter;
mcan_std_filter_element_config_t stdFilter;
mcan_rx_fifo_config_t rxFifo0;
mcan_buffer_transfer_t txXfer;
mcan_handle_t mcanHandle;
uint8_t count = 0;
void CAN0_IRQ0_IRQHandler(void)
{
    MCAN_ClearStatusFlag(CAN0, CAN_IR_RF0N_MASK);
    MCAN_ReadRxFifo(CAN0, 0, &rxFrame);
    rxComplete = true;
#if defined __CORTEX_M && (__CORTEX_M == 4U)
    __DSB();
#endif
}
void Can_Init(void)
    {
        CLOCK_SetClkDiv(kCLOCK_DivCan0Clk, 22U, true);
               MCAN_GetDefaultConfig(&mcanConfig);
               MCAN_Init(CAN0, &mcanConfig, CLOCK_GetFreq(kCLOCK_MCAN0));
            /* Create MCAN handle structure and set call back function. */
             MCAN_TransferCreateHandle(CAN0, &mcanHandle, mcan_callback, NULL);
               MCAN_SetMsgRAMBase(CAN0, MSG_RAM_BASE);
               uint32_t *p=(uint32_t *)(MSG_RAM_BASE);
               memset(p, 0, TX_BUFFER_OFS + 0x10U);
               rxFilter.address = 0x0;
               rxFilter.idFormat = kMCAN_FrameIDStandard;
               rxFilter.listSize = 1U;
               rxFilter.nmFrame = kMCAN_reject0;
               rxFilter.remFrame = kMCAN_rejectFrame;
               MCAN_SetFilterConfig(CAN0, &rxFilter);
               stdFilter.sfec = kMCAN_storeinFifo0;
               stdFilter.sft = kMCAN_dual;
               stdFilter.sfid1 = 0x000U;
               stdFilter.sfid2 = 0x002U;
               MCAN_SetSTDFilterElement(CAN0, &rxFilter, &stdFilter, 0);
               rxFifo0.address = RX_FIFO0_OFS;
               rxFifo0.elementSize = 1U;
               rxFifo0.watermark = 0;
               rxFifo0.opmode = kMCAN_FifoBlocking;
               rxFifo0.datafieldSize = kMCAN_8ByteDatafield;
               MCAN_SetRxFifo0Config(CAN0, &rxFifo0);
               MCAN_EnableInterrupts(CAN0, 0, CAN_IE_RF0NE_MASK);
               EnableIRQ(CAN0_IRQ0_IRQn);
               MCAN_EnterNormalMode(CAN0);
    }
void CAN_getmsg(void)
{
      for(int a=0;a<8;a++) {rcv_data[a] = *(rxFrame.data + a);}
 
      Can_get_ID = rxFrame.id>>18U;
     PRINTF("GET_ID: %x", Can_get_ID);
     PRINTF(" DATA: ");
     {PRINTF(" %x %x",rcv_data[0],rcv_data[1]);}
    PRINTF("\r\n");
}
int main(void)
{
    CLOCK_AttachClk(BOARD_DEBUG_UART_CLK_ATTACH);
    BOARD_InitPins();
    BOARD_BootClockPLL180M();
    BOARD_InitDebugConsole();
    Can_Init();
    while (1)
    {
         CAN_getmsg();
    }
}
0 Kudos

728 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Ozen,

   About the classic CAN driver for LPC54608, please refer to this code, you need to modify your Can operation code:

CAN/CAN-FD drivers and examples for use with LPC5461x parts

   Then refer to project classical_msgobjs.

    This is the MCUXpresso project, this project is just configured for LPC54608, you can run it directly.


Have a great day,
Kerry

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos