2/4

Dependencies:   mbed

main.cpp

Committer:
maxnagazumi
Date:
21 months ago
Revision:
0:f61429c7c6c0

File content as of revision 0:f61429c7c6c0:

#include "mbed.h"

CAN can1(p30,p29);

DigitalOut led(LED1);
DigitalOut led2(LED2);

Ticker ticker;

char can_data1[2]= {0,0};
int data1;
float y;
void can_send()
{
    data1=500;
    can_data1[0]=data1>>8;
    can_data1[1]=data1&255;
    if(can1.write(CANMessage(1,can_data1,2))) {
        led =1;
        led2=0;
        printf("send\r\n");
    } else {
        led=0;
        led2=1;
        printf("no send\r\n");
    }
    
    CANMessage msg1;
    if(can1.read(msg1)) {
        if(msg1.id == 2) {
            y=(short)((msg1.data[0]<<8)|msg1.data[1]);
            if(y==1000) {
                led=1;
                led2=1;
            } else {
                led=0;
                led2=0;
            }
        }
    }
}
int main()
{
    can1.frequency(1000000);
    ticker.attach(&can_send,0.01);
}