# Thread: CAN Message Transmission Logic

1. ## 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;
}```

2. 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.