Report
1 year, 3 months ago.

Big problem with Can Analyzer Microchip and Ublox-C027

Hi! I'm trying in these days to test the can bus of my board, Ublox C027 with lisa u200, using the Microchip Apgdt002 Can Bus Analyzer. The problem is that, using the preconstruncted functions in the mbed library, they don't see each other. The code i used is the following: /media/uploads/Axel9888/main.cpp

Therefore, when i transmit with the Can Analyzer, i have errors and the board doesn't red the massages. The cables for Can_H and Can_L are connected correctly.

Comment on this question

1 Answer

1 year, 3 months ago.

Hello Alessio,

Since the used code lacks any endless while loop in the main() function, after printing a "main()" message to the serial port and attaching the send function to the ticker it is terminated. To keep it running and show info about the received CAN messages try to modify it as follows:

#include "mbed.h"
 
Ticker ticker;
CAN can1(P0_4, P0_5, 250000);
char counter = 0;
 
void send() {
    printf("send()\r\n");
    if(can1.write(CANMessage(5, &counter, 1))) {
        printf("wloop()\r\n");
        counter++;
        printf("Message sent: %d\r\n", counter);
    } 
}
 
int main() {
    printf("main()\r\n");
    ticker.attach(&send, 1);
    CANMessage msg;
    while(1)
    {
        if(can1.read(msg)) {
            printf("Message received:\r\n");
            printf("  ID      = 0x%.3x\r\n", msg.id);
            printf("  Type    = %d\r\n", msg.type);
            printf("  Format  = %d\r\n", msg.format);
            printf("  Length  = %d\r\n", msg.len);
            printf("  Data    =");
            for(int i = 0; i < msg.len; i++)
                printf(" 0x%.2X", msg.data[i]);
            printf("\r\n");
            printf("-------------------------------------\r\n");
        } 
    }
}

Also make sure that the CAN Analyzer is set to the same CAN bus speed as your CAN node above (250000Hz).

Also ensure you have a CAN termination resistor on the bus or you'll get a permanent error state.

posted by Andy A 09 May 2018

You need to log in to post a question