can18xx8.c 的程式有問題嘛?
|
||||
---|---|---|---|---|
初級會員
|
各位好
我在適用 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
|
|||
|