智能车制作
标题:
求教,CAN发送不出去!
[打印本页]
作者:
921507436
时间:
2013-6-3 14:42
标题:
求教,CAN发送不出去!
void CAN_Init(void){
CANCTL0 = 0x01; /* MSCAN进入初始化模式 */
while (!(CANCTL1_INITAK)); /* 等待初始化模式确认 */
CANCTL1_CANE = 1; /* Enable MSCAN module */
CANCTL1_CLKSRC = 1; /* MSCAN时钟为总线时钟 */ //振荡器
CANCTL1_LISTEN = 0; /* 正常模式,1:监听模式 */
CANBTR1 = 0x26; // 500kbps (TSEG2<<4) + TSEG1
CANBTR0 =0X41;
CANIDAC_IDAM = 0x1; // Four 16-bit acceptanc filter
// accept all the ID on CAN bus
CANIDMR0 =0xFF;
CANIDMR1 = 0xFF;
CANIDMR2 = 0xFF;
CANIDMR3 = 0xFF;
CANIDMR4 = 0xFF;
CANIDMR5 = 0xFF;
CANIDMR6 = 0xFF;
CANIDMR7 = 0xFF;
CANIDAR0 = 0xFF;
CANIDAR1 = 0xFF;
CANIDAR2 = 0xFF;
CANIDAR3 = 0xFF;
CANIDAR4 = 0xFF;
CANIDAR5 = 0xFF;
CANIDAR6 = 0xFF;
CANIDAR7 = 0xFF;
CANCTL0_INITRQ = 0; /* 退出初始化模式请求 */
while (CANCTL1_INITAK) ; /* 等待进入正常模式*/
while(!(CANCTL0_SYNCH)) ; /*等待CAN同步*/
CANRFLG_RXF = 1; /* 清除接收标志位*/
CANRIER_RXFIE = 1; /* 使能接收满中断*/
}
byte CAN_Send_Frame(mscan_msg_t msg)
{
/* Transmission buffer */
byte u8TxBuffer = {0};
/* Index to data within the transmission buffer */
byte u8Index;
if (!CANTFLG) /* Retrun if Transmit Buffer is full */
return ERR_BUFFER_FULL;
CANTBSEL = CANTFLG; /* Select lowest empty buffer */
u8TxBuffer = CANTBSEL; /* Backup selected buffer */
*((dword *) ((dword)(&CANTXIDR0)))= msg.u32ID; /* Load Id to IDR Registers */
/* Load data to Data Segment Registers */
for (u8Index=0;u8Index<(msg.u8Length);u8Index++) {
*(&CANTXDSR0 + u8Index) = (msg.u8TxData)[u8Index];
}
CANTXDLR = msg.u8Length; /* Set Data Length Code */
CANTXTBPR = msg.u8Prio; /* Set Priority */
CANTFLG = u8TxBuffer; /* Start transmission */
//CANTARQ= u8TxBuffer;
while ( (CANTFLG & u8TxBuffer) != u8TxBuffer)
; /* Wait for Transmission completion */
return NO_ERR;
}
作者:
921507436
时间:
2013-6-3 14:50
当发送时程序一直死在while ( (CANTFLG & u8TxBuffer) != u8TxBuffer)
CAN上位机数据接收到的是错误,不知道为什么!!!!!!!!!!!!!
作者:
易寒
时间:
2014-4-1 10:08
加个分号试试
作者:
张世民
时间:
2014-4-3 23:35
过来瞧瞧啊 哈哈哈过来瞧瞧啊 哈哈哈
作者:
zhifu
时间:
2015-8-20 21:16
我是能发不能接收啊?
欢迎光临 智能车制作 (http://111.231.132.190/)
Powered by Discuz! X3.2