我用C8051F506 的CAN通讯, 用USB-CAN 工具总看不数据,然后我用官方的历程,也看不到数据,好像是有错误,然后就不发送了~ 我初次用CAN 初次用C8051的,求解答,谢谢,我打算用这和SJA1000的经典电路通讯。。
我测试CAN TX 单片机的IO 发现也是 仅2个字节后 就没有数据发送了
我不明白这个怎么设置帧类型?需要设置吗?我看SJA1000 有设置帧类型的
我电路是:单片机CAN光 耦隔离,接82C250,
我问过技术支持,他们说,发送程序单独是发送不出去?? 需和接收程序的板子连接后,才发送成功! 为什么、、
初始化是官方例程一样呀。
void CAN0_Init (void)
{
U8 iter;
U8 SFRPAGE_save = SFRPAGE;
SFRPAGE = CAN0_PAGE; // All CAN register are on page 0x0C
CAN0CN |= 0x01; // Start Intialization mode
//---------Initialize general CAN peripheral settings
CAN0CN |= 0x4E; // Enable Status, Error,
// Module Interrupts
// Enable access to bit timing register
// See the CAN Bit Timing Spreadsheet for how to calculate this value
CAN0BT = 0x1402; // Based on 24 Mhz CAN clock, set the
// CAN bit rate to 1 Mbps
//---------Initialize settings common to all message objects
// Command Mask Register
CAN0IF1CM = 0x00F0; // Write Operation
// Transfer ID Mask, MDir, MXtd
// Transfer ID, Dir, Xtd, MsgVal
// Transfer Control Bits
// Don't set TxRqst or transfer data
// Mask Registers
CAN0IF1M1 = 0x0000; // Mask Bits 15-0 not used for filtering
CAN0IF1M2 = 0x5FFC; // Ignore Extended Identifier for
// filtering
// Used Direction bit for filtering
// Use ID bits 28-18 for filtering
// Arbitration Registers
CAN0IF1A1 = 0x0000; // 11-bit ID, so lower 16-bits not used
// Message Control Registers
CAN0IF1MC = 0x0880 | MESSAGE_SIZE; // Enable Transmit Interrupt
// Message Object is a Single Message
// Message Size set by #define
//---------Initialize unique settings for each valid message object
for (iter = 0; iter < MESSAGE_OBJECTS; iter++)
{
// For example purposes, set 11-bit identifier based on the message
// object that is used to send it.
// Arbitration Registers
CAN0IF1A2 = 0xA000 | (iter << 2); // Set MsgVal to valid
// Set Direction to write
// Set 11-bit Identifier to iter
CAN0IF1CR = iter; // Start command request
while (CAN0IF1CRH & 0x80) {} // Poll on Busy bit
}
//---------Initialize settings for unused message objects
for (iter = MESSAGE_OBJECTS; iter < 32; iter++)
{
// Set remaining message objects to be Ignored
CAN0IF1A2 = 0x0000; // Set MsgVal to 0 to Ignore
CAN0IF1CR = iter; // Start command request
while (CAN0IF1CRH & 0x80) {} // Poll on Busy bit
}
CAN0CN &= ~0x41; // Return to Normal Mode and disable
// access to bit timing register
SFRPAGE = SFRPAGE_save;
} |