This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CAN not working on Stellaris LM4F120 LaunchPad Evaluation Board

Hi,

    I am trying to use the CAN peripheral with this board. I understand that we need to connect an external CAN transceiver for CAN communication to work. I tried using the MCP2551 from Microchip and the simple_tx.c example code provided by TI. I changed the CAN pin definitions given in the simple_tx.c program to ones matching my board (TX->PE.5 and RX->PE.4), but have been unable to communicate. I tried probing the CAN TX output from the controller and found that it is always held high irrespective of the data being sent. However on the UART (debug interface) I do not see any error messages.

    Can someone please help me out with this?

Satwik

  • OK... So after a lot of debugging I was able to get the CAN module on the Launchpad working. The issues I found out are as follows.

    1. The Launchpad needs to be connected to a CAN bus through a CAN transceiver chip like the MCP 2551.

    2. The RX pin should be high when the CAN bus is in idle state. If the RX pin is not high, the LM4F120 CAN module will not transmit data at all after initialization. So if you want to check if the LM4F120 CAN module is sending out data on the TX line without connecting it to a CAN bus, connect the RX pin of the controller to 3.3V. In such a case, the controller will send data out on the TX line, but since it is not connected to a CAN bus, it will not receive any acknowledgement and the error counter in the CAN module will increase.

    3. For some reason, the port F pins (PF0 and PF3) do not work for CAN, even after proper initialization. It is better to use port E pins (PE4 and PE5) instead.

    4.  The simple_TX and simple_RX codes provided by TI work fine after you change the port configurations to the ports that you want to use for CAN. However you need  to register the CAN interrupt for the controller to enter the interrupt handler. The line of code to register the CAN interrupt is present in the simple_TX and simple_RX codes, but it is commented out. You just need to uncomment it.

  • Believe you've done a very nice job w/your report - should help many - thank you.

    Regarding PF0 - this pin defaults to NMI (and catches many).  Special "unlock" procedure is required to liberate this pin for other duty.  MCU data manual details.

    Likely wise to mention that 2 such CAN xcvr chips are needed - should you wish to speak to 2nd, CAN capable board.  Must always be MCU1 -> CAN Xcvr1 <- -> CAN Xcvr2 -> MCU2.

    Insure that power supply is adequate to power both boards - together (and both "adapted" CAN Xcvr boards) - so that individual board (or Xcvr) power Up/Down is not enabled.  Both boards must at all times be powered during check-out and operation - powering just one will likely cause damage.

  • Hello,

    I am also trying to use CAN on LM4f232. Since my custom board is already fabricated I cant change the port. The CAN0 Tx is at PF0. 

    I wanted to know if you can provoide the special "unlock" procedure you are talking about.

    Thank you,

    Agraj

  • Agraj,

    The unlock procedure is used to commit the GPIO configurations to the four JTAG/SWD pins and the NMI pin.  You write the key to the GPIOLOCK register enable write access to the commit register (GPIOCR).

    A quick shortcut to this code in TivaWare is given using the PinMux Utility.  For example, for PF0, to open the lock and select the bit we want to modify:

    HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY_DD;
    HWREG(GPIO_PORTF_BASE + GPIO_O_CR) = 0x1;

    Then modify the configuration of the PF0 pin that was unlocked, to CAN0RX, for example:

    GPIOPinConfigure(GPIO_PF0_CAN0RX);
    GPIOPinTypeCAN(GPIO_PORTF_BASE, GPIO_PIN_0);

    -Rebecca

  • Hello.

    I apologise if I am a little off topic and if my question is a bit silly.

    I have one TI Tiva C Series TM4C123GXL Launchpad and two MCP2551 transceivers. I am trying to send and receive simple messages via a Controller Area Network bus. Is it possible to do this using only one Launchpad?

    Thank you. Have a nice day.

     Alex

  • Hello Alex,

    While I don't understand why you would need to use the same uC for the full network, but yes it is possible to do so.

    You would need to configure both CAN controllers, connect the TX-RX of each CAN controller to the CAN transcievers and then connect CANH-CANL of the transceivers together with correct termination.

    You can then configure each of the CAN controller message objects and then TX-RX between them

    Regards

    Amit

  • Hello, again and thank you very much for your reply.

    I am using only one board, because I only have one. My goal is to learn how CAN buses work.

    I wanted to use PA0 (CAN1Rx) and PA1 (CAN1Tx), but they are hardwired to the serial port, so I used PB4 and PB5 (they have CAN0 mapped to them, just like PE4 and PE5). Would this setup work?

    In case you can't see the photo, the schematic is the same as the one on github (except I am using only one LaunchBoard, and on the lower half of the drawing PE5 is replaced by PB5 and PE4 is replaced by PB4 - so, practically I am using PE4, PE5, PB4, PB5, all belonging to CAN0).

    Software-wise, I have the two simple_rx and simple_tx examples from TivaWare. How would I go about making the whole thing work, in regards to interrupts and the order of events? Any input would be useful.

    Thank you. Best wishes,

     Alex

  • Alex Dumitrescu said:
    practically I am using PE4, PE5, PB4, PB5, all belonging to CAN0).

    Is not that, "All belonging to CAN0" the dealbreaker?  I'd expect that your 2nd (later) set-up of CAN0 would "undo" your 1st set-up of CAN0 - don't you agree?  And then what?  (pardon but vendor's post of "CAN to CAN" could not properly anticipate your CAN0 to CAN0 usage!)  Don't do that!

    A 2nd launchpad would seem so much more efficient (and fully allow use of your "preferred" CAN0 - on each board!) and that 2nd board may be programmed w/diagnostics - which would make your effort so much easier & more insightful...  You program only one board at a time - a text Lcd would serve as a much needed "monitor" of the CAN transactions.  (or a UART & PC may be pressed into service - providing far less convienient (and less portable) use - which is less practical for "somewhat distant" CAN or RS232 network test/observation.)

    If you must use single board - be sure to employ different instantiations of CANx - not each the same!  (i.e. CAN0 <-> CAN1 (or CAN2, or CANx ... where x != 0)  If the board does not "escape" different CAN ports - you must employ a 2nd board.

    Glad to (now) note you've "cracked" the diagram display method - now appears, looks good.

  • Hello.

    I don't think I can use CAN1 - mapped to PA0 (CAN1Rx) and PA1 (CAN1Tx), because they are hardwired to the serial port. So, I'll put this on hold until I'm able to use two boards.

    Thank you very much for your reply.

     Alex

  • Hi Alex.

    I like the idea you say on this post and let me know if you can send and receive simple messages via a Controller Area Network bus with a only one IT Tiva C Series TM4C123GXL Launchpad.

    I try to make this project which is in this link: http://www.ijrcct.org/index.php/ojs/article/view/911

    what do you say? I hope your answer please.

  • Hi,

    Although the "idea" shown in this thread may be tempting, I strongly advise against it  - doing so you will miss some important aspects/facts of your implementation - specially common ground problems (which does not appear in "idea") due to missing an important component: the transmission line (CAN bus). See this application note from TI about this problem. Start by building first the bus - 10 ft minimum (3m) cable length, different power supply for different boards, no common neutral line, 3'' stub at the terminating nodes - these are minimum requirements to be taken to be as close as the real case. Cable length and its characteristic impedance may need subtle changes in CAN timing, which will appear otherwise at final product qualification.

  • Hello Kevin

    Do you mean a single device or CAN node? That may not work at all and will be a more painful process to bring it to a n/w. Petrei's post does an excellent job of bringing forth the Application Note.

    Regards
    Amit