CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

18F47Q84 - CAN FD issue -can_putd() -> CAN_EC_OBJ_TX_FULL

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
pet007



Joined: 25 Jan 2023
Posts: 21

View user's profile Send private message

18F47Q84 - CAN FD issue -can_putd() -> CAN_EC_OBJ_TX_FULL
PostPosted: Wed Apr 10, 2024 9:40 am     Reply with quote

Hi, pls I have problem with can_put() function, when I'm debuging it, it returns this error value:
Code:

..
   //Check TFNRFNIF bit in C1FIFOSTAm register to determine if FIFO is full
   if(pFIFOSta->TFNRFNIF == 0)
   {
     
      return(CAN_EC_OBJ_TX_FULL);
   }

If I turn CAN_OPERATION_MODE to 1 (CAN 2.0B), everything is working fine, as well as Rx filters are working well on CAN FD. My config in main.h:

Code:

#include <18F47Q84.h>
#device ADC=12
#device ICD=TRUE           
#use delay(internal=64MHz)

// -------------------------------------------------
//  === CANBUS config ===   Start
// -------------------------------------------------
#define CAN_SPEED                        1000      // kBit
#define CAN_TX_PIN                     PIN_B2     
#define CAN_RX_PIN                     PIN_B3       // DEFAULT
#define CAN_OPERATION_MODE              0      // 1 - CAN 2.0B , 0 - CANFD -> nefunguje, jen s CAN 2.0B   
#define CAN_NOMINAL_BAUD_RATE       CAN_SPEED*1000  // v b/s
#define CAN_DATA_BAUD_RATE                  0     
#define CAN_TIME_BASE_COUNTER_PRESCALAR    64       
//#define CAN_TX_BUFFERS                   8         // 1-32
#define CAN_TX_MAX_PAYLOAD_SIZE          PAYLOAD_SIZE_64_BYTES
//#define CAN_CLOCK_SPEED                64*1000000   // 64Mhz - kdyz nic, sam vezme akt. CLOCK

// CAN RX - Filter 1 - ID=0x20-0x27
#define CAN_USE_FILTERS          TRUE
#define CAN_USER_FILT_0          0x20 
#define CAN_USER_MASK_0          0x1FFFFFF8   0x20-0x27 -bity [0:3]
#define CAN_USER_FILT_0_TYPE     CAN_FILTER_TYPE_SID_ONLY   // 
#define CAN_USER_FILT_0_OBJECT   CAN_OBJECT_FIFO_1
// CAN RX - Filter 2 - ID=0x120-0x127
#define CAN_USER_FILT_1          0x120     
#define CAN_USER_MASK_1          0x1FFFFFF8        // 0x120-0x127 maskujeme bity [0:3]
#define CAN_USER_FILT_1_TYPE     CAN_FILTER_TYPE_SID_ONLY   
#define CAN_USER_FILT_1_OBJECT   CAN_OBJECT_FIFO_2

#include <can-pic18_fd.c>      // must be here afters define
// -------------------------------------------------
//  === CANBUS config ===   End
// -------------------------------------------------



and then in main.c (working well in CAN 2.0 B mode and max. 8 bytes payload of course)

...


Code:


void CAN_Send_ADC_mV(u32 ID) //, tADC ADC)  // posle 3x pakety s ID, ID+1, ID+2 , kazdy posila 4xU16 ADC resulty v mV, celkem tedy 3x4 = 12x ADC U16 v mV
{
    #define LEN    8
    CAN_TX_HEADER CanTx;   
    u8 bufTx[LEN],i=0;
   
   
    CanTx.Length = LEN; CanTx.ext = 1; CanTx.Format = CAN_MESSAGE_FORMAT_CAN_FD;
    CanTx.Id = ID;
 
     for (i=0; i<LEN; i++)
     {
       bufTx[i] = i;     
     }
     can_putd(&CanTx, bufTx);     
     
}


I have some wrong settings for CAN_OBJECT_TXQ FIFO buffer probably, but I'm a bit confused, where/what FIFO to set it up correctly.

Thanks for any help.
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Wed Apr 10, 2024 11:25 am     Reply with quote

CAN FD _requires_ the longer CAN 2.0B address field. So needs 1 selected....
pet007



Joined: 25 Jan 2023
Posts: 21

View user's profile Send private message

PostPosted: Wed Apr 10, 2024 11:59 am     Reply with quote

Hmm, not understand yet......
The longer ID isn't a problem - I'd like to use CAN FD due bigger payload (up to 64 bytes instead of 8 for Can 2.0 B)....
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Wed Apr 10, 2024 1:14 pm     Reply with quote

Does the chip you are using have a peripheral that supports FD???

The standard CCS software does not support FD. You have to be using
the FD drivers can-dspic33_fd.c, for the PIC24/33 with an FD peripheral,
or can-mcp2517.c for the external FD peripheral. Using the MCP2517FD.
The normal PIC CAN hardware does not support this.
pet007



Joined: 25 Jan 2023
Posts: 21

View user's profile Send private message

PostPosted: Wed Apr 10, 2024 10:46 pm     Reply with quote

Of course the PIC18F47Q84 is capable to handle CAN Flexible Data. (My transceiver AT6560 is CAN FD ready too). HW isn't an issue IMHO..
When I call getenv("CAN"), it returns 3 -> CANFD peripheral is present.
I'm using can-pic18_fd.c driver...
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Thu Apr 11, 2024 1:25 am     Reply with quote

So you are using the can-dspic33_fd.c driver?.
pet007



Joined: 25 Jan 2023
Posts: 21

View user's profile Send private message

PostPosted: Thu Apr 11, 2024 2:01 am     Reply with quote

Ttelmah wrote:
So you are using the can-dspic33_fd.c driver?.

Smile No, it's already noted in previous post -
Quote:
I'm using can-pic18_fd.c driver...
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Thu Apr 11, 2024 7:30 am     Reply with quote

OK. Great. However it still goes back to the fact you cannot use CAN FD,
and set CAN_OPERATION_MODE to 0.. Using FD requires the operating
mode to be 2.0b. The FD driver supports programming the FD peripheral to
non FD modes. This is what you are doing.
pet007



Joined: 25 Jan 2023
Posts: 21

View user's profile Send private message

PostPosted: Thu Apr 11, 2024 7:39 am     Reply with quote

Hmm I'm still confused. But in 2.0b mode I can't use more than 8bytes as payload, can I ?
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Thu Apr 11, 2024 11:19 am     Reply with quote

The point is you don't want to switch the device down to 2.0a mode,
you need to leave it in FD mode, and then the format of the packet
determines how the system behaves. 64byyte data is only supported
when FD mode is selected.
pet007



Joined: 25 Jan 2023
Posts: 21

View user's profile Send private message

PostPosted: Thu Apr 11, 2024 1:55 pm     Reply with quote

In file can-pic18_fd.h is written:
Code:

PREPROCESSORS:
   ----------------------------------------------------------------------------   
   CAN_OPERATION_MODE
      The CAN operational mode of peripheral after can_init() is called,
      0 - CAN FD mode or 1 - CAN 2.0 mode.  Defaults to CAN FD mode.
...
...
...

#ifndef __CAN_PIC18_FD_H__
#define __CAN_PIC18_FD_H__

#define CAN_DEVICE_HAS_FD

#include <stdint.h>

#ifndef CAN_OPERATION_MODE
 #define CAN_OPERATION_MODE   0  //0-CAN FD, 1-CAN 2.0
#endif
   


- it means, if there is this definition in my main.h :
#define CAN_OPERATION_MODE 0 = > CAN FD mode
then MCU is operating in CAN FD mode (or it should).

Note: CAN 2.0A or CAN 2.0B are the same in payload question - both are able to transfer only 8 bytes, only difference is that CAN 2.0B is able to use 29bit extended ID (instead of only 11bit for CAN 2.0A).

So the question is still the same - if is it possible with this driver (can-pic18_fd.c) to switch this MCU into working CAN FD mode...
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Thu Apr 11, 2024 2:29 pm     Reply with quote

So what does the bus support?
You do understand that if you are talking to a CAN2 peripheral, you can
select FD, but the bus will switch down to CAN2 mode, and only support
a CAN2 packet?. So no 64byte data. A CAN FD master can normally only
use CAN FD packets on a bus that is only using CAN FD.
A CAN FD bus cannot support simultaneous CAN2 and CAN FD messages.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group