Сеть Mbed CAN получает только половину данных - PullRequest
0 голосов
/ 23 января 2019

Я создаю программное обеспечение, которое должно запрашивать данные в устройстве с сетью CAN.По какой-то причине я получаю только часть отправляемых данных по запросу.Устройство имеет частоту CAN 100 кбит или 100000 бит, как показано в коде.Я использую 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
    }
}

1 Ответ

0 голосов
/ 24 января 2019

Я исправил это, увеличив последовательную скорость передачи данных, которая, по-видимому, должна была замедлить печать данных достаточно быстро, прежде чем они уже были изменены.

...