Thread: CAN Message Transmission Logic

  1. #1
    Registered User
    Join Date
    Apr 2019
    Posts
    35

    CAN Message Transmission Logic

    Hi,
    I need to transmit data over CAN, but i am really struggling to organize the software flow. The below is the prototype function to transmit
    Code:
    void CanTransmit(uint8_t *TxData)
    {
    }
    The above function transmits 8 bytes of data in a cyclic manner every 10ms and i have to fill the TxData[8] array.
    Code:
    uint8 TxData[8];
    uint8_t current;
    int main(void)
    {
    while(1)
    {
    }
    }
    The problem is the data comes from different functions ex:
    Code:
    void CalculateCurrent(void)
    {
      current = 12; 
    }
    void CalVoltage(void)
    {
     voltage = 15;
    }
    How do i organize the filling of array of TxData[8], define global variables for each data and fill it in each function or define a common function and fill the data. The problem is multiple people work on the software.
    Like for example
    Code:
    void CalculateCurrent(void)
    {
      current = 12; 
      TxData[0] = current ;
    }
    void CalVoltage(void)
    {
     voltage = 15;
     TxData[1] = voltage;
    }
    or
    Code:
    void FillBuffer(void)
    {
    TxData[0] = current ;
    TxData[1] = voltage;
    }
    Call the FillBuffer code periodically. Please advise.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    So why not
    Code:
    void CanTransmit(uint8_t *TxData)
    {
    }
    
    void CalculateCurrent(uint8_t *TxData, int offset)
    {
      uint8_t current = 12; 
      TxData[offset] = current ;
    }
    void CalVoltage(uint8_t *TxData, int offset)
    {
     uint8_t voltage = 15;
     TxData[offset] = voltage;
    }
    
    int main(void)
    {
        uint8 TxData[8];
        while(1) 
        {
            CalculateCurrent(TxData,0);
            CalVoltage(TxData,1);
            CanTransmit(TxData);
        }
    }
    > The problem is multiple people work on the software.
    It's called design, and agreeing on an interface specification for the boundaries between functional/work areas.

    > Call the FillBuffer code periodically.
    Well a while(1) loop will do that.

    At the very least, you need some means of measuring time if you want to call something say once a second.
    Ideally, you have an OS of some sort to make this easier.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Logic for Message Timeout
    By Clearner123 in forum C Programming
    Replies: 2
    Last Post: 12-25-2022, 03:22 AM
  2. S/w part Number Transmission
    By Satya in forum C Programming
    Replies: 4
    Last Post: 03-16-2018, 09:42 PM
  3. file transmission with ftp
    By Picachu in forum C Programming
    Replies: 3
    Last Post: 01-11-2007, 06:37 AM
  4. IE end of transmission?
    By Sebastiani in forum C++ Programming
    Replies: 7
    Last Post: 10-22-2002, 05:31 PM

Tags for this Thread