Manual

RS485 CAN Shield User Manual
8
Rev: V1.4, Date: May 19
th
2015
share awesome hardware
#include "mbed.h"
#include "CAN.h"
Serial pc(D1,D0); //serial print message
Serial RS485(D8, D2); //RS485_TX RS485_RX
DigitalOut RS485_E(D7); //RS485_E
CanRxMsg RxMessage; //RxMessage
char s[1024];
void callback()//RS485 RX interrupt handler
{// Note: you need to actually read from the serial to clear the RX interrupt
RS485.scanf("%s",s);//Save received messages
pc.printf("\r\nRS485 Receive:%s \r\n",s);//Print Received messages
}
int main() {
CAN_Config();//CAN initiation
RS485.attach(&callback);//Open RS485 reception interruption
RS485_E = 0;//Enable receiving status
pc.printf( "**** This is a can receive test program ****\r\n");
while(1) {
while(CAN_MessagePending(CAN1, CAN_FIFO0) < 1)// Message waiting
{
}
CAN_Receive(CAN1, CAN_FIFO0, &RxMessage);//CAN data reception
pc.printf("The CAN RxMsg: %s\r\n",RxMessage.Data);//Print
received messages
}
}
2.3.3. Operating phenomenon
The serial port of sending side will print:
**** This is a RS485_CAN_Shield Send test program ****
CAN send TxMessage successfully
RS485 send: counter=0