3 Replies Latest reply on Jun 9, 2020 6:20 AM by BragadeeshV_41

    Can Receive Mailbox ID at runtime

    OmAb_4672891

      Hi everyone,

       

      I know there is a way to change the ID of a TX mailbox during runtime. I was wondering if there is a way to do the same for RX mailbox? My use case:

       

      I have a bunch of MCU's networking over can. These MCU's have dipswitch's that correlate to a CAN ID. During runtime, I would like to initialze by doing the following:

      1) read dipswitches to get CAN ID

      2) set teh RX mailbox CAN ID so we only interrupt the MCU if there is a message on the network with its CAN ID.

       

      I've looked up and down the data sheet, and even looked at the CAN_RX_CFG struct but there does not seem to be a parameter for rxid.

       

      Thanks in advance!

        • 1. Re: Can Receive Mailbox ID at runtime
          OmAb_4672891

          Hi guys,

          update on what I found. A friend linked me a CAN Debugging web page:
          Control Area Network (CAN) Protocol Troubleshooting Guide for PSoC® - KBA224456

           

          n this webpage i found a way to dynamically change RX Mailbox ID.

          This is how i do mine:

           

          ------------------------------------

          void setRXCanID(void){

            

              CAN_1_RX_CFG rxcfg;

              uint32 regAddr = 0;

             

              #define AMR_1 (0x001FFFF9) /* AMR (Bit[31;21]is Mask set to 0 for ID, Bit[20:3]=1, Bit2(IDE)=0, Bit1   RTR=0,Bit0=N/A*/

              #define ACR_1 (0x00200000) /* ACR (Bit[31;21]is ID=0x1, Bit2(IDE)=0, Bit(RTR)=0,Bit0=N/A*/

           

           

              CY_SET_REG32((reg32 *) (&rxcfg.rxmailbox), 0);

             

              CY_SET_REG32((reg32 *) (&rxcfg.rxamr), AMR_1);

              CY_SET_REG32((reg32 *) (&rxcfg.rxacr), ACR_1);

             

              if(CAN_1_RxBufConfig(&rxcfg) == CYRET_SUCCESS){

                 

                      uint32 temp = CAN_1_GET_RX_ID(0);

                      UART_1_PutHexByte(temp);

                 

              }   

          }

          ------------------------------------

           

          However, That if statement never returns wit ha success. Upon further debugging I found that it writes the RXCMD register after the RXmailbox register and for some reason doesn't continue writing the AMR and ACR registers. Its hard to read their macros (CYREG whatever) im used to doing |= and &=.

           

          To combat this i decided to set the rxcfg.rxcmd register. Upon looking at the field, I concluded that the value should be 0x70028 from the TRM but it still fails. Any ideas?

           

          I am using psoc 4plus family cy8c4147azi-s465. Tahnks in advance

          • 2. Re: Can Receive Mailbox ID at runtime
            OmAb_4672891

            UPDATE:

             

            It seemed that was failing because I was using a FULL can mailbox. Not a Basic one. Changing it to basic seems to work. I attempt to set CAN ID using the code above. But whatver I change the ID bit fields to, when I call CAN_1_GET_RX_ID macro, I always get an ID of 0x454. not sure why

            • 3. Re: Can Receive Mailbox ID at runtime
              BragadeeshV_41

              Hi OmAb_4672891,

               

              Yes, the AMR and ACR registers are meant to be used with the basic mailboxes.

              CAN_GET_RX_ID() returns the ID of the received message. It doesn't return the filter that is set. Therefore, please do not check the RX ID after setting up the filter. CAN_GET_RX_ID()  is typically called in the Receive interrupt to check which is the received message ID.

               

              Regards,

              Bragadeesh