HMI 7" CAN bus

Post Reply
Author
Message
Jan.Peca
Posts: 2
Joined: 29 Nov 2019 17:51

HMI 7" CAN bus

#1 Post by Jan.Peca » 30 Nov 2019 12:55

Hi,

I am looking for advice about CAN communication.
I have Micromedia HMI 7" (https://www.mikroe.com/mikromedia-hmi-70-no-touch), micromedia HMI Break Board (https://www.mikroe.com/mikromedia-hmi-breakout) and source sending CAN messages. In this case it is arduino.


And pins are connected like this:

CAN1 RX -> CAM-PWDN
CAN1 TX -> CAM-D0
or
CAN0 RX -> CAM-D1
CAN0 TX -> CAM-D2

But I am not able to get CAN message from CAN0 nor CAN1 anyway.

I was looking for throught your forum for some advice. I found this topic (viewtopic.php?f=204&t=65113) then I took example for CAN from EasyFT90x folder, but still I was not able to get CAN bus working.

I am using microC PRO for FT90X and my code is following:

Code: Select all

#include "__Can.h"
#include "__Can_Hw_Map.h"
#include "CANTest_objects.h"

uint32_t flags;
TCANMsg msg;


void main() {

  InitVTFTStack();
  UART1_Init(9600);
  Delay_100ms;
  
  CAN_SysInit(CAN1);
  
  if(CAN_OK == CAN_Init(CAN1,500)){
     UART1_Write_Text("CAN1 INIT OK \r\n");
  }

  while (1) {
    if (CAN_OK == CANx_Read(CAN1, &msg.ID, &msg.buf, &msg.len, &flags)){     
     UART1_Write_Text("CAN1 READ \r\n");
       if (msg.len){
         UART1_Write_Text("CAN1 LEN CONDITION \r\n");
       }
     }
    ProcessVTFTStack();
  }

}
I can get output by UART from the first condition (CAN_Init()), from the second one (CANx_Read()), but I can not get output by UART from the last conditon.
Is something wrong there or missing?
Why I am able to get CAN_OK status from CANx_Read() but no message?
And how is possible, that I get CAN_OK status from CANx_Read() with no pins connected to CAN bus?

User avatar
stefan.filipovic
mikroElektronika team
Posts: 1135
Joined: 18 Dec 2018 10:30

Re: HMI 7" CAN bus

#2 Post by stefan.filipovic » 03 Dec 2019 11:46

Hi,

Did you add a 120 Ohm resistor at each end of the bus (or between can lines)?
Read more about that here:
https://electronics.stackexchange.com/q ... or-and-not

Kind regards,
Stefan Filipović

Jan.Peca
Posts: 2
Joined: 29 Nov 2019 17:51

Re: HMI 7" CAN bus

#3 Post by Jan.Peca » 05 Dec 2019 15:15

Hi,

thanks for asnwer. Yes, we have resistors between can lines. But CAN still does not working.
Now I want to test, if I am able to measure signal on CAM-D0 or CAM-D2 by oscilloscope.
I took your example from EasyFT90X folder.

CAN_Init and CAN_PushMessage return CAN_OK status, but I can not get into IF conditions in while.

Code: Select all

if (CAN_OK == CAN_Init(CAN1, 500)){
    UART1_Write_Text("CAN Init OK \r\n");
  }
  msg.RTR    = 0;
  msg.ID     = 13;
  msg.len    = 1;
  msg.buf[0] = 0xaa;
if(CAN_OK == CAN_PushMessage(CAN1, &msg)){
     Delay_ms(1000);
     UART1_Write_Text("PUSH MESSAGE OK");
 }


  while(1){
    uint8_t count;
    count = CAN_RXQueueCount(CAN1);
    if (count){
    UART1_Write_Text("COUNT CONDTION");
      CAN_PullMessage(CAN1, &msg);
      if (msg.len)
      {
      UART1_Write_Text("LEN CONDITION");
        IntToStr(msg.buf[0], txt);
        UART1_Write_Text(txt);
        Delay_ms(500);

        msg.RTR = 0;
        msg.ID  = 13;
        msg.len = 1;
        flags   = 0;

        msg.buf[0]++;
        CANx_Write(CAN1, msg.ID, msg.buf, msg.len, flags);
      }
    }
  }
}
Then I try to take only CANx_Write function (code below) and want just write message still with oscilloscope connected to CAM-D0 or CAM-D2. But I got output to UART only one times from the first condition and then nothing. (no error, no overrun)

Code: Select all

  while(1){
      Delay_ms(1000);
      if(CAN_OK == CANx_Write(CAN1, msg.ID, msg.buf, msg.len, flags)){
      UART1_Write_Text("CAN WRITE \r\n");
      }
      if(CAN_RX_OVERRUN == CANx_Write(CAN1, msg.ID, msg.buf, msg.len, flags)){
      UART1_Write_Text("CAN WRITE RX ERROR \r\n");
      }
      if(CAN_ERROR == CANx_Write(CAN1, msg.ID, msg.buf, msg.len, flags)){
      UART1_Write_Text("CAN WRITE ERROR \r\n");
      }
}
I am using your examples for EasyFT90x, because I can not find any CAN examples exactly for Micromedia HMI.
Is something wrong there or do you have any advice for me?

Thanks.

User avatar
stefan.filipovic
mikroElektronika team
Posts: 1135
Joined: 18 Dec 2018 10:30

Re: HMI 7" CAN bus

#4 Post by stefan.filipovic » 16 Dec 2019 16:56

Hi Jan,

I noticed that you have opened a Helpdesk ticket, so we can continue our correspondence there.

Kind regards,
Stefan Filipović

Post Reply

Return to “Mikromedia”