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.

RM42 CAN TX/RX issue with configuring as GPIO

Other Parts Discussed in Thread: HALCOGEN

Hi there,

I am trying to use two of the CAN pins on the RM42 as GPIO. I have them configured as such in halcogen, and I noticed that given the way the pins are controlled it doesn't appear they can be driven with the GPIO driver so I wrote a simple interface function to change the state of the pins. At this point I noticed it seems to have no effect, and on further investigation I discovered that the FUNC bit in either pin control register cannot be set to zero, whether through the halcogen startup utility or otherwise (debugger, other function). 

As far as I can tell the INIT bit in the CAN control register is NOT being reset. If I set it to one it remains that way and it does not seem to change state from zero, so I do not believe that it is the problem. If I set it to one the changes to the FUNC bits remain until I clear it to zero to exit initialization mode.

I was wondering what exactly I may have overlooked, any help is much appreciated.

Cheers,

Jonathan

  • Hello Jonathan,

    It is possible to configure the CAN pins in Halcogen.

    First, you must enable the drivers under the RM42L432-->Driver Enable Tab.

    Next, select the CAN tab you wish to be in GIO mode and the sub tab for CANx Port.

    For Eample: CAN1-->CAN1 Port

    Then select GIO by connecting the nodes for GIO. To the right on this tab is the IO configuration to configure the IO state at startup. i.e., configure DIR, Pull direction, Open Drain Enabled, and default IO level.

    After configured, you will generate the code and there should be a CAN.C file with the drivers. You will need to add a call to CAN_Init() in your main{} which will initialize the startup state of the IO.

    For further manipulation, there are APIs within the CAN.c file such as

    void canIoSetDirection(canBASE_t *node,uint32 TxDir,uint32 RxDir) ==> runtime control of pin direction

    void canIoSetPort(canBASE_t *node, uint32 TxValue, uint32 RxValue) ==> set the IO state of CANTx and CANRx pins

    uint32 canIoTxGetBit(canBASE_t *node) ==> returns state of CANTx pin

    uint32 canIoRxGetBit(canBASE_t *node)==> returns state of CANRx pin

    As far as your code you are using now that is not working, it seems as though the module is not out of reset or is in a powerdown mode since you are unable to write to the registers.

  • Chuck,

    Thank you for the prompt reply. I have got the CAN pins working as GPIO, however I had to add a line to the initialization function to set the INIT bit in CAN CTL to 1. If this bit is 0 then all writes to the pin control registers involving the FUNC, DIR and OUT bits are ignored, either through the preconfigured halcogen drivers or otherwise. When the INIT bit is set to 1, (ie, the CAN is in initialization mode) then the pins act as expected and are controllable.

    Worth noting, I have already completed all configuration with halcogen as described above, this is the only set of routines I have seen so far that hasn't worked essentially right out of the box. Perhaps there is something in my development environment or another issue that led to this confusion. 

    Cheers,

    Jonathan

  • Hi Jonathan,

    Glad to hear it is all working for you now. I will send your comments to our Software lead so that he can review the issues with the Halcogen code. Certainly, if the CAN pins are configured as IO, then you need to be able to update the IO control registers so the init bit should be in the proper state to do this.

  • Hi Jonathan,

    HALCoGen 4.01.00 has the fix already.Please do double check. Thanks!

  • Hi Jonathan
    Im using the CAN pins as GPIO but I was checking the codes generated by halcogen and I see all the configurations there (messaage, ram, etc) so I have two questions...
    1)can I erease all the congifurations I dont need and the functions?
    2) I need to output a signal on the CAN TX and/or RX pins. I used this line: canIoSetPort(canREG1->TIOC, 0x1,0x0); but it gives me a warning when compiling and also... Im not sure which registers are the registers of the TX and RX on the three CAN modules... And I was reading the code, the can.h, and saw that the function (I might be wrong) modifies the TX and the RX at the same line??

    could you guide me pls?

    Best regards

  • Hi Miguel,

    Regarding question 1, I would not erase any of these functions or config data as there is a risk you could break the CAN driver. Although I suppose it depends on the compiler, unused functions won't be included in the final code binary so they won't take up any space in your application.

    For point 2, I believe you need to use the CAN node pointer (ie just canREG1, not canREG1->TIOC). Other than that that should compile no problem. The first integer parameter is the new TX pin value, and the second the RX pin value.

    Cheers,

  • ooh ok ok
    Im using CCS, so I ignore that haha
    about point 2, I modify the line to this: canIoSetPort(canREG1, 0x1,0x1); but there is no way to make it independant? because I need to do a mask to be able to change those values randomly between 0 and 1 since Im using them as the direction pin for a dc motor...

    thanks!!
  • Miguel,

    In that case for a quick test I would suggest simply duplicating the existing canIoSetPort function in can.c into two new functions, like canIoSetTX and canIoSetRX and pulling out the third input parameter. If you look at the actual function canIoSetPort you can see it is only two lines, once that sets the Transmit pin to the input TX value and one that sets the RX pin. Simply use only one of the RX or TX lines in the correct function.

    Cheers,