0

I am using dspic33ch512mp508. When I call the CAN1_Transmit function, it transmitting continuously with 100us second gaps. Even if I put it in the 1 second timer, it doesn't work.I tested it, the timer works, it doesn't send for the first second, then it sends continuously.Even if I call the function once, it sends data constantly. Where am I going wrong or what am I missing?

I shared the necessary details, if there is something missing, I can add it.

Thanks.

#include "mcc_generated_files/system.h"

#include "mcc_generated_files/pin_manager.h"

#include "mcc_generated_files/tmr1.h"

#include "mcc_generated_files/spi1.h"

#include "mcc_generated_files/user_structs.h"

#include "mcc_generated_files/uart1.h"

#include "mcc_generated_files/can1.h"

#include "mcc_generated_files/can_module_features.h"

#include "mcc_generated_files/can_types.h"

#include <xc.h>

#include <stdio.h>

/*

Main application

 */





bool tmr1flag;

uint16_t timer_1_sec=0;

uint16_t timer_1ms=0;

uint16_t timer_100ms=0;




   

////////--------------------------------------------------------------------------------------------------

 

 

 //////_____MAIN FUNCTION_____________________________________________________



int main(void)

{

  CAN_MSG_OBJ msg;

   uint8_t data[8] = {0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48};

  SYSTEM_Initialize();

  CAN1_Initialize();

  CAN1_OperationModeSet(CAN_CONFIGURATION_MODE); 

  TMR1_Initialize();

  TMR1_Start();

  UART1_Initialize();


  while (1)

  {


    //100us TIMER INTERRUPT________________________________________________

    if( (tmr1flag=TMR1_GetElapsedThenClear()) == true)

    {

      TMR1_Stop();

      timer_1_sec++;

      timer_1ms++;

      timer_100ms++;

      TMR1_Start();

         

        

    } 


    //1 second TIMER_______________________________________________________

    if(timer_1_sec >= 10000)

    {

        if(CAN_CONFIGURATION_MODE == CAN1_OperationModeGet())

        {   

              if(CAN_OP_MODE_REQUEST_SUCCESS == CAN1_OperationModeSet(CAN_NORMAL_2_0_MODE))

                {

                msg.msgId = 0x1FFFF;

                msg.field.formatType = CAN_2_0_FORMAT;

                msg.field.brs = CAN_NON_BRS_MODE;

                msg.field.frameType = CAN_FRAME_DATA;

                msg.field.idType = CAN_FRAME_EXT;

                msg.field.dlc = DLC_8;

                msg.data = data;



                    if(CAN_TX_FIFO_AVAILABLE == (CAN1_TransmitFIFOStatusGet(CAN1_TX_FIFO1) & CAN_TX_FIFO_AVAILABLE))

                    {

                      CAN1_Transmit(CAN1_TX_FIFO1, &msg);



                    }

      }

       

    }

      

      timer_1_sec=0;

       

      

    }


   

  ////////___MAIN END___________________________________________________________

  

}

}

/**

 End of File

*/

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

emnbke
  • 9
  • 2
  • It sounds like there are no other devices on the CAN network. Most CAN devices will continuously transmit a packet until they receive an acknowledgment. If there are no other devices on the CAN network, it won't receive an acknowledgment. If you have another device on the CAN network, make sure the bit rates match or you will also get this type of behavior. – Steve Mathwig Aug 01 '23 at 13:44
  • Thanks a lot for your suggestion. After writing, I connected another device to the line, but this time I could not see any data. I'll check the can line again. – emnbke Aug 02 '23 at 06:26

0 Answers0