9 years, 11 months ago.  This question has been closed. Reason: Off Topic

CAN Gateway

Hi, I am currently preparing a gateway CAN.One CAN PIN for example (p9,p10) is directly connected to my OBD diagnostic socket.And I use the program below.But the problem is that I am obliged to go through the program to change the frequency of the PIN CAN.What I would like to do is make a program to have the frequency of the CAN directly.Do you think this is possible? Sorry if it's not very clear.

  1. include "mbed.h"

Ticker ticker; DigitalOut led1(LED1); DigitalOut led2(LED2); CAN can1(p9, p10); CAN can2(p30, p29); char counter = 0;

void send() { printf("send()\n"); if(can1.write(CANMessage(1337, &counter, 1))) { printf("wloop()\n"); counter++; printf("Message sent: %d\n", counter); } led1 = !led1; }

int main() { printf("main()\n"); ticker.attach(&send, 1); CANMessage msg; while(1) { printf("loop()\n"); if(can2.read(msg)) { printf("Message received: %d\n", msg.data[0]); led2 = !led2; } wait(0.2); } }