簡體   English   中英

Mbed CAN網絡僅獲得一半的數據

[英]Mbed CAN network only gets half the data

我正在創建一個必須在具有CAN網絡的單元中請求數據的軟件。 出於某種原因,我僅在需要時才獲取要發送的數據的一部分。 如代碼所示,該單元的CAN頻率為100 kbit或100000 bit。 我正在使用Nucleo-F767ZI,並且要連接到CAN網絡,我正在使用開發板的內置功能。

我已經查看了正在發送的數據是否存在故障,但這似乎很好,因為其他程序可以無故障地讀取數據。 我當前用於測試的代碼就是這一位。

#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