本帖最后由 yanrenwu1989 于 2010-11-4 09:44 编辑
本人所使用的是lpc23xx系列的can开发板,板子的具体型号是MCU123,用它来做can实验,所使用的程序是开发板所自带的程序,程序如下:
int main( void )
{
CAN_Init( BITRATE100K28_8MHZ );
#if !ACCEPTANCE_FILTER_ENABLED
// Initialize MsgBuf
MsgBuf_TX1.Frame = 0x80080000; // 29-bit, no RTR, DLC is 8 bytes
MsgBuf_TX1.MsgID = 0x00012345; // CAN ID
MsgBuf_TX1.DataA = 0x3C3C3C3C;
MsgBuf_TX1.DataB = 0xC3C3C3C3;
MsgBuf_RX2.Frame = 0x0;
MsgBuf_RX2.MsgID = 0x0;
MsgBuf_RX2.DataA = 0x0;
MsgBuf_RX2.DataB = 0x0;
CAN_SetACCF( ACCF_BYPASS );
/* Test bypass */
while ( 1 )
{
// Transmit initial message on CAN 1
while ( !(CAN1GSR & (1 << 3)) );
if ( CAN1_SendMessage( &MsgBuf_TX1 ) == FALSE )
{
continue;
}
if ( CAN2RxDone == TRUE )
{
CAN2RxDone = FALSE;
if ( MsgBuf_RX2.Frame & (1 << 10) ) /* by pass mode */
{
MsgBuf_RX2.Frame &= ~(1 << 10 );
}
if ( ( MsgBuf_TX1.Frame != MsgBuf_RX2.Frame ) ||
( MsgBuf_TX1.MsgID != MsgBuf_RX2.MsgID ) ||
( MsgBuf_TX1.DataA != MsgBuf_RX2.DataA ) ||
( MsgBuf_TX1.DataB != MsgBuf_RX2.DataB ) )
{
while ( 1 );
}
// Everything is correct, reset buffer
MsgBuf_RX2.Frame = 0x0;
MsgBuf_RX2.MsgID = 0x0;
MsgBuf_RX2.DataA = 0x0;
MsgBuf_RX2.DataB = 0x0;
} // Message on CAN 2 received
}
#else
MsgBuf_TX1.Frame = 0x00080000; // 11-bit, no RTR, DLC is 8 bytes
MsgBuf_TX1.MsgID = EXP_STD_ID; // Explicit Standard ID
MsgBuf_TX1.DataA = 0x55AA55AA;
MsgBuf_TX1.DataB = 0xAA55AA55;
MsgBuf_RX2.Frame = 0x0;
MsgBuf_RX2.MsgID = 0x0;
MsgBuf_RX2.DataA = 0x0;
MsgBuf_RX2.DataB = 0x0;
CAN_SetACCF( ACCF_ON );
while ( 1 )
{
// Transmit initial message on CAN 1
while ( !(CAN1GSR & (1 << 3)) );
if ( CAN1_SendMessage( &MsgBuf_TX1 ) == FALSE )
{
continue;
}
if ( CAN2RxDone == TRUE )
{
CAN2RxDone = FALSE;
if ( ( MsgBuf_TX1.MsgID != MsgBuf_RX2.MsgID ) ||
( MsgBuf_TX1.DataA != MsgBuf_RX2.DataA ) ||
( MsgBuf_TX1.DataB != MsgBuf_RX2.DataB ) )
{
while ( 1 );
}
// Everything is correct, reset buffer
MsgBuf_RX2.Frame = 0x0;
MsgBuf_RX2.MsgID = 0x0;
MsgBuf_RX2.DataA = 0x0;
MsgBuf_RX2.DataB = 0x0;
} // Message on CAN 2 received
}
#endif
}
我用这个程序做自发自收的实验时,用keil单步运行,不能看到正确的结果!CAN2总是接收不到数据!于是我又买了一块周公的CAN232MB,用lpc23xx的板子发,周公的板子接收,程序是把上面程序的红色部分去掉余下的部分的程序。但是还是接收不到数据,我调试看了下好像是没有进入接收中断,不知道这是怎么回事!
补充一下,上面的程序中ACCEPTANCE_FILTER_ENABLED值为1,也就是蓝色部分程序无效,没有运行!
希望高人能解答!急急急!!! |