在我的28335程序中,CAN可以正常发送数据,通过CANtest能够收到收据,但是通过CANtest发送数据就会显示发送失败,或者显示发送了但下位机程序中对应邮箱没有接收到收据。
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
在我的28335程序中,CAN可以正常发送数据,通过CANtest能够收到收据,但是通过CANtest发送数据就会显示发送失败,或者显示发送了但下位机程序中对应邮箱没有接收到收据。
//###########################################################################
//
// FILE: PMSM_281x_eCAN.c
//
// TITLE: DSP281x eCAN Initialization Program
//
// ASSUMPTIONS:
//
// This program requires the DSP281x V1.00 header files.
// As supplied, this project is configured for "boot to H0" operation.
//
// Other then boot mode configuration, no other hardware configuration
// is required.
//
// DESCRIPTION:
//
// Initializing the eCAN Module and the mailboxes.
//
//###########################################################################
//
// Ver | dd mmm yyyy | Who | Description of changes
// =====|=============|======|===============================================
// 1.00| 05 JUL 2008 |S.X.L |
// | | |
// | | |
//###########################################################################
#include "DSP2833x_Device.h" // DSP281x Headerfile Include File
#include "EV_PMSM_eCANData.h"
#include "DSP2833x_Examples.h"
/***************************************************************************/
/*-------------------------------------------------------------------------*/
/***************************************************************************/
// Prototype statements for functions found within this file.
void EcanA_init(void);
void EcanAMboxConfig(void);
void mailbox_readA(int16 i);
/***************************************************************************/
/*-------------------------------------------------------------------------*/
/***************************************************************************/
// Global variable for this example
Uint32 ErrorCount_A;
Uint32 TestAMbox1 = 0;
Uint32 TestAMbox2 = 0;
Uint32 TestAMbox3 = 0;
/***************************************************************************/
/*-------------------------------------------------------------------------*/
/***************************************************************************/
void EcanA_init()
{
/*-------------------------------------------------------------------------*/
// configure CAN pins using GPIO regs here
EALLOW;
GpioCtrlRegs.GPAMUX2.bit.GPIO30=1;
GpioCtrlRegs.GPAMUX2.bit.GPIO31=1;
GpioCtrlRegs.GPAPUD.bit.GPIO30 = 0;
GpioCtrlRegs.GPAPUD.bit.GPIO31 = 0;
EDIS;
/*-------------------------------------------------------------------------*/
// Configure the eCAN RX and TX pins for eCAN transmissions
EALLOW;
ECanaRegs.CANTIOC.bit.TXFUNC = 1;
ECanaRegs.CANRIOC.bit.RXFUNC = 1;
EDIS;
/*-------------------------------------------------------------------------*/
// eCAN mode (reqd to access 32 mailboxes)
EALLOW;
ECanaRegs.CANMC.bit.SCB = 1; // eCAN mode
EDIS;
ECanaRegs.CANME.all = 0x00000000;
/*-------------------------------------------------------------------------*/
/* Clear all TAn bits */
ECanaRegs.CANTA.all = 0xFFFFFFFF;
/*-------------------------------------------------------------------------*/
/* Clear all RMPn bits(write 1 to clear) */
ECanaRegs.CANRMP.all = 0xFFFFFFFF;
/*-------------------------------------------------------------------------*/
/* Clear all interrupt flag bits */
ECanaRegs.CANGIF0.all = 0xFFFFFFFF;
ECanaRegs.CANGIF1.all = 0xFFFFFFFF;
/*-------------------------------------------------------------------------*/
/* disbale global interrupt and mailbox interrupt */
EALLOW;
ECanaRegs.CANGIM.all = 0x00000000;
ECanaRegs.CANMIM.all = 0x00000000;
EDIS;
/*-------------------------------------------------------------------------*/
/* Configure bit timing parameters */
EALLOW;
ECanaRegs.CANMC.bit.CCR = 1; // Set CCR = 1
EDIS;
while(ECanaRegs.CANES.bit.CCE != 1 ) {} // Wait for CCE bit to be set..
/*-------------------------------------------------------------------------*/
EALLOW;
ECanaRegs.CANBTC.bit.BRPREG = 19; // 19 150MHz/20=7.5MHz
ECanaRegs.CANBTC.bit.TSEG1REG = 10; //10
ECanaRegs.CANBTC.bit.TSEG2REG = 2; //2 Bode rate:7.5M/(1+11+3)=500k
// ECanbRegs.CANBTC.bit.SJWREG = 1; //
EDIS;
/*-------------------------------------------------------------------------*/
EALLOW;
ECanaRegs.CANMC.bit.CCR = 0; // Set CCR = 0
EDIS;
while(ECanaRegs.CANES.bit.CCE != 0 ) {} // Wait for CCE bit to be cleared..
/*-------------------------------------------------------------------------*/
/* Disable all Mailboxes */
ECanaRegs.CANME.all = 0x00000000; // Required before writing the MSGIDs
/*-------------------------------------------------------------------------*/
EALLOW;
ECanaRegs.CANMC.bit.STM = 0; // Configure CAN for normal mode
ECanaRegs.CANMC.bit.DBO = 1;
ECanaRegs.CANMC.bit.ABO = 1;
ECanaRegs.CANMC.bit.PDR = 0;
ECanaRegs.CANMC.bit.WUBA = 0;
EDIS;
ECanaRegs.CANMC.bit.SRES = 0;
ECanaRegs.CANMC.bit.CDR = 0;
ECanaRegs.CANMC.bit.MBNR = 0;
/*-------------------------------------------------------------------------*/
EcanAMboxConfig();
/*-------------------------------------------------------------------------*/
}
/***************************************************************************/
/*-------------------------------------------------------------------------*/
/***************************************************************************/
void EcanAMboxConfig()
{
ECanaRegs.CANME.all = 0x00000000;
ECanaRegs.CANTRR.all = 0xFFFFFFFF;
/*-------------------------------------------------------------------------*/
// configure control fields of mailboxes
ECanaMboxes.MBOX0.MSGCTRL.all = 0x00000000;
ECanaMboxes.MBOX1.MSGCTRL.all = 0x00000000;
ECanaMboxes.MBOX2.MSGCTRL.all = 0x00000000;
ECanaMboxes.MBOX3.MSGCTRL.all = 0x00000000;
ECanaMboxes.MBOX4.MSGCTRL.all = 0x00000000;
ECanaMboxes.MBOX5.MSGCTRL.all = 0x00000000;
ECanaMboxes.MBOX6.MSGCTRL.all = 0x00000000;
ECanaMboxes.MBOX7.MSGCTRL.all = 0x00000000;
ECanaMboxes.MBOX8.MSGCTRL.all = 0x00000000;
ECanaMboxes.MBOX9.MSGCTRL.all = 0x00000000;
ECanaMboxes.MBOX10.MSGCTRL.all = 0x00000000;
ECanaMboxes.MBOX11.MSGCTRL.all = 0x00000000;
ECanaMboxes.MBOX12.MSGCTRL.all = 0x00000000;
ECanaMboxes.MBOX13.MSGCTRL.all = 0x00000000;
ECanaMboxes.MBOX14.MSGCTRL.all = 0x00000000;
ECanaMboxes.MBOX15.MSGCTRL.all = 0x00000000;
ECanaMboxes.MBOX16.MSGCTRL.all = 0x00000000;
ECanaMboxes.MBOX17.MSGCTRL.all = 0x00000000;
ECanaMboxes.MBOX18.MSGCTRL.all = 0x00000000;
ECanaMboxes.MBOX19.MSGCTRL.all = 0x00000000;
ECanaMboxes.MBOX20.MSGCTRL.all = 0x00000000;
ECanaMboxes.MBOX21.MSGCTRL.all = 0x00000000;
ECanaMboxes.MBOX22.MSGCTRL.all = 0x00000000;
ECanaMboxes.MBOX23.MSGCTRL.all = 0x00000000;
ECanaMboxes.MBOX24.MSGCTRL.all = 0x00000000;
ECanaMboxes.MBOX25.MSGCTRL.all = 0x00000000;
ECanaMboxes.MBOX26.MSGCTRL.all = 0x00000000;
ECanaMboxes.MBOX27.MSGCTRL.all = 0x00000000;
ECanaMboxes.MBOX28.MSGCTRL.all = 0x00000000;
ECanaMboxes.MBOX29.MSGCTRL.all = 0x00000000;
ECanaMboxes.MBOX30.MSGCTRL.all = 0x00000000;
ECanaMboxes.MBOX31.MSGCTRL.all = 0x00000000;
/*-------------------------------------------------------------------------*/
// configure ID fields of mailboxes
ECanaMboxes.MBOX0.MSGID.all = CANMBOX0ID;
ECanaMboxes.MBOX1.MSGID.all = 0x1CFF0727;//CANMBOX1ID;
ECanaMboxes.MBOX2.MSGID.all = 0x8CFE08EF;
ECanaMboxes.MBOX3.MSGID.all = 0x8CFE0008;
ECanaMboxes.MBOX4.MSGID.all = CANMBOX4ID;
ECanaMboxes.MBOX5.MSGID.all = 0x1CFF28EF;//CANMBOX5ID;
ECanaMboxes.MBOX6.MSGID.all = CANMBOX6ID;
ECanaMboxes.MBOX7.MSGID.all = CANMBOX7ID;
ECanaMboxes.MBOX8.MSGID.all = 0x8CFE0108;
ECanaMboxes.MBOX9.MSGID.all = 0x8CFE0208;
ECanaMboxes.MBOX10.MSGID.all = 0x8CFE0308;
ECanaMboxes.MBOX11.MSGID.all = CANMBOX11ID;
ECanaMboxes.MBOX12.MSGID.all = CANMBOX12ID;
ECanaMboxes.MBOX13.MSGID.all = CANMBOX13ID;
ECanaMboxes.MBOX14.MSGID.all = CANMBOX14ID;
ECanaMboxes.MBOX15.MSGID.all = CANMBOX15ID;
ECanaMboxes.MBOX16.MSGID.all = CANMBOX16ID;
ECanaMboxes.MBOX17.MSGID.all = CANMBOX17ID;
ECanaMboxes.MBOX18.MSGID.all = CANMBOX18ID;
ECanaMboxes.MBOX19.MSGID.all = CANMBOX19ID;
ECanaMboxes.MBOX20.MSGID.all = CANMBOX20ID;
ECanaMboxes.MBOX21.MSGID.all = CANMBOX21ID;
ECanaMboxes.MBOX22.MSGID.all = CANMBOX22ID;
ECanaMboxes.MBOX23.MSGID.all = CANMBOX23ID;
ECanaMboxes.MBOX24.MSGID.all = CANMBOX24ID;
ECanaMboxes.MBOX25.MSGID.all = CANMBOX25ID;
ECanaMboxes.MBOX26.MSGID.all = CANMBOX26ID;
ECanaMboxes.MBOX27.MSGID.all = CANMBOX27ID;
ECanaMboxes.MBOX28.MSGID.all = CANMBOX28ID;
ECanaMboxes.MBOX29.MSGID.all = CANMBOX29ID;
ECanaMboxes.MBOX30.MSGID.all = CANMBOX30ID;
ECanaMboxes.MBOX31.MSGID.all = CANMBOX31ID;
/*-------------------------------------------------------------------------*/
// configure mask fields of mailboxes
ECanaRegs.CANGAM.bit.AMI = 0;
ECanaLAMRegs.LAM0.all = 0x80000000;
ECanaLAMRegs.LAM1.all = 0x80000000;
ECanaLAMRegs.LAM2.all = 0x80000000;
ECanaLAMRegs.LAM3.all = 0x80000000;
ECanaLAMRegs.LAM4.all = 0x80000000;
ECanaLAMRegs.LAM5.all = 0x80000000;
ECanaLAMRegs.LAM6.all = 0x80000000;
ECanaLAMRegs.LAM7.all = 0x80000000;
ECanaLAMRegs.LAM8.all = 0x00000000;
ECanaLAMRegs.LAM9.all = 0x00000000;
ECanaLAMRegs.LAM10.all = 0x00000000;
ECanaLAMRegs.LAM11.all = 0x00000000;
ECanaLAMRegs.LAM12.all = 0x00000000;
ECanaLAMRegs.LAM13.all = 0x00000000;
ECanaLAMRegs.LAM14.all = 0x00000000;
ECanaLAMRegs.LAM15.all = 0x00000000;
ECanaLAMRegs.LAM16.all = 0x00000000;
ECanaLAMRegs.LAM17.all = 0x00000000;
ECanaLAMRegs.LAM18.all = 0x00000000;
ECanaLAMRegs.LAM19.all = 0x00000000;
ECanaLAMRegs.LAM20.all = 0x00000000;
ECanaLAMRegs.LAM21.all = 0x00000000;
ECanaLAMRegs.LAM22.all = 0x00000000;
ECanaLAMRegs.LAM23.all = 0x00000000;
ECanaLAMRegs.LAM24.all = 0x00000000;
ECanaLAMRegs.LAM25.all = 0x00000000;
ECanaLAMRegs.LAM26.all = 0x00000000;
ECanaLAMRegs.LAM27.all = 0x00000000;
ECanaLAMRegs.LAM28.all = 0x00000000;
ECanaLAMRegs.LAM29.all = 0x00000000;
ECanaLAMRegs.LAM30.all = 0x00000000;
ECanaLAMRegs.LAM31.all = 0x00000000;
/*-------------------------------------------------------------------------*/
// ECanaMboxes.MBOX7.MDL.word.LOW_WORD = 0;
// ECanaMboxes.MBOX7.MDL.word.HI_WORD = 0x0010;
// ECanaMboxes.MBOX7.MDH.word.LOW_WORD = 0;
// ECanaMboxes.MBOX7.MDH.word.HI_WORD = 0;
// ECanbMboxes.MBOX3.MDL.word.LOW_WORD = 0x0010;//20180308
// ECanbMboxes.MBOX3.MDL.word.HI_WORD = 0;
// ECanbMboxes.MBOX3.MDH.word.LOW_WORD = 0;
// ECanbMboxes.MBOX3.MDH.word.HI_WORD = 0;
ECanaMboxes.MBOX2.MDL.word.LOW_WORD = 0;
ECanaMboxes.MBOX2.MDL.word.HI_WORD = 0;
ECanaMboxes.MBOX2.MDH.word.LOW_WORD = 0;
ECanaMboxes.MBOX2.MDH.word.HI_WORD = 0;
ECanaMboxes.MBOX6.MDL.word.LOW_WORD = 0;
ECanaMboxes.MBOX6.MDL.word.HI_WORD = 0;
ECanaMboxes.MBOX6.MDH.word.LOW_WORD = 0;
ECanaMboxes.MBOX6.MDH.word.HI_WORD = 0;
ECanaMboxes.MBOX2.MDH.word.LOW_WORD=5000;
/*-------------------------------------------------------------------------*/
// configure TX and RX mailboxes
ECanaRegs.CANMD.all = 0x0000000D7;//2 receive zhengche,1 6 7 receive shangweiji 4 5 NOTUSED, 3 8 9 10 send TO zhengche,11 12 tiaoshi,13-17shangweiji
//1 shou 0 fa
// ECanbRegs.CANMD.all = 0x000000004;
// ECanbRegs.CANME.all = 0x00003FFFF; //0-17������ʹ��
ECanaRegs.CANME.all = 0x00003FFFF; //0-17������ʹ��
/*----- --------------------------------------------------------------------*/
}
/***************************************************************************/
/*-------------------------------------------------------------------------*/
/***************************************************************************/
// This function reads out the contents of the indicated
// by the Mailbox number (MBXnbr).
void mailbox_readA(int16 MBXnbr)
{
volatile struct MBOX *Mailbox;
Mailbox = &ECanaMboxes.MBOX0 + MBXnbr;
TestAMbox1 = Mailbox->MDL.all; // = 0x9555AAAn (n is the MBX number)
TestAMbox2 = Mailbox->MDH.all; // = 0x89ABCDEF (a constant)
TestAMbox3 = Mailbox->MSGID.all;// = 0x9555AAAn (n is the MBX number)
} // MSGID of a rcv MBX is transmitted as the MDL data.
/***************************************************/
/* Bit configuration parameters for 150 MHz SYSCLKOUT*/
/***************************************************/
/*
The table below shows how BRP field must be changed to achieve different bit
rates with a BT of 15, for a 80% SP:
---------------------------------------------------
BT = 15, TSEG1 = 10, TSEG2 = 2, Sampling Point = 80%
---------------------------------------------------
1 Mbps : BRP+1 = 10 : CAN clock = 15 MHz
500 kbps : BRP+1 = 20 : CAN clock = 7.5 MHz
250 kbps : BRP+1 = 40 : CAN clock = 3.75 MHz
125 kbps : BRP+1 = 80 : CAN clock = 1.875 MHz
100 kbps : BRP+1 = 100 : CAN clock = 1.5 MHz
50 kbps : BRP+1 = 200 : CAN clock = 0.75 MHz
The table below shows how to achieve different sampling points with a BT of 25:
-------------------------------------------------------------
Achieving desired SP by changing TSEG1 & TSEG2 with BT = 25
-------------------------------------------------------------
TSEG1 = 18, TSEG2 = 4, SP = 80%
TSEG1 = 17, TSEG2 = 5, SP = 76%
TSEG1 = 16, TSEG2 = 6, SP = 72%
TSEG1 = 15, TSEG2 = 7, SP = 68%
TSEG1 = 14, TSEG2 = 8, SP = 64%
The table below shows how BRP field must be changed to achieve different bit
rates with a BT of 25, for the sampling points shown above:
1 Mbps : BRP+1 = 6
500 kbps : BRP+1 = 12
250 kbps : BRP+1 = 24
125 kbps : BRP+1 = 48
100 kbps : BRP+1 = 60
50 kbps : BRP+1 = 120
*/
//===========================================================================
// No more.
//===========================================================================