简体   繁体   English

Mbed CAN网络仅获得一半的数据

[英]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. 我正在创建一个必须在具有CAN网络的单元中请求数据的软件。 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. 如代码所示,该单元的CAN频率为100 kbit或100000 bit。 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. 我正在使用Nucleo-F767ZI,并且要连接到CAN网络,我正在使用开发板的内置功能。

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
    }
}

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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