CAN Bus Example

General discussion on mikroC PRO for FT90x.
Post Reply
Author
Message
superglitch
Posts: 7
Joined: 22 Jul 2015 19:19

CAN Bus Example

#1 Post by superglitch » 22 Jul 2015 20:24

Hey guys, if you can't tell by this post, I'm a n00b when it comes to this low level of hardware programming. I was able to get myself familiar with the clicker 2 board starting from other examples, but nothing goes over what I really bought the board for, CAN bus.

Is there any examples of getting the CAN Bus modules working? Even if it's just for a single write or read that would be great.

In the case that there isn't, I'm for right now just trying to send out a simple write, which I should see on my CAN logger (which has been verified to work correctly on many other applications), or even on my oscilloscope.

I have found the documentation and it appears that CAN_SysInit must be called first. It says that CAN0 or CAN1 must be passed, but in the ft900.c file I can't find any definitions for the CAN modules or a CANStruct variable.

The example in the documentation shows as:

Code: Select all

// initialize system registers for CAN0 module usage
CAN_SysInit(&CAN0);
Obviously this cannot be compiled as CAN0 cannot be resolved to a definition.

Sorry if this seems extremely stupid, but I've always been in a well documented product area when developing in the past (Arduino mostly). Thanks for your help!

User avatar
marina.petrovic
Posts: 2986
Joined: 18 Apr 2013 08:11

Re: CAN Bus Example

#2 Post by marina.petrovic » 23 Jul 2015 11:07

Hi,

In mikroC PRO for FT90x Example folder you can find the CAN SPI example written for clicker 2 for FT90x:
...\mikroC PRO for FT90x\Examples\Clicker 2 for FT90x\CANSPI

and CAN example written for EasyFT90x v7:
...\mikroC PRO for FT90x\Examples\EasyFT90x V7\CAN

You can take a look at this examples and use them as a starting point for your projects.

Best regards,
Marina

superglitch
Posts: 7
Joined: 22 Jul 2015 19:19

Re: CAN Bus Example

#3 Post by superglitch » 23 Jul 2015 17:09

Awesome thank you. Yesterday I was able to find the address by referencing the datasheet, but the EasyFT90x example is great, why isn't this part of the Clicker2 examples? It compiles and runs decent, problem I'm stuck at is that I will need a CAN transceiver, for now it's just infinite looping trying to send a message. The transceiver should be here tomorrow.

superglitch
Posts: 7
Joined: 22 Jul 2015 19:19

Re: CAN Bus Example

#4 Post by superglitch » 27 Jul 2015 17:18

Is there anyway to get better documentation on how to use the library properly? The easy ft90x example requires that you have two FT90x devices, which I do not, so I'm not even sure if it works correctly.

If we can not get updated documentation can you answer the following?

What is the difference between CAN_SysInit and CAN_Init, do both need to be called?

If no filter is set, does the module listen to all messages? Or does there need to be a "pass all" filter set?

Thanks!

superglitch
Posts: 7
Joined: 22 Jul 2015 19:19

Re: CAN Bus Example

#5 Post by superglitch » 27 Jul 2015 18:41

Well I was able to get a message on the bus that my CAN logger is picking up, but rather than sending one message it's sending it repeatedly.

I think the repeating problem is more of my little understanding of CAN on this low of level, hopefully more reading will clear this up, or if anyone has any idea that would be great.

Here's the code I was able to use get it working (hopefully it helps someone in the future):

Code: Select all

CAN_SysInit(CAN1);
  
if(CAN_ERROR == CAN_Init(CAN1, 500))
{
  return;
}

TCANMsg  msg; 
msg.frameFormat = CAN_STD_FRAME;
msg.RTR    = 0;
msg.ID     = 0x0740;
msg.len    = 2;
msg.buf[0] = 0xaa;
msg.buf[1] = 0xbb;
  
if(CAN_OK != CAN_PushMessage(CAN1, &msg))
{
   return;
}

superglitch
Posts: 7
Joined: 22 Jul 2015 19:19

Re: CAN Bus Example

#6 Post by superglitch » 27 Jul 2015 21:37

Well must be something to do with the wiring, when I hook up my ECU to the bus, everything works great.

P.S. don't forget your Mask and Filters.

superglitch
Posts: 7
Joined: 22 Jul 2015 19:19

Re: CAN Bus Example

#7 Post by superglitch » 28 Jul 2015 17:23

Well when heavily loading the CAN Bus (via other devices), I'm getting a lot of weird errors. Are there any examples to implement interrupt handlers with this library?

User avatar
Aleksandar.Mitrovic
mikroElektronika team
Posts: 1697
Joined: 11 Mar 2015 12:48

Re: CAN Bus Example

#8 Post by Aleksandar.Mitrovic » 29 Jul 2015 16:24

Hi,

If you need some example for external interrupt I suggest you to take a look at our compiler example folder:
...\Mikroelektronika\mikroC PRO for FT90x\Examples\Internal MCU modules\External Interrupt

Best regards,
Aleksandar

superglitch
Posts: 7
Joined: 22 Jul 2015 19:19

Re: CAN Bus Example

#9 Post by superglitch » 29 Jul 2015 19:15

Thank you for the example.

Now I cannot get interrupts to work, seems to be a mismatch of the given vector table the documented table from FTDI.

Here's what is defined in MikroE library's FT900.c:

Code: Select all

const IVT_WDT_IRQ                 = 1;
const IVT_PM_IRQ                  = 2;
const IVT_EHCI_IRQ                = 3;
const IVT_DUSB2_IRQ               = 4;
const IVT_DMAC_IRQ                = 5;
const IVT_SDHOST_IRQ              = 6;
const IVT_CAN1_IRQ                = 7;
const IVT_CAN2_IRQ                = 8;
const IVT_CAM_IRQ                 = 9;
const IVT_SPIM_IRQ                = 10;
const IVT_SPIS1_IRQ               = 11;
const IVT_SPIS2_IRQ               = 12;
const IVT_I2CM_IRQ                = 13;
const IVT_I2CS_IRQ                = 14;
const IVT_UART1_IRQ               = 15;
const IVT_UART2_IRQ               = 16;
const IVT_I2S_IRQ                 = 17;
const IVT_PWM_IRQ                 = 18;
const IVT_TIMERS_IRQ              = 19;
const IVT_GPIO_IRQ                = 20;
const IVT_RTC_IRQ                 = 21;
const IVT_ADC_IRQ                 = 22;
const IVT_DAC_IRQ                 = 23;
const IVT_SLOWCLK_IRQ             = 24;
const IVT_INT_RESERVED1           = 25;
const IVT_INT_RESERVED2           = 26;
const IVT_INT_RESERVED3           = 27;
const IVT_INT_RESERVED4           = 28;
const IVT_INT_RESERVED5           = 29;
const IVT_INT_RESERVED6           = 30;
const IVT_INT_RESERVED7           = 31;
const IVT_INT_RESERVED8           = 32;
const IVT_DIF_IRQ                 = 33;
You can see FTDI's definition on page 25 here http://www.ftdichip.com/Support/Documen ... _1_2_3.pdf

I've tried using 5, 6, 7, and 8 with no success interrupting when a CAN message is present. Any help with the explanation of this would be greatly appreciated.

Post Reply

Return to “mikroC PRO for FT90x General”