Manual

RS485 CAN Shield User Manual
6
Rev: V1.4, Date: May 19
th
2015
share awesome hardware
D8(PA_9), D2(PA_10) are the sending and receiving port of RS485.
D7(PA_8) is for RS485 sending or receiving enable. High level is for sending, low level is for
receiving.
Message is sent to serial port of PC through D0 and D1.
The CANH and CNAL of one CAN port should be connected to anothers CANH and CANL port,
and the A and B port of one RS485 should be connected to anothers A and B.
2.3.1. Sending side pr ogram description
CAN: After related registers are initiated. the message to be sent will be saved into the Mailbox, and
then it will be sent by driver functions.
RS485: Set RS485_E to high level, which will make RS485 into sending status. Messages will be sent
through RS485 serial port.
#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
CanTxMsg TxMessage;
uint8_t TransmitMailbox = 0;
int i =0,j=0;
int main() {
CAN_Config();//CAN initiation
RS485_E = 1;//enable RS485 sending status
/* TxMessage */ //Setting message of Txmessage
TxMessage.StdId = 0x10;
TxMessage.ExtId = 0x1234;
TxMessage.RTR=CAN_RTR_DATA;
TxMessage.IDE=CAN_ID_STD;
TxMessage.DLC=8;
TxMessage.Data[0] = 'C';
TxMessage.Data[1] = 'A';
TxMessage.Data[2] = 'N';
TxMessage.Data[3] = ' ';
TxMessage.Data[4] = 'T';