Abstract: Has not integrated the CAN controller’s processor regarding the interior to be possible through exterior to expand the CAN connection to realize the CAN communication. Take philips ARM7 processor LPC2131 as an example, has given the more general hardware design and μCOS-II realizes the CAN correspondence essential software code based on the embedded real-time operating system.
Key word: LPC2131; CAN main line; ARM; μCOS-II; Embedded system
Along with the information technology technology’s swift development, the ARM technical program construction takes one kind to have the low power loss, the high performance, as well as small volume and so on characteristic the 32 embedded microprocessors, obtained the numerous intellectual property rights authorization user, including the world top the semiconductor and the system company. At present widespread has used in each kind of electronic products, the automobile, the expense entertainment, the phantom, the industrial control, the mass memory, the network, the security and wireless and so on domains. Believed by the field public figure that is most has the market prospect and the market superiority solution based on the ARM technical program.
Field bus CAN is to solve one kind of serial communication agreement which in the modern automobile between the numerous electrically controlled module’s data exchanges develop. Because it has the multi-master stations to carry on the main line visit based on the priority, uses the non-destructive bus arbitration, may complete to the correspondence data wrong examination and the priority distinguished, the data length most are many are 8 bytes, the transmission time is short, the probability which disturbs is been low, antijamming ability is strong, the correspondence speed is highest may reach characteristics and so on 1Mbit/s, it is widely applied in the automobile, the industry, domains and so on expense class electron, but is recognized for is one of most promising field buses.
Based on ARM in the embedded system aspect superiority and the CAN main line’s widespread application, more and more ARM processor interior has brought at present the CAN controller, enormous convenience development personnel to CAN main line’s development. But still in some product’s ARM processor did not have the built-in CAN controller at present, for can adapt the node timeliness which proposed to the data transmission, the reliable request, simultaneously does not change the original hardware architecture, expanded the CAN interface module through outside to realize Can correspond a more appropriate choice.
This article based on ARM7TDMI-S processor LPC2131, has not integrated the CAN controller’s processor to the interior, has designed the more general CAN interface module hardware circuit, and has carried on the reliability design to the CAN main line, moreover to μCOS-II realizes the CAN correspondence based on the embedded real-time operating system, has carried on embedded software’s design, finally in reality has carried on the confirmation to the CAN main line communication’s reliability and the feasibility.
LPC2131
Philips LPC2131 is based on the ARM7TDMI-S high performance 32 RISC micro controller, it has ARM processor’s all merits at the same time: Low power loss, high performance; Simultaneously also has on a richer piece the resources, very suitable embedded product development. Its characteristic is as follows:
· integrated the Thumb expansion set of instructions.
· 32KB may program (ISP) in the system internal Flash and may program (IAP) in the application 8KB RAM, has the vectored interrupt controller.
· 2 UART,2 the I2C serial interface, 2 SPI serial interfaces, 2 timers (7 capture/compare channel), the PWM unit may provide reaches 6 PWM outputs, 8 channel 10 ADC, real-time clock RTC, watch-dog timer WDT,48 general I/O pin.
· The CPU clock reaches as high as 60MHz, has the internal crystal oscillator and internal PLL.
The LPC2131 interior has not integrated the CAN controller, but is unable using the CAN main line to carry on the communication. In order to enable LPC2131 to be able to carry on the communication using the CAN main line, may develop its function through the exterior expansion.
Hardware circuit design
Because LPC2131 is by 3.3V the power supply ARM7TDMI-S microprocessor, its each IO pin is the 3.3V TTL level, moreover may withstand 5V the voltage. But independent CAN controller SJA1000 is the 5V power supply, its each IO mouth’s level is the 5V TTL level, therefore the two are compatible, its IO may direct connected.
LPC2131 and CAN controller connection
LPC2131 and CAN controller connection as shown in Figure 1, LPC2131 P0.8~P0.15 and SJA1000 AD0~AD7 direct realize the data to be interactive connected, P0.22, P0.25, P0.31, P0.23 realizes the read-write connected separately with SJA1000 ALE/AS, RD/E, WR, CS and selects patches or strips of land as worth saving for seed, P0.30, P0.27 realizes the interrupt and the replacement connected separately with SJA1000 INT, RST. When LPC2131 visits SJA1000, may the read-write succession which stipulated through software simulation SJA1000 in carry on, SJA1000 pattern pin MODE sets through VCC for the high level, causes SJA1000 to work in the Intel pattern.

Figure 1 LPC2131 and CAN controller interface circuit
CAN transceiver and CAN bus interface
The CAN transceiver and CAN main line’s connection as shown in Figure 2, SJA1000 TX0, RX0 is separately connected with CAN transceiver TXD, RXD, to enhance CAN transceiver 82C250 and CAN main line’s connection part antijamming ability, especially serially connects a syntype impedance coil in 82C250 CANH and the CANL pin, eliminates certain syntype disturbance, but enables the main line difference signal to be able to pass smoothly. And CANH and CANL separately are connected through a magnetism bead and the main line, by gets up eliminates certain high frequency interference. Simultaneously between CANH and CANL and place parallel two 30pf small electric capacity, may get up filters on main line’s high frequency interference and certain against electromagnetic radiation ability. Moreover in two CAN main lines met between the input terminal and the place have met TVS separately, when the CAN main line had the high voltage earthed through the TVS puncture, might play certain overvoltage protection role. on the 82C250 Rs pin meets has a slope resistance to reduce the CAN main line’s radiation outward.

