This Figure shows the programming flowchart. Table: CAN Get Mode through Table: CAN Set Bit Timing list the CAN controller modes.
Task |
Register |
Register Field |
Register Offset |
Bits |
Value (Binary) |
---|---|---|---|---|---|
Get the current mode of the device to confirm that the device is in configure mode. Refer to the CAN Get Mode. |
|||||
Program baud rate value. |
BRPR |
BRP |
0x08 |
7:0 |
7b'00101001 |
Task |
Register |
Register Field |
Register Offset |
Bits |
Value (Binary) |
---|---|---|---|---|---|
Get the current mode of the device to confirm the device is in configure mode. Refer to the CAN Get Mode. |
|||||
Program the baud rate value. |
BTR |
SJW | TS2 | TS1 |
0x0C |
8:0 |
8b110101111 |
Task |
Register |
Register Field |
Register Offset |
Bits |
Value (Binary) |
---|---|---|---|---|---|
To get the current mode of to device. Refer to the CAN Get Mode. |
|||||
If current mode is normal mode, and requested mode is sleep mode, then follow these normal mode to sleep mode steps. |
|||||
Select sleep mode and return |
MSR |
SLEEP |
0x04 |
0 |
1b'1 |
If current mode is sleep mode, and requested mode is normal mode, then follow these sleep mode too normal mode steps. |
|||||
Select normal mode and return. |
MSR |
SLEEP | LBACK | SNOOP |
0x04 |
2:0 |
3b'000 |
If the mode transition is not any of the two cases above, CAN must enter configuration mode before switching into the target operation mode. |
|||||
Set configuration mode |
SRR |
CEN | SRST |
0x00 |
1:0 |
2b'00 |
Check the device mode. Refer to the CAN Get Mode. If the device is not entered into configuration mode, return. If entered, then follow these steps to set the requested mode. |
|||||
To set sleep mode |
|||||
Select sleep mode. |
MSR |
SLEEP |
0x04 |
0 |
1b'1 |
Enable CAN. |
SRR |
CEN |
0x00 |
1 |
1b'1 |
To set normal mode |
|||||
Select normal mode. |
MSR |
SLEEP | LBACK | SNOOP |
0x04 |
2:0 |
3b'000 |
Enable CAN |
SRR |
CEN |
0x00 |
1 |
1b'1 |
To set loopback mode |
|||||
Select sleep mode. |
MSR |
LBACK |
0x04 |
1 |
1b'1 |
Enable CAN |
SRR |
CEN |
0x00 |
1 |
1b'1 |
To set snoop mode |
|||||
Select snoop mode. |
MSR |
SNOOP |
0x04 |
2 |
1b'1 |
Enable CAN |
SRR |
CEN |
0x00 |
1 |
1b'1 |
Task |
Register |
Register Field |
Register Offset |
Bits |
Value (Binary) |
---|---|---|---|---|---|
Check if the CAN FIFO is full to make sure there is room in the FIFO. Refer to Check CAN FIFO is Full. |
|||||
Program TXFIFO_ID. |
TXFIFO_ID |
IDH | SRRRTR | IDE | IDL | RTR |
0x30 |
31:0 |
0x20000000 (hex) |
Program TXFIFO_DLC. |
TXFIFO_DLC |
DLC |
0x34 |
31:28 |
4b'1000 |
Program TXFIFO_DATA1. |
TXFIFO_DATA1 |
DB0 | DB1 | DB2 | DB3 |
0x38 |
31:0 |
Data |
Program TXFIFO_DATA2. |
TXFIFO_DATA2 |
DB4 | DB5| DB6 | DB7 |
0x3c |
31:0 |
Data |
Task |
Register |
Register Field |
Register Offset |
Bits |
Value (Binary) |
---|---|---|---|---|---|
Read ISR. |
ISR |
RXNEMP |
0x1C |
7 |
Read operation |
If the RXNEMP bit is set, then the RX is not empty. Else, the RX FIFO is empty. |
Task |
Register |
Register Field |
Register Offset |
Bits |
Value (Binary) |
---|---|---|---|---|---|
Initialize GIC. Refer to the GIC section. |
|||||
Register GIC interrupt handler. Refer to the GIC section. |
|||||
Register CAN interrupt handler with the GIC. |
|||||
Enable GIC. Refer to the GIC section. |
|||||
Enable processor interrupts. |
Task |
Register |
Register Field |
Register Offset |
Bits |
Value (Binary) |
---|---|---|---|---|---|
Read ISR (status). |
ISR |
All |
0x1C |
14:0 |
Read |
Get enabled interrupts list (pendingintr and status). |
IER |
All |
0x20 |
14:0 |
Read |
Clear all interrupts. |
ICR |
All |
0x24 |
14:0 |
pendingintr |
If error interrupt is set (bit CERROR), notify application the error interrupt has been set. |
|||||
Read error status (esr_status). |
ESR |
0x14 |
All |
4:0 |
Read |
Clear error status. |
ESR |
0x14 |
esr_status |
4:0 |
esr_status |
If the bus off interrupt is set (BSOFF bit), return from interrupt. |
|||||
If water mark full OR RXNEMP interrupts set, receive frame. Refer to CAN Receive Frame. |
|||||
If TXOK interrupt is set notify application that TX is ok. |