我參考此文件16bit_Language_Tool_Libraries_51456c.pdf
經過些微修改
#define __dsPIC30F6014__
#include<p30f4012.h>
#include<can.h>
#define dataarray 0x1820
int main(void)
{
/* Length of data to be transmitted/read */
unsigned char datalen;
unsigned char Txdata[] =
{'M','I','C','R','O','C','H','I','P','\0'};
unsigned int TXConfig, RXConfig;
unsigned long MaskID,MessageID;
char FilterNo,tx_rx_no;
unsigned char * datareceived = (unsigned char *)
dataarray; /* Holds the data received */
/* Set request for configuration mode */
CAN1SetOperationMode(CAN_IDLE_CON &
CAN_MASTERCLOCK_1 &
CAN_REQ_OPERMODE_CONFIG &
CAN_CAPTURE_DIS);
while(C1CTRLbits.OPMODE <=3);
/* Load configuration register */
CAN1Initialize(CAN_SYNC_JUMP_WIDTH2 &
CAN_BAUD_PRE_SCALE(2),
CAN_WAKEUP_BY_FILTER_DIS &
CAN_PHASE_SEG2_TQ(5) &
CAN_PHASE_SEG1_TQ(4) &
CAN_PROPAGATIONTIME_SEG_TQ(4) &
CAN_SEG2_FREE_PROG &
CAN_SAMPLE1TIME);
/* Load Acceptance filter register */
FilterNo = 0;
CAN1SetFilter(FilterNo, CAN_FILTER_SID(0x1920) &
CAN_RX_EID_EN, CAN_FILTER_EID(0x12344));
/* Load mask filter register */
CAN1SetMask(FilterNo, CAN_MASK_SID(0xFFFF) &
CAN_MATCH_FILTER_TYPE, CAN_MASK_EID(0xFFFFF));
/* Set transmitter and receiver mode */
tx_rx_no = 0;
CAN1SetTXMode(tx_rx_no,
CAN_TX_STOP_REQ &
CAN_TX_PRIORITY_HIGH );
CAN1SetRXMode(tx_rx_no,
CAN_RXFUL_CLEAR &
CAN_BUF0_DBLBUFFER_EN);
/* Load message ID , Data into transmit buffer and set
transmit request bit */
datalen = 8;
CAN1SendMessage((CAN_TX_SID(0x1920)) & CAN_TX_EID_EN &
CAN_SUB_NOR_TX_REQ,
(CAN_TX_EID(0x12344)) & CAN_NOR_TX_REQ,
Txdata,datalen,tx_rx_no);
/* Set request for Loopback mode */
CAN1SetOperationMode(CAN_IDLE_CON & CAN_CAPTURE_DIS &
CAN_MASTERCLOCK_1 &
CAN_REQ_OPERMODE_LOOPBK);
while(C1CTRLbits.OPMODE !=2);
/* Wait till message is transmitted completely */
while(!CAN1IsTXReady(0));
/* Wait till receive buffer contain valid message */
while(!CAN1IsRXReady(0));
/* Read received data from receive buffer and store it into
user defined dataarray */
CAN1ReceiveMessage(datareceived, datalen, tx_rx_no);
while(1);
return 0;
}
這個程式工作在lookback模式
可是我執行時候沒辦法接收到資料
請問程式是否出問題?