10 years, 8 months ago.

mbed Driver Bug? CAN for the EA LPC4088 QSB puts garbage on the bus

Hello

We have been struggling with getting the QSB to talk via CAN. With the very simple program below, we only get garbage on the bus, as we have verified with the logic analyzer. On the other hand, the same hardware works perfectly when the QSB is programmed using LPCopen (instead of mbed), and mbed works if we put a LPC1768 mbed module on the same board.

Might there be an issue with the mbed CAN drivers for the LPC4088 QSB? Did this work for anybody?

Thanks Hans

--

Here's the code:

CAN example

#include "mbed.h"

DigitalOut m1(LED1);
DigitalOut m2(LED2);
DigitalOut m3(LED3);
DigitalOut m4(LED4);
CAN can(p9,p10);

int main()
{
    wait(0.5);
    can.frequency(250000);
    char can_msg[8];
    can.reset();    
    can_msg[0] = 0x02;
    can_msg[1] = 0x01;
    can_msg[2] = 0x50;
    can_msg[3] = 0x60;
    can_msg[4] = 0;
    can_msg[5] = 0;
    can_msg[6] = 0;
    can_msg[7] = 0;

    CANMessage cn(0x1f11233, can_msg, 8, CANData,CANExtended);
    while(1) {
        if (can.write(cn) == 1) 
       {
            // success
            m2 = 1;
            wait(0.1);
            m2=0;
        } else {
            // fail
            m2 = 1;
            wait(0.1);
            m2=0;
            wait(0.1);
            m2 = 1;
            wait(0.1);
            m2=0;
        }
   wait(0.8);
    
    }
}

Question relating to:

The mbed-enabled LPC4088 QuickStart Board from Embedded Artists is a easy to use ARM Cortex-M4 rapid prototyping board in a standard through hole DIP package (44-pin), targeted at high-performance as …

When doing the mbed port CAN was verified by running the two CAN tests that are available in the SDK:

https://github.com/mbedmicro/mbed/blob/master/libraries/tests/mbed/can/main.cpp https://github.com/mbedmicro/mbed/blob/master/libraries/tests/mbed/can_interrupt/main.cpp

The CAN pins where connected by jumper cables on the board (p9 -> p34, p10 ->p33).

posted by EmbeddedArtists AB 25 Mar 2014

Was this sorted out ?

posted by K P 17 Jul 2014

3 Answers

9 years, 9 months ago.

Hello, There must be additional SW faults, because I've looked at the src code and it has changed. I guess after it was found.

I'm trying to run it on 500k, but there is no output at all when looking at the TX pins with a scope.

Any suggestions?

BR JOhan

Running it on 1Mbaud works but only on 1 CAN port and it's only CAN 1 that works....

posted by Johan Svensson 24 Feb 2015

Hi Johan, We have tested CAN2 (on p33/p34) running at 125kHz bitrate and it works just fine. See code below.

#include "mbed.h"

CAN can1(p34, p33);


int main() {

    can1.frequency(125000);
    
    // read/write
    CANMessage msg;
    char buf[9] = {0};
    char text[10];
    char counter = 0;
    while(true) {
        printf("(rderrors = %u, tderrors = %u)\n", can1.rderror(), can1.tderror());
        if (can1.read(msg)) {
            //printf("Message received: %d\n", msg.data[0]);
            strncpy(buf, (const char*)msg.data, 8); 
            printf("Message received: \"%s\", len=%d, format=%d, type=%d, id=%d (0x%x)\n", buf, msg.len, msg.format, msg.type, msg.id, msg.id);
        }                
        sprintf(text, "anders%02d", counter);
        if (can1.write(CANMessage(0x142, text, 8))) {
            printf("Message sent: %d\n", counter);
        }
        counter++;
        
        wait_ms(2000);
    }
}
posted by EmbeddedArtists AB 06 Mar 2015
10 years, 2 months ago.

I am also having problems getting CAN working on the LCP4088. Did you get yours working? And in that case, what was the problem?

I have measured on the CAN tranceiver output and it seem to be CAN traffic, however it seems as thought they are coming way to fast, one bit seem to be about 280ns. Also the frequency() seem to have no effect (at least not on the bitlength)

10 years, 2 months ago.

Hi,

I have found a problem with calculating the CAN clock. Fixing this error got it working for me. Could you please also test this fix before I issue a pull request.

  1. Use the mbed-src library in your project instead of mbed. Doing this allows you to modify code in the mbed platform.
  2. Open file mbed-src/targets/hal/TARGET_NXP/TARGET_LPC408X/can_api.c
  3. Locate function can_speed and and do the modification below

Change this line (original)

  bitwidth = sclk / (pclk * cclk);

To this (modified)

  bitwidth = pclk / cclk;

Sorry for the late reply, been sick... That works! ( At least for 1 MBit (MHz) ).

posted by Markus Johansson 09 Sep 2014

A pull request has been issued.

posted by EmbeddedArtists AB 11 Sep 2014