Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
6 years, 10 months ago.
マイコン間のCAN通信について
サンプルプログラムを以下の様に変更してマイコン間のCAN通信をしようとしているのですが,出来ません.can1.write(msg)=1となるのですが,ピンの電圧も変化していないため送信できていないようです.プログラムに問題がありましたら教えて頂きたいです.
送信側プログラム
- include "mbed.h"
- include "init.h"
- include "CAN.h"
DigitalOut led_2(LED2); CAN can1(p9,p10); Serial pc(USBTX,USBRX); Ticker ticker;
char counter=0; CANMessage msg(1337,&counter,1,CANData,CANStandard);
void send();
================================================================== int main(){ pc.baud(115200); pc.printf("main()\n\r"); can1.reset(); ticker.attach(&send,1); }main
================================================================== void send(){
if(can1.write(msg)){ counter++; pc.printf("Message sent: %d\n\r",counter); led_2=!led_2; } }send()
受信側プログラム
- include "mbed.h"
- include "init.h"
- include "CAN.h"
DigitalOut led_2(LED2); CAN can1(p9,p10); Serial pc(USBTX,USBRX); CANMessage msg(1337,CANStandard);
================================================================== int main(){ pc.baud(115200); pc.printf("main()\n\r"); can1.reset();
while(1){ AdjustCycle(30000); if(can1.read(msg)){ pc.printf("Message received: %d\n\r",msg.data); led_2=!led_2; } else if(!can1.read(msg)){ pc.printf("NO Message \n\r"); } }while(1) }main