• slider image 514
  • slider image 516
  • slider image 517
  • slider image 518
  • slider image 519
:::


Browsing this Thread:   1 Anonymous Users






請問文件上CAN的C CODE使否有問題
#1
新會員
新會員


查看用戶資訊
我參考此文件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模式
可是我執行時候沒辦法接收到資料
請問程式是否出問題?

發表於: 2006/7/31 15:42
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部







You can view topic.
不可以 發起新主題
You cannot reply to posts.
You cannot edit your posts.
You cannot delete your posts.
You cannot add new polls.
You cannot vote in polls.
You cannot attach files to posts.
You cannot post without approval.
You cannot use topic type.
You cannot use HTML syntax.
You cannot use signature.
You cannot create PDF files.
You cannot get print page.

[進階搜尋]


:::

Microchip連結

https://www.facebook.com/microchiptechnologytaiwan/
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=13
https://mu.microchip.com/page/tmu
http://elearning.microchip.com.tw/modules/tad_link/index.php?cate_sn=1
https://page.microchip.com/APAC-PrefCenters-TW.html
http://www.microchip.com/
http://www.microchip.com/treelink
http://www.microchipdirect.com/
http://www.microchip.com.cn/newcommunity/index.php?m=Video&a=index&id=103
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=2
http://www.microchip.com.tw/Data_CD/eLearning/index.html
http://www.microchip.com.tw/RTC/RTC_DVD/
https://www.microchip.com/development-tools/
https://www.youtube.com/user/MicrochipTechnology
[ more... ]

教育訓練中心

!開發工具購買
辦法說明 [業界客戶] [教育單位]
----------------------------------
!校園樣品申請
辦法說明 [教師資格] [學生資格]
----------------------------------