[En-Nut-Discussion] SJA1000
Petri Hyötylä
phyotyla at cc.hut.fi
Wed Aug 29 11:08:04 CEST 2007
Thank you for quick and helpful response.
I am using a solderless breadboard and one wire was misplaced.
Now I have another problem. I am testing the CAN-circuit with
Peak System CAN debugger (Opto-decoupled USB-CAN Interface,
www.peak-system.com)
and I noticed a small discrepancy with it. I wrote some code that
sends the frames that it receives back to the bus with identical ID
and slightly altered
data bytes.
It seems that it works when I send frames with extended ID but when I send
frames with standard ID it returns a frame with ID with bits shifted
three bits
right. I guess that was not the best way to describe it but maybe
example helps.
Sent ID means the ID that the debugger sends and so on.
Sent ID: 0x050 (0000 0101 0000)
Received ID: 0x00A (0000 0000 1010)
Sent ID: 0x500 (0101 0000 0000)
Received ID: 0x0A0 (0000 1010 0000)
I tested with about 50 different combinations but I guess these two examples
suffice. Please Help. The code I used follows.
---------------------------------------------------------------------------
CANFRAME txCanFrame;
CANFRAME rxCanFrame;
CANINFO *canInfoPtr;
int main(void)
{
u_short base_address = 0x8000;
NutRegisterDevice(&devSJA1000, base_address, 0);
// Set CAN bit rate
CAN_SetSpeed(&devSJA1000, CAN_SPEED_125K);
// Prepare a sample frame for sending
memset(&txCanFrame, 0, sizeof(txCanFrame));
txCanFrame.id = 0x123;
txCanFrame.len = 8;
txCanFrame.ext = 0; // Set to 1 to send an extended frame
txCanFrame.byte[0] = 0x11;
txCanFrame.byte[1] = 0x22;
txCanFrame.byte[2] = 0x33;
txCanFrame.byte[3] = 0x44;
txCanFrame.byte[4] = 0x55;
txCanFrame.byte[5] = 0x66;
txCanFrame.byte[6] = 0x77;
txCanFrame.byte[7] = 0x88;
while(1)
{
CAN_TxFrame(&devSJA1000, &txCanFrame);
CAN_RxFrame(&devSJA1000, &rxCanFrame);
txCanFrame.id = rxCanFrame.id;
txCanFrame.len = 8;
txCanFrame.ext = rxCanFrame.ext;
txCanFrame.byte[0] = rxCanFrame.byte[0]+1;
txCanFrame.byte[1] = rxCanFrame.byte[1]+1;
txCanFrame.byte[2] = rxCanFrame.byte[2]+1;
txCanFrame.byte[3] = rxCanFrame.byte[3]+1;
txCanFrame.byte[4] = rxCanFrame.byte[4]+1;
txCanFrame.byte[5] = rxCanFrame.byte[5]+1;
txCanFrame.byte[6] = rxCanFrame.byte[6]+1;
txCanFrame.byte[7] = rxCanFrame.byte[7]+1;
NutSleep(2000);
}
return 0;
}
--
Petri
More information about the En-Nut-Discussion
mailing list