• slider image 442
  • slider image 483
  • slider image 484
  • slider image 485
  • slider image 486
  • slider image 487
:::


Browsing this Thread:   1 Anonymous Users






Re: can18xx8.c 的程式有問題嘛?
#2
管理員
管理員


查看用戶資訊
你好,

這其中的玄機就在於 CANCON 暫存器的 bit 1 .. bit 3 啦.
因為 PIC18F 為了要有效率的存取各組不同的 buffer (包括 RXB0 , RXB1 , TXB0..TXB2 ) , 就採取了將大家都可以被 Mapping 到 RXB0 的機制 , 此機制由 CANCON 的 bit 1..3 控制.
所以在程式的一開頭有先對 CANCON bit 1..3 做 & and | 的動作 , 就是要將指定的 TX Buffer Mapping 到 RXB0 的區間. 如此一來就可以較快的 Access TX Buffer 的資料了 ( RXB0 的位址位於 PIC18F 的 Access Buffer 區間 , 最有效率 )

希望您的問題能因此有所解決 :)

發表於: 2008/3/3 11:11
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


can18xx8.c 的程式有問題嘛?
#1
初級會員
初級會員


查看用戶資訊
各位好
我在適用 can-bus 的部分
在看附上的 can18xx8.c 的程式裡面
我發現在 CanSendMessage 這個 function 裡面
都再利用一些 RXB0CON 的 buffer

我想問的,在傳出資料,應該要動的是 TXB0CON 而不是 RX

以下是程式碼

BOOL CANSendMessage(unsigned long id,
BYTE* Data,
BYTE DataLen,
enum CAN_TX_MSG_FLAGS MsgFlags)
{
BYTE i;
BYTE *ptr;

// Find the first empty transmitter.
if ( TXB0CON_TXREQ == 0 )
{
// TxBuffer0 is empty. Set WIN bits to point to TXB0
CANCON &= 0b11110001;
CANCON |= 0b00001000;
}
else if ( TXB1CON_TXREQ == 0 )
{
// TxBuffer1 is empty. Set WIN bits to point to TXB1
CANCON &= 0b11110001;
CANCON |= 0b00000110;
}
else if ( TXB2CON_TXREQ == 0 )
{
// TxBuffer2 is empty. Set WIN bits to point to TXB2
CANCON &= 0b11110001;
CANCON |= 0b00000100;
}
else
// None of the transmit buffers were empty.
return FALSE;

/*
* Now that WIN has remapped RXB0 to empty buffer, simply
* populate RXB0 buffer
*/

// Set transmit priority.
RXB0CON = MsgFlags & CAN_TX_PRIORITY_BITS;

// Populate Extended identifier information only if it is
// desired.
if ( !(MsgFlags & CAN_TX_FRAME_BIT) )
CANIDToRegs((BYTE*)&RXB0SIDH, id, CAN_CONFIG_XTD_MSG);
else
CANIDToRegs((BYTE*)&RXB0SIDH, id, CAN_CONFIG_STD_MSG);

RXB0DLC = DataLen;

if ( !(MsgFlags & CAN_TX_RTR_BIT) )
RXB0DLC |= 0b01000000;

// Populate data values.
ptr = (BYTE*)&RXB0D0;
for ( i = 0; i < DataLen; i++ )
ptr[i] = Data[i];

/*
* Mark this buffer as ready to start transmit.
* We are not using C bit field structure because RXB0 registers
* are remapped to one of the empty transmit buffers and their
* bit3 is not same as RXB0CON bit3. To avoid confusion, in-line
* assembly is used to directly set bit 3 of corresponding TXBnCON
* register.
*/
#if defined(MCHP_C18)
_asm
bsf RXB0CON, 3, 0
_endasm
#endif
#if defined(HITECH_C18)
asm("bsf _RXB0CON,3");
#endif

/*
* Restore CAN buffer mapping so that subsequent access to RXB0
* buffers are to the real RXB0 buffer.
*/
CANCON &= 0b11110001;

return TRUE;
}


我用紅色的部分標示我說的地方
謝謝

發表於: 2008/2/27 17:15
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... ]

教育訓練中心

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