Cannot read CAN_FD frames through python API

CAN FD Interface for High-Speed USB 2.0
Post Reply
CANuser76
Posts: 1
Joined: Wed 19. Jul 2023, 16:45

Cannot read CAN_FD frames through python API

Post by CANuser76 » Wed 19. Jul 2023, 17:29

Hello,

I have issues using PCANbasic API for CAN_FD for Python (I don't have any issues for normal CAN).
First of all, I don't have any issues through PCAN View, I can read and write CAN_FD frames.
But through my python script, I can send frames but when I try to read frames it doesn't work. I just receive three time a frame with these information :
ID = 1, DLC = 4, DATA = 0 (which looks like a status message)
After that, I receive a 0x20 status (empty queue).
Whereas, I should receive many frames every 100ms with different ID, not empty datas and DLC = 16.

Here's the configuration that work with PCAN view :

Code: Select all

Clock = 80MHz

Nominal : 
BR = 1M/s
Sample point = 87.5%
Prescaler = 1
TSEG1 = 69
TSEG2 = 10
SJW = 10
tqs = 12.5ns
Nq = 80

DATA: 

BR = 5M/s
Sample point = 87.5%
Prescaler = 1
TSEG1 = 13
TSEG2 = 2
SJW = 2
tqs = 12.5ns
Nq = 16
Here's the configuration used in the API :

Code: Select all

b"f_clock_mhz=80, nom_brp=1, nom_tseg1=69, nom_tseg2=10, nom_sjw=10, nom_sam=87.5, data_brp=5, data_tseg1=13, data_tseg2=2, data_sjw=2, data_ssp_offset=87.5"
I think the problem is coming from nom_sam and data_ssp_offset as it's not totaly the same thing but I tried with different value and it didn't work.
When I read my configuration all the parameters are good except nom_sam which is =1 and data_ssp_offset which is = 0.
Could you help me please.
Have a great day !
Last edited by K.Wagner on Thu 20. Jul 2023, 08:23, edited 1 time in total.
Reason: Code formatting for better reading

K.Wagner
Software Development
Software Development
Posts: 1082
Joined: Wed 22. Sep 2010, 13:36

Re: Cannot read CAN_FD frames through python API

Post by K.Wagner » Thu 20. Jul 2023, 08:55

Hello,
CANuser76 wrote:
Wed 19. Jul 2023, 17:29
Here's the configuration used in the API :
b"f_clock_mhz=80, nom_brp=1, nom_tseg1=69, nom_tseg2=10, nom_sjw=10, nom_sam=87.5, data_brp=5, data_tseg1=13, data_tseg2=2, data_sjw=2, data_ssp_offset=87.5"
I think the problem is coming from nom_sam and data_ssp_offset as it's not totaly the same thing but I tried with different value and it didn't work.
The bit rate string parameter you posted represents 1MB nominal and 1 MB data (not 5 MB) - it also contains unknown/not_used values that are just ignored. If you connect two nodes with a different bit rate for the data phase and you send messages with bit rate switch, your bus will probably go bus-off, so you will receive nothing but error frames (if configuried to get them). A correct bit rate string for 1MB/5MB with 87,5% sample point for both nominal and data phase, will be:

Code: Select all

f_clock=80000000,nom_brp=1,nom_tseg1=69,nom_tseg2=10,nom_sjw=10,data_brp=1,data_tseg1=13,data_tseg2=2,data_sjw=2
For the furtue, if you want to get a correct bit rate string value, you can do this in two easy ways:
  1. Connect the PCAN-View to the bit rate that works for you, and then copy the bit rate configuration to the clipboard. Then use that values within your PCAN-Basic connection (* see pitcutre bellow).
  2. Use our Bit rate Calculation tool, that can be downloaded here.
Attachments
PCAN-View.PNG
PCAN-View.PNG (57.24 KiB) Viewed 5863 times
Best regards,
Keneth

Post Reply