Hi,
I am working with a LPC2292/01 Rev. C and use the CAN interface 1 of
this chip.
The RBS and the DOS bit in the CAN1GSR are never set.
I checked the address of the Register definition of CAN1GSR twice.
Transmitting works. Receiving works, when I ignore the RBS-Bit.
I looked at the code from the AN10438 and RBS and DOS were never
checked. Are these Bits broken? There is nothing in the errata. How can
you determine when there is a new message without the RBS-bit.
Has anyone an idea?
Here is my Code (initialisation and receive-function)
1 | void can_init()
|
2 | {
|
3 | //Reset bus
|
4 | C1MOD = (1 << 0);
|
5 |
|
6 | //Bus-Timing 25kBit (60MHz PCLK)
|
7 | //Prescaler: 300, SJW: 1, TESG1: 5, TESG2: 2
|
8 | C1BTR = 299 | (4 << 16) | (1 << 20);
|
9 |
|
10 | //IO
|
11 | PINSEL1 |= (0x01 << 18);
|
12 |
|
13 | //activate
|
14 | C1MOD &= ~(1 << 0);
|
15 | }
|
16 |
|
17 | int8_t can_read_msg(CAN_MSG * msg)
|
18 | {
|
19 | //Receive
|
20 | if(C1GSR & 0x01)
|
21 | {
|
22 | msg->len = (C1RFS >> 16) & 0x0F; //read length
|
23 | msg->id = C1RID & 0x3FF; //read ID
|
24 |
|
25 | if(C1RFS & (1 << 30)) //RTR?
|
26 | {
|
27 | msg->status = CAN_STATUS_RTR; //RTR Flag
|
28 | }
|
29 | else
|
30 | {
|
31 | //no RTR, read databytes, ignore length
|
32 | msg->data[0] = C1RDA & 0xFF;
|
33 | msg->data[1] = (C1RDA >> 8) & 0xFF;
|
34 | msg->data[2] = (C1RDA >> 16) & 0xFF;
|
35 | msg->data[3] = (C1RDA >> 24) & 0xFF;
|
36 | msg->data[4] = C1RDB & 0xFF;
|
37 | msg->data[5] = (C1RDB >> 8) & 0xFF;
|
38 | msg->data[6] = (C1RDB >> 16) & 0xFF;
|
39 | msg->data[7] = (C1RDB >> 24) & 0xFF;
|
40 | }
|
41 |
|
42 | //next time, next message
|
43 | C1CMR = (1 << 2);
|
44 |
|
45 | return 0;
|
46 | }
|
47 | else
|
48 | {
|
49 | return -1;
|
50 | }
|
51 | }
|