世纪电源网社区logo
社区
Datasheet
标题
返回顶部
未解决

关于DSP28379D的CAN通信问题

[复制链接]
查看: 1616 |回复: 0
1
amazing阿泽
  • 积分:467
  • |
  • 主题:2
  • |
  • 帖子:5
积分:467
LV6
高级工程师
  • 2020-2-11 14:30:16
10问答币
我根据TI给出的can-loopback例程,然后把IO口改掉,环回模式是对的,之后把环回模式    // Enable test mode and select external loopback    HWREG(CANA_BASE + CAN_O_CTL) |= CAN_CTL_TEST;
    HWREG(CANA_BASE + CAN_O_TEST) = CAN_TEST_EXL;
给注释掉,波特率也设定好了,连接一个CAN分析仪后,发现dsp的数据不能发送出去,请问还需要修改其他地方嘛?
这是我的程序,十分感谢各位前辈的指导。
main(void)
{
    tCANMsgObject sTXCANMessage;
    tCANMsgObject sRXCANMessage;


    // Step 1. Initialize System Control:
        InitSysCtrl();

        // Step 2. Initialize GPIO:
        InitGpio();
        //GPIO70 - CANRXA
        GPIO_SetupPinMux(17, GPIO_MUX_CPU1, 2);
        //GPIO71 - CANTXA
        GPIO_SetupPinMux(12, GPIO_MUX_CPU1, 2);
        GPIO_SetupPinOptions(17, GPIO_INPUT, GPIO_ASYNC);
        GPIO_SetupPinOptions(12, GPIO_OUTPUT, GPIO_PUSHPULL);

    // Initialize the CAN controller
    CANInit(CANA_BASE);

    // Setup CAN to be clocked off the M3/Master subsystem clock
    CANClkSourceSelect(CANA_BASE, 0);

    CANBitRateSet(CANA_BASE, 200000000, 50000);

    // Step 3. Clear all interrupts and initialize PIE vector table:
    // Disable CPU interrupts
        DINT;

        InitPieCtrl();

    // Disable CPU interrupts and clear all CPU interrupt flags:
        IER = 0x0000;
        IFR = 0x0000;

    InitPieVectTable();

    // Enable test mode and select external loopback
   // HWREG(CANA_BASE + CAN_O_CTL) |= CAN_CTL_TEST;
   // HWREG(CANA_BASE + CAN_O_TEST) = CAN_TEST_EXL;

    // Enable the CAN for operation.
    CANEnable(CANA_BASE);

    // Initialize the message object that will be used for sending CAN
    // messages.  The message will be 4 bytes that will contain an incrementing
    // value.  Initially it will be set to 0.
    *(unsigned long *)ucTXMsgData = 0;
    sTXCANMessage.ui32MsgID = 1;                      // CAN message ID - use 1
    sTXCANMessage.ui32MsgIDMask = 0;                  // no mask needed for TX
    sTXCANMessage.ui32Flags = MSG_OBJ_TX_INT_ENABLE;  // enable interrupt on TX
    sTXCANMessage.ui32MsgLen = sizeof(ucTXMsgData);   // size of message is 4
    sTXCANMessage.pucMsgData = ucTXMsgData;           // ptr to message content

    // Initialize the message object that will be used for recieving CAN
    // messages.
    *(unsigned long *)ucRXMsgData = 0;
    sRXCANMessage.ui32MsgID = 1;                      // CAN message ID - use 1
    sRXCANMessage.ui32MsgIDMask = 0;                  // no mask needed for TX
    sRXCANMessage.ui32Flags = MSG_OBJ_NO_FLAGS;
    sRXCANMessage.ui32MsgLen = sizeof(ucRXMsgData);   // size of message is 4
    sRXCANMessage.pucMsgData = ucRXMsgData;           // ptr to message content

    // Setup the message object being used to receive messages
    CANMessageSet(CANA_BASE, 5, &sRXCANMessage, MSG_OBJ_TYPE_RX);  

    // Enter loop to send messages.  A new message will be sent once per
    // second.  The 4 bytes of message content will be treated as an unsigned
    // long and incremented by one each time.
    for(;;)
    {
        // Send the CAN message using object number 1

        CANMessageSet(CANA_BASE, 1, &sTXCANMessage, MSG_OBJ_TYPE_TX);

        // Now wait 1 second before continuing
        DELAY_US(1000*1000);

        // Get the receive message
        CANMessageGet(CANA_BASE, 5, &sRXCANMessage, true);

        // Ensure the received data matches the transmitted data
        if((*(unsigned long *)ucTXMsgData) != (*(unsigned long *)ucRXMsgData)){
                asm(" ESTOP0");
        }

        // Increment the value in the transmitted message data.
        (*(unsigned long *)ucTXMsgData)++;
        asm(" ESTOP0");
    }

}




热门技术、经典电源设计资源推荐

世纪电源网总部

地 址:天津市南开区黄河道大通大厦8层

电 话:400-022-5587

传 真:(022)27690960

邮 编:300110

E-mail:21dy#21dianyuan.com(#换成@)

世纪电源网分部

广 东:(0755)82437996 /(138 2356 2357)

北 京:(010)69525295 /(15901552591)

上 海:(021)24200688 /(13585599008)

香 港:HK(852)92121212

China(86)15220029145

网站简介 | 网站帮助 | 意见反馈 | 联系我们 | 广告服务 | 法律声明 | 友情链接 | 清除Cookie | 小黑屋 | 不良信息举报 | 网站举报

Copyright 2008-2024 21dianyuan.com All Rights Reserved    备案许可证号为:津ICP备10002348号-2   津公网安备 12010402000296号