80h: TX | Stuff Error

The free CAN Software API (Application Programming Interface) for Windows®
Post Reply
fenasikerim
Posts: 12
Joined: Fri 8. Nov 2024, 11:16

80h: TX | Stuff Error

Post by fenasikerim » Tue 17. Dec 2024, 09:53

I'm currently trying to write data to my CANBUS line.
$ cat /proc/pcan
*------------- PEAK-System CAN interfaces (www.peak-system.com) -------------
*------------- Release_20240521_n (8.18.0) Dec 13 2024 16:57:39 --------------
*------------- [mod] [isa] [pci] [pec] [dng] [usb] --------------
*--------------------- 4 interfaces @ major 505 found -----------------------
*n -type- -ndev- --base-- irq --btr- --read-- --write- --irqs-- -errors- status
0 pcifd -NA- d391000 380 0x001c 00000001 00000000 00000039 00000380 0x0000
1 pcifd -NA- d392000 380 0x001c 00000000 00000000 00000000 00000000 0x0000
2 pcifd -NA- d393000 380 0x001c 00000000 00000000 00000000 00000000 0x0000
3 pcifd -NA- d394000 380 0x001c 00000000 00000000 00000000 00000000 0x0000
Before that I used to do it in a for loop to set 4 channel;
Init_CAN(UINT8 channel_ID)
{
TPCANBaudrate baudrate = PCAN_BAUD_500K;
DWORD parameter_value = PCAN_PARAMETER_ON;
UINT32 parameter_status = CAN_SetValue(CAN_device, PCAN_LISTEN_ONLY, &parameter_value, 4);
INT32 CAN_device = PCAN_PCIBUS1 + channel_ID;

UINT32 status = CAN_Initialize(CAN_device, baudrate, 0, 0, 0);
return status;
}
now I'm trying to remove LISTEN_ONLY mode and write message to my CANBUS line by doing;
while(true){
TPCANHandle pcan_handler = PCAN_PCIBUS1;
TPCANBaudrate baudrate = PCAN_BAUD_500K;
TPCANStatus status;

status = CAN_Initialize(pcan_handler, baudrate);

TPCANMsg msg;

msg.ID = 0x123;
msg.MSGTYPE = PCAN_MESSAGE_STANDARD;
msg.LEN = 3;
msg.DATA[0] = 1;
msg.DATA[2] = 2;
msg.DATA[2] = 3;

status = CAN_Write(pcan_handler, &msg);

CAN_Uninitialize(pcan_handler);
}
when I run the code and check canAnalyser3 Mini it says
ID(hex) = Error
DLC = 1
Data(hex) = 80h: TX | stuff error

I tried to change msgtype to PCAN_MESSAGE_EXTENDED and set the analyser mini for the extended data but nothing changed. At first, when the LISTEN_ONLY is set I can read data from the line but when I remove it all I get is error can't send any data to the line

M.Maidhof
Support
Support
Posts: 1751
Joined: Wed 22. Sep 2010, 14:00

Re: 80h: TX | Stuff Error

Post by M.Maidhof » Tue 17. Dec 2024, 11:22

Hi,

please check that you use termination resistors on both ends of your CAN cable. A small sleep between write and CAN_Unitialize() could also help, maybe you close the channel before the frame was fully written to the bus.

regards

Michael

fenasikerim
Posts: 12
Joined: Fri 8. Nov 2024, 11:16

Re: 80h: TX | Stuff Error

Post by fenasikerim » Tue 17. Dec 2024, 11:56

Hi Michael, I initialize channel at 500K Baudrate do I need to sleep around 2 microseconds (which equivalents to 500 kHz) ? If I don't put a sleep in between, will the transmission occur at 500 kHz or do I need to run the entire thread at 500 kHz to be able to run at this baudrate?

M.Maidhof
Support
Support
Posts: 1751
Joined: Wed 22. Sep 2010, 14:00

Re: 80h: TX | Stuff Error

Post by M.Maidhof » Tue 17. Dec 2024, 12:00

Hi,

simply use a 1ms sleep, to be sure the frame could be sent on a 500k bus (empty CAN, no arbitration losses!).

How about termination of your cables? A stuff error is mostly a termination issue....

regards

Michael

fenasikerim
Posts: 12
Joined: Fri 8. Nov 2024, 11:16

Re: 80h: TX | Stuff Error

Post by fenasikerim » Wed 18. Dec 2024, 11:39

Okay, I made sure the cable ends with proper resistance and it worked as we expect thank you :) :)

Post Reply