简体   繁体   中英

Mbed CAN network only gets half the data

I am creating a software that has to ask for data in a unit with a CAN network. For some reason I am only getting a part of the data being send when asked for. The unit has a CAN frequency of a 100 kbit or a 100000 bits as shown in the code. I am using a Nucleo-F767ZI and to make a connection to the CAN network I am using the build in function of the board.

I already looked if there was a fault with the data being send, but this seems fine since a different program is able to read it without fault. The code I currently use to test is this bit.

#include "mbed.h"

CAN can1(PD_0, PD_1);//Sets the pins for the CAN.
Serial pc(USBTX, USBRX);//Selects the type of serial and assigns a name to it.
char buffer[300];

int main (){
    pc.baud(9600);//sets serialportbaud to 9600
    CANMessage test;
    can1.frequency(100000); //Sets frequency speed. it has to be 100000 otherwise the unit wont respond
    test.format = CANStandard; //Selects the format for the can message.
    test.id = 24; //Gives the can message an ID.
    test.len = 2; //How long the message is in bytes.
    test.data[0] = 0; //Select the data for this byte. 
    test.data[1] = 3;
    can1.write(test); //this sends the data of 0 , 3 with the id of 24 and gets data from the unit its being send to.

    printf("\n\rsended \n\r"); //confirmation that it has come this far without crashing.

    while(true){
        can1.read(receive);//receives any message send over the network except his own.
        sprintf(buffer, "%d/%d/%d/%d/%d/%d/%d/%d", receive.data[0], receive.data[1], receive.data[2], receive.data[3], receive.data[4], receive.data[5], receive.data[6], receive.data[7]);//stores data in buffer
        printf("%s \n\r", buffer);//shows what the data was
    }
}

我通过增加串行波特率来解决该问题,因为串行波特率在更改数据之前似乎足够慢地打印数据。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM