-3

I have been assigned a project in my lab to implement CAN protocol on ARM 7.

I looked for some tutorials and sample code, but all looks so much complex that I think I should get some help on the coding part. Can anybody explain me the basic transmitter and receiver coding on any ARM board?

The sender code is the following. I have used question marks where I don't understand the full meaning of an expression.

#include <lpc23xx.h>
#include "type.h
#include "can.h"
#include <LPC23xx.H>

CAN_MSG MsgBuf_RX1,MsgBuf_RX2; // TX and RX Buffers for CAN message
volatile DWORD CAN1RxDone, CAN2RxDone;

int main(void)
{
    DWORD tempbuf1,tempbuf2;

    int current;
    FIO2DIR=0x000000FF;
    CAN_Init(BITRATE100K28_8MHZ);

    MsgBuf_RX2.Frame = 0x0;
    MsgBuf_RX2.MsgID = 0x0;
    MsgBuf_RX2.DataA = 0x0;
    MsgBuf_RX2.DataB = 0x0;
    CAN_SetACCF(ACCF_BYPASS);

    while (1)
    {
        while (!(CAN2GSR & (1 << 0)) )
            ;

        if (CAN2RxDone == TRUE)
        {
            tempbuf1 = MsgBuf_RX2.DataA; // Data A has 32 bits, of which only the
                                         // first 16 bits are actual data
            tempbuf2 = (tempbuf1 & 0x0000ffff); //??

            current = tempbuf2;
            if ((current/3) >= 25)
                FIO2SET |= 0x00000001; ///??
        }

        CAN2RxDone = FALSE;

        if (MsgBuf_RX2.Frame & (1 << 10)) //?
        {
            MsgBuf_RX2.Frame &= ~(1 << 10); //?
        }
    }
}
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
mrigendra
  • 1,472
  • 3
  • 19
  • 33
  • its lpc2368 board made up of arm7tdmi-s .i was using keil uvision4 and flashmagic , and i have a sample program too. But i am unable to understand it fully as i read datasheet of lpc2368 i find it difficult to understand. So i decided to make just a program that use can protocol to send 8 bits from one board to another. – mrigendra Sep 26 '13 at 04:25
  • the board specifications are easily available .. just google lpc2368 user manual and datasheet. – mrigendra Sep 26 '13 at 04:26
  • i have a master an slave program if you want to look at it i can post it. – mrigendra Sep 26 '13 at 04:27
  • Read the CAN specification. – starblue Sep 26 '13 at 07:03
  • i read it but it was too complex to follow – mrigendra Sep 26 '13 at 07:15
  • Is your problem with understanding the C syntax for logical operations, the format and operation of the protocol or both? Currently this question is too open-ended. – unixsmurf Sep 26 '13 at 09:40
  • if you take a look on lpc2368 datasheet its not that open ended question ,and yes i have some difficulty understanding the purpose of while loop in this program.. also why there is current/3 (is this because of three buffers in transmitter..?) and checking it with 25 (is this polling..?) – mrigendra Sep 26 '13 at 13:09
  • "ARM7" says nothing, CAN is not part of the CPU core... please specify the exact MCU part number you are using. – Lundin Sep 26 '13 at 14:20
  • i am using a board developed by NXP(philips) LPC2368 it uses arm7tdmi-s – mrigendra Sep 26 '13 at 14:23
  • So let me get this straight - I am supposed to go off and read a data sheet for a component not even mentioned in the original question in order to be able to determine what the question actually is? Is your problem with the C syntax or the protocol or the hardware interaction or all of these? You say you do not understand the while loop, but there are two while loops in the program. The question is open-ended and unclear. – unixsmurf Sep 26 '13 at 15:43
  • no you need not to do all this. i posted this question because i thought someone with experience on this particular board might answer . – mrigendra Sep 26 '13 at 16:29
  • and if i write everything here in comments then it would be just "comment reading" so try to be a little obvious about which while loop i am asking, its both while loops. – mrigendra Sep 26 '13 at 16:31
  • 2
    You need to put in more effort to understand complex things. If you still have problems, ask your instructor. Since you understand so little of what you are doing, your question is too open-ended for asking it here. In particular, asking for external resources like tutorials is off-topic here. – starblue Sep 27 '13 at 07:14

1 Answers1

3

Keil provides some examples and programs for CAN development: http://www.keil.com/dd/vtr/4152/7837.htm

Here you can find CAN source for LPC2129: http://www.siwawi.arubi.uni-kl.de/avr_projects/arm_projects/

Here some examples: http://mbed.org/handbook/CAN

yegorich
  • 4,653
  • 3
  • 31
  • 37