Figure 2 CAN transceiver and bus interface electric circuit
Can withstand 5V regarding other not built-in CAN controller the TTL level processor, outside only need change the pin which and SJA1000 data port ALE/AS, RD/E, WR, CS, INT, RST connects then to complete expands the CAN connection the hardware design work, otherwise adds the component which between both a logic level transforms then.
Software design
Visit to SJA1000 read-write
Because the LPC2131 48 pins all are IO, therefore first needs through the software simulation read-write SJA1000 succession, to come to SJA1000 to carry on the operation, then completes the CAN communication function.
Based on SJA1000 in Intel under pattern read-write succession [4], may compile LPC2131 transmission data to write function void WriteCan through CAN the controller SJA1000 (uint8 Addr, uint8 Data) and accepts the data which the CAN controller accepts to read function uint8 ReadCan (uint8 Addr), Addr is the SJA1000 corresponding register’s address, Data is the data which LPC2131 transmits, reads data which function ReadCan may return accepts.
CAN communication realization
Must realize a CAN communication to need to realize 3 functional modules: To the SJA1000 initialization module; Data transmission module; The data accepts the module.
· to the SJA1000 initialization module
Before starting the communication, must first carry on the establishment in the SJA1000 each function register, including the pattern register, the baudrate, the clock frequency divider, the interrupt enables the register, filter register, output control register.
uint8 IniSJA1000 (uint8 BTR0, uint8 BTR1)
{
IO0CLR=CS; // selects patches or strips of land as worth saving for seed SJA1000
WriteCan(0,0×09); // enters the replacement pattern
WriteCan(31,0xe8); // establishment clock frequency divider
WriteCan(4,0xfd); // establishes the interrupt to enable the register
WriteCan(16, AcceptCode1); // establishment approval code 1
WriteCan(17, AcceptCode2); // establishment approval code 2
WriteCan(18, AcceptCode3); // establishment approval code 3
WriteCan(19, AcceptCode4); // establishment approval code 4
WriteCan(20, MaskCode1); // establishes the approval to shield 1
WriteCan(21, MaskCode2); // establishes the approval to shield 2
WriteCan(22, MaskCode3); // establishes the approval to shield 3
WriteCan(23, MaskCode4); // establishes the approval to shield 4
WriteCan(6, BTR0); // establishment main line succession register 1
WriteCan(7, BTR1); // establishment main line succession register 2
WriteCan(8,0xfa); // establishes the output control accumulation
WriteCan(0,0×08); // enters the operator schema
OSCANMbox=OSMboxCreate(0); /establishes Can pass
News mailbox
if (OSCANMbox==NULL)
{
return FALSE;
}
return TRUE;
}
· data transmission module
The supposition must transmit data ID saves in array ID[4], the data storage in array SendData[8], its transmission module procedure as follows shows, parameter DLC is the transmission byte count, FF is the frame type, namely 0 are the data frames, 1 is the long-distance frame.
void Tx (uint8 DLC, uint8 FF)
{
uint8 i;
OS_ENTER_CRITICAL();
If (FF==0×01)
{
WriteCan(16, DLC 0×80); // data frame
}
else
{
WriteCan(16, DLC 0xd0); // long-distance frame
}
WriteCan(17, ID[0]);
WriteCan(18, ID[1]);
WriteCan(19, ID[2]);
WriteCan(20, ID[3]); //TX identification code
for (i=0; i<DLC; i )
WriteCan(21 i, sentdata[i]); //TX data
WriteCan(1,0×01); // establishment transmission register transmission
OS_EXIT_CRITICAL();
}
· the data accepts the module
According to the circuit diagram 1, selects the method which the interrupt accepts to accept the data, LPC2131 P0.30 establishes as the external interrupt 3, the entire data accepts the module to accept function void ReceiveData by the data (uint8 *Rt), the interrupt processing function Can_Exception(void) constitution. When SJA1000 accepts the CAN main line data, causes LPC2131 through the receive interrupt to have the external interrupt 3 to cause it to enter the interrupt processing function, then docking receives the data carries on processing. And the data accepts the function and the interrupt processing function is as follows:
void ReceiveData (void)
{
uint8 i, err,*Rt;
OS_ENTER_CRITICAL();
Rt= (uint8 *) OSMboxPend(OSCANMbox,0,&err);
// accepts the data through the mailbox
for (i=0; i<13; i )
ReceiveData[i]=*Rt ; // will accept data existence
In the global variable supplies the following processing
OS_EXIT_CRITICAL();
}
void Can_Exception(void)
{
uint8 temp[13], i;
OS_ENTER_CRITICAL();
for (i=0; i<13; i )
temp[i]=ReadCan(16 i); // reads the CAN data
OSMboxPost (OSCANMbox, (void *) temp); //
The CAN data transmits by the mailbox to accepts the function
EXTINT=0×08; // clear ENT3
VICVectAddr=0; // interrupts the returns
OS_EXIT_CRITICAL();
}
Conclusion
Took the master-control unit by the ARM chip, the CAN main line carries on the communication as the data transmission way the embedded system to obtain more and more widespread application. Simultaneously the CAN communication’s reliability also becomes one of influence system performance essential parts. This article take LPC2131 as an example, has given a kind of microprocessor and CAN between the controller SJA1000 more general hardware connection method, has carried on the reliability design to the CAN main line, and μCOS-II has carried on the CAN communication software development based on the embedded real-time operating system, this design already obtained the application in the factory workshop’s distributional supervisory system, the movement has been reliable, is stable.
Reference:
1. Jean J.Labrosse, MicroC/OS-II The Teal-Time Kernel(SecondEdition) Shao Beibei and so on is translating. “embedded real-time operating system uC/OS-II (the second edition)”, Beijing University of Aeronautics and Astronautics Publishing house, in May, 2003
2. Du spring thunder, “ARM architecture and programming”, Tsinghua University publishing house, 2003
3. LPC2131/LPC2132/2138 Product data, Philips Semiconductors.2004
4. SJA1000 Datasheet, Philips Semiconducto-rs. 1